NULL character in serialized string

1,672 views
Skip to first unread message

Devesh Gupta

unread,
Jul 21, 2015, 5:22:00 PM7/21/15
to prot...@googlegroups.com
Hello,

as per various forums it is mentioned that in serialized string can have null character in between.
I just wanted to know how is protobuf able to find the end of the string being passed for deserialization.

Actually, when i am deserialization a the string it is failing. This happens when the int32 value passed for serialization is 0. In case if we pass any value above 0 gets de-serialized successfully,

I have checked the serialized string characters and in case of 0 value, there is a null character representing it.

Andrew Brampton

unread,
Jul 22, 2015, 12:56:49 AM7/22/15
to Devesh Gupta, Protocol Buffers
https://developers.google.com/protocol-buffers/docs/encoding shows that strings are length delimited. That is, an integer varint is stored, representing the length of the following string. This way the string can contain nulls, or any other character, but protobuf parser will keep reading until it reads up to length bytes.

As for the issue you are having, I don't know the answer, but perhaps showing your code would help someone spot a problem.

Andrew

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

Christopher Smith

unread,
Jul 22, 2015, 1:13:31 AM7/22/15
to Devesh Gupta, Protocol Buffers

How are you determining the end of the encoded protocol buffer? What language/data type are you using? It sounds to me like you are null termination (perhaps with a C char*?), which isn't going to work to well with a binary structure. Decoding with a null byte, particularly for an integer field, shouldn't ever cause a problem with protocol buffers.

Having null bytes in the encoded bytes should be expected. In C terms, assume the encoded data is an array of unsigned chars (so a null value is of no particular significance).

--
Reply all
Reply to author
Forward
0 new messages