I've found my problem: SerializeToZeroCopyStream doesn't return any error because all the stream does is accumulate the input in a buffer before compression, so it doesn't even try to write the result yet. The stream return error codes when calling Flush() and Close(). If I call those then I detect that there is an error from Zlib. But because I was relying on the stream destructor to flush, I was not getting any error.
On Tuesday, November 4, 2014 7:16:33 PM UTC+13, Antoine Bouthors wrote: > > Hi, > > I am trying to serialize messages to and from arrays using zlib > compression. > > Attached is a trivial example of what I'm trying to do. > > The code asserts at line 64: the messages read from the buffer is empty. > > My problem is: there is no indication whatsoever from protobuf that > something went wrong, either during encoding or decoding. I can only detect > something went wrong by comparing the decoded result against the original, > which is a bit of a pain. > > There are variations around that theme. If I add these two lines after > t.set_a(): > > t.set_b( 42 ); > t.set_c( 42 ); > > Then serialization still passes but deserialization fails. It doesn't tell > my why, though. Nothing is ever sent to the log handler. > > If I increase the size of the buffer prior to encoding, then everything > goes through fine and the assertion passes. Evidently, zlib has issues with > small buffers and sometimes the compressed result ends up being bigger than > the input. That's something I can understand, but it leaves me with a bunch > of questions: > - Why am I not getting any error on serialization when trying to > serialize into a buffer that's too small? > - Why am I not getting any error on deserialization when trying to parse > from a buffer that was too small? > - What should the size of my buffer be to guarantee that serialization > will pass? Even adding 1KB to it, I still have problems on some production > cases. > > Thanks, > A. > -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/protobuf. For more options, visit https://groups.google.com/d/optout.
