Sorry, it is a non-goal of protocol buffers to provide message integrity --
this is left to a higher layer.  One byte of corruption in a protocol
message can very easily make it impossible to parse the remainder of the
message, or even make the rest of the message appear as parseable garbage.
 Therefore, trying to design code which can work around corruption in the
message is fraught with peril, and no one has tried.

If you need to be able to recover from corruption without discarding the
whole file, the way to do it is by designing your file format to contain
multiple protocol buffers framed in some way that allows you to continue
reading the others if one is corrupted.  This isn't something protocol
buffers can provide, but it would make sense for someone to write a library
on top of protobufs that provides it.

On Wed, Jan 27, 2010 at 8:40 PM, Stefan <sneg...@gmail.com> wrote:

> Hello everybody,
>
> I have a small dilemma with regards to protocol buffers. I read the
> documentation but I still do not see a clear answer (I only use the
> Java version of protocol buffers). I hope I am not missing something
> really obvious here ...
>
> I have the following setup:
>
> message Item {
>    optional string name = 1;
>    optional string description = 2;
> }
>
> message Bag{
>    repeated Item item= 1;
> }
>
> In the code, a Bag (with a significantly big number of items) gets
> serialized to a file. Now, lets suppose the file gets corrupted in the
> middle (arbitrary point). From my experiments, the entire content
> would be lost because Bag cannot be deserialized anymore. To construct
> the Bag, I use the parseFrom() method and I get exceptions. I do not
> see anything in the documentation that would suggest mergeFrom() would
> have a different result either.
>
> I do not expect to be able to recover any individual corrupted items
> but it would be nice to be able to recover the rest of the list.
>
> What could I do reduce the risk of losing the entire list due to
> arbitrary corruption? What if corruption only occurs at the end of the
> file, would it be simpler to recover all the elements up to the
> corruption point?
>
> Thanks for your help!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To post to this group, send email to proto...@googlegroups.com.
> To unsubscribe from this group, send email to
> protobuf+unsubscr...@googlegroups.com<protobuf%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/protobuf?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to