Still haven't run it (I only seem to have a too old cmake; a simple Makefile with a .proto and .cc file showing the problem would be better. Please strip down the example if someone should help debugging it ;) )
Anyway, it seems that you in write_message() to write a header with some magic number and the size. stream << magic8; stream << (uint8_t)data_types::PB_DATA; stream << _htole32(message.GetCachedSize()); .. but wouldn't this write the output in decimal instead of binary that you intend ? So it will not be exactly 4 bytes. So better write this in binary ;) (and BTW, it is not a good idea to use some system macros (such as _htole32() .. better use htonl()) On Wed, Oct 7, 2009 at 18:24, Henner Zeller <h.zel...@acm.org> wrote: > Hi, > haven't run the example yet, just a quick look (however, it is a bit > more than a stripped example of the problem ;) ) > > You have some constants strayed in such as > size_t len = msg.GetCachedSize() + 6; > why that ? > > -h > > On Wed, Oct 7, 2009 at 18:11, Brenden Matthews <bren...@diddyinc.com> wrote: >> Oops, had some bad math in that last sample. This is more correct (but >> still fails). >> >> On Wed, Oct 7, 2009 at 5:33 PM, Brenden Matthews <bren...@diddyinc.com> >> wrote: >>> >>> Here you go...attached is an example that fails quite reliably (for me). >>> Compile like so: >>> mkdir build >>> cd build >>> cmake ../ >>> make >>> ./test-pb >>> On Wed, Oct 7, 2009 at 4:49 PM, Kenton Varda <ken...@google.com> wrote: >>>> >>>> ByteSize() definitely returns the right value -- if it didn't, tons of >>>> stuff would be broken. Can you provide a complete example program that >>>> demonstrates your problem? >>>> On Wed, Oct 7, 2009 at 4:01 PM, Brenden Matthews <bren...@diddyinc.com> >>>> wrote: >>>>> >>>>> The value returned by Message::ByteSize() does not match the actually >>>>> number of bytes that are consumed after writing a message to a >>>>> stream. Example: >>>>> >>>>> some_message m; >>>>> /* ... populate m ... */ >>>>> size_t len = m.ByteSize(); >>>>> int pos = boost::iostreams::position_to_offset(stream.tellp()); /* >>>>> save the current position of the stream */ >>>>> m.SerializeToOstream(&stream); >>>>> >>>>> /* and now this assert will fail */ >>>>> assert(pos + len == boost::iostreams::position_to_offset >>>>> (stream.tellp()); >>>>> >>>>> Maybe I'm missing something here, but shouldn't the value returned by >>>>> ByteSize() be the same as the actual number of bytes written to the >>>>> stream? >>>>> >>>> >>> >> >> >> >> >> > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to protobuf@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 -~----------~----~----~----~------~----~------~--~---