Can you elaborate a bit on the "before" scenario? (i.e. exactly what
are you comparing protobuf to?)

Protobuf adds overhead to data (in order to tell which field is which,
etc), and does nothing for reducing the sizes of strings. (Integers
are usually varint-encoded, so if they're small, they'll save space,
if they're large, they'll take up even more space than before. But you
can use fixed32/fixed64 to mitigate that if you expect large integers
to be sent.)

In your case, I would expect <tag 1> <varint with string length>
<string data>. Both tag 1 and the string length should be 1 byte each,
unless the string is longer than 127 bytes (in which case the string
length would take up 2 bytes). And the string data will be however
long the passed in string is... let's say it was 50 bytes, I would
expect the protobuf-serialized message to be 52 bytes.

Does that not line up with what you're seeing?

  -ilia


On Fri, May 16, 2014 at 7:21 AM, Ratheesh R <rathe.2...@gmail.com> wrote:
>  Hello Experts,
>
>  I am new to this Protocol buffer techinque.I am trying to use PB in my
> project because my project is critical to the data transfer rate(Battery
> power).
> So I am trying to use PB to serialize data (in binary mode) to reduce the
> data size before transferring this data to the other application.
> But I was not successful in seeing the reduction in size even after
> serializing with API's SerializeToString() OR SerializeToArray().
>
> let's  say ,my string is like the below which I am sending on evey 100
> millisecond to other application,
>
> <attribute msgCommand="update" type="uid64" uid64="123445667898"
> datatype="8" rawdata="FFF1" default="65297" />
>
> Previously it was sending in text mode and now i am trying with ProtoBuff to
> serailize this to send,but I could not see any diffrence in size reduction
> of this string
> after serilaizng with PB.please see my code and let me know where i am doing
> the mistake,
>
> -------
> proto
> --------
> message AMessage
>    {
>       optional string str1=1;
>    }
> -------------------------------------------------------------------------------------
> Code i have done to serailize the above string to reduce the size (binary
> format)
> -----------------------------------------------------------------------------------------
>      AMessage A_msg;
>      A_msg.set_str1(m_txBuff); // m_txBuff -contains the above mentioned
> string
>      std::string encode_string;
>
>     // ----tried with SerializeToString,but was not successful --------//
>     A_msg.SerializeToString(&encode_string);
>
>    // ----------tried  with SerializeToArray ,it was also not
> successful-----//
>     int size_bytes = A_msg.ByteSize();
>     void *buffer_bytes = malloc(size_bytes);
>     A_msg.SerializeToArray(buffer_bytes, size_bytes);
>
>    //sending the data send
>      infomq_cmd_publish((unsigned
> char*)encode_string.c_str(),encode_string.size(),0);
>
> Anything i need to do extra for making this serailization in binary format
> for reducing the size on serialization ?
>
>
>
>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> Visit this group at http://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.

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

Reply via email to