Re: [protobuf] Logic to Parse Either a Message or a Size Delimited Series of Messages

2014-01-09 Thread jonathan . wolk

>
> You can't do that. Why don't you always use size-delimited messages?
>
>
Well, I'm always using size-delimited message now. I was naive and in a 
rush in my previous implementation. I was just curious as to if there is 
anyway I could keep backward compatibility with my previous implementation 
(in terms of deserializing it) but now I see there's not really. Ok, thank 
you for clearing that up for me.

-Jonathan

-- 
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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [protobuf] Logic to Parse Either a Message or a Size Delimited Series of Messages

2014-01-09 Thread Feng Xiao
On Mon, Jan 6, 2014 at 5:17 PM,  wrote:

> Hi All,
>
> Quick question (though it may be a little confusing).
>
> I currently have a Message that looks something like this
>
> message MyMessage {
>
>   repeated float positions = 1 [packed = true];
>
>   repeated float normals = 2 [packed = true];
>
>   // other repeated float fields
>
> }
>
> This message has been written to a various files. Unfortunately, if I want
> to follow the guidelines outlined in the technique section of the
> documentation, I need to change the structure of the file to fit under the
> 1 MB per message guideline. The reason being that the message may go over
> 1MB depending on how many positions, normals, etc. are in the message and
> sometimes it can be very large.
>
> My solution to the problem is to turn the files from "one message per
> file" to a "size delimited series of messages." The new message would be
> something like:
>
> message MyNewMessage
>
> {
>
>   optional float position = 1;
>
>   optional float normal = 2;
>
>   ///other fields
>
> }
>
> The file would then contain something like:
>
> [varint of the size of the first MyNewMessage]
>
> [MyNewMessage #1]
>
> [varint of the size of the second MyNewMessage]
>
> [MyNewMessage #2]
>
> ..
>
> Conceptually, so far so good. The problems comes when I want to be
> backwards compatible (have my code be able to take either "version" of the
> file as input). How can I do a test to see if my file has just a message in
> it or starts with the varint? Something akin to the pseudo code below
> (using C++):
>
> void DeserializeMyDataFromCodedInput(CodedInputStream* inputStream){
>
>   if ( able_to_parse_MyMessage_from_stream() ) {
>
> // Do code that parses from MyMessage
>
>   } else {
>
> // Do code that parses from the size delimited collection of messages
>
>  }
>
> }
>
> It's easy enough to test for parsing failure when trying to parse a
> MyMessage from the coded input stream (which really wraps an ifstream
> underneath), but how do I put the coded input stream back at the "proper"
> position. The docs and code comments aren't that clear (to me at least) as
> to what BackUpInputToCurrentPosition()so I'm unsure if that is the right
> thing to use.
>
You can't do that. Why don't you always use size-delimited messages?


> I would prefer not to change file extensions or encode such information in
> the filenames if at all possible.
>
> Thanks for all of the help!
>
>
> -Jonathan
>
> --
> 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 protobuf+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> Visit this group at http://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/groups/opt_out.