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 
like this:

def main():
    user = test_tools.generate_user() # creates a 'user' protobuf object = 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
    print test_string

So I run that with python > 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 "", line 112, in <module>
  File "", 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
Visit this group at
For more options, visit

Reply via email to