Howdy all --
I'm looking to use protobuf objects as a convenient and lightweight object
framework for some cross-language stuff I'm doing between Cascading and
Hadoop Streaming, but I'm running into some low-level problems just parsing
messages when I'm writing the message out somewhere.
So, more concretely:
I've got a simple python script to generate an object for me, which looks
user = test_tools.generate_user() # creates a 'user' protobuf object
user.id = 427293847234
v1_activity = user.v1_activities.add()
test_string = user.SerializeToString()
# Just to prove that the string can be parsed at all--this part works
sample_user_2 = user_pb2.User()
# Now let's push the string to sys.stdout
So I run that with python test_usergen.py > sample_user.txt, everything
works fine, the sample_user_2 object parses just fine, and I've got some
sort of string stored in sample_user.txt. The problem begins here.
Now, on the receiving end, I've got a script where I want to be able to
parse this string. Only when I do this:
user_file = open('sample_user.txt', 'rb').read()
user = User()
I get the following:
Traceback (most recent call last):
File "test_mta.py", line 112, in <module>
File "test_mta.py", line 59, in main
line 146, in ParseFromString
line 182, in ParseFromString
line 800, in MergeFromString
raise message_mod.DecodeError('Truncated message.')
google.protobuf.message.DecodeError: Truncated message.
If I compare the len() of the two strings (pre-writing/reading v.
post-writing/reading) I tend to get two add'l chars on the reading, so I
guess I'm confused by how this is getting truncated? Is python running into
a newline char and interpreting it literally somehow?
Any help would be great...I've been banging my head against this all day :)
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
To post to this group, send email to firstname.lastname@example.org.
Visit this group at http://groups.google.com/group/protobuf?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.