So how do you change the code:

ZeroCopyOutputStream* raw_output = new ArrayOutputStream(snap_buf2, 
snap1.ByteSize()+numBytesForDelim); //Here?
            CodedOutputStream* coded_output = new 
CodedOutputStream(raw_output); 

coded_output->WriteVarint32(snap1.ByteSize()); //Here?
snap1.SerializeToCodedStream(coded_output); 

Anthony

On Wednesday, October 20, 2010 10:02:31 AM UTC-7, Paul wrote:
>
> ok thanks a lot guys!  both ByteCount() and VarintSize32() worked for 
> me! 
>
> Paul 
>
> On Oct 20, 3:13 am, Evan Jones <[email protected]> wrote: 
> > On Oct 20, 2010, at 2:13 , Kenton Varda wrote: 
> > 
> > > But you are actually writing a varint32, which can be anywhere   
> > > between 1 and 5 bytes depending on the value. 
> > 
> > > Use CodedOutputStream::Varint32Size() to compute the number of bytes   
> > > needed to encode a particular value. 
> > 
> > This has the advantage that you can allocate a buffer of exactly the   
> > right size, rather than adding 100 as an estimate. However, you can   
> > also find the final size after all the writes with   
> > CodedOutputStream::ByteCount() 
> > 
> > You should not need to do any byte swapping if you are serializing and   
> > deserializing integers using the protobuf API: it handles any required   
> > byte swapping for you. 
> > 
> > Evan 
> > 
> > -- 
> > Evan Joneshttp://evanjones.ca/

-- 
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.

Reply via email to