Strange decode error when reading descriptor set file in python (ver.2.4.0)

2,514 views
Skip to first unread message

haje01

unread,
Mar 1, 2011, 8:28:39 PM3/1/11
to Protocol Buffers
I am using protobuf v2.4.0 in Windows and having problems.

Say I have following message file. 'foo.proto'

message School
{
optional int32 students = 1;
}

from which I generated description set file 'foo.desc' like this:

protoc -o foo.desc foo.proto

and, reading description set file..

from google.protobuf.descriptor_pb2 import FileDescriptorSet

fds = FileDescriptorSet()
fds.ParseFromString(open('foo.desc').read())

generates following error message:

File "build\bdist.win32\egg\google\protobuf\message.py", line 179,
in ParseFromString
File "build\bdist.win32\egg\google\protobuf\internal
\python_message.py", line 755, in MergeFromString
File "build\bdist.win32\egg\google\protobuf\internal
\python_message.py", line 782, in InternalParse
File "build\bdist.win32\egg\google\protobuf\internal\decoder.py",
line 521, in DecodeRepeatedField
google.protobuf.message.DecodeError: Truncated message.

Strangely enough, when I changed field name from 'students' to
'student', no error occurred.


Any ideas?

haje01

unread,
Mar 2, 2011, 11:59:23 PM3/2/11
to Protocol Buffers
It's my mistake.

I forgot to open file as 'Binary' mode.

fds.ParseFromString(open('foo.desc', 'rb').read())

This solved the problem cleary.

Sorry..
Reply all
Reply to author
Forward
0 new messages