You need to know the message size to know that you have an entire message
to actually deserialize. That requirement cannot be glossed over, although
it can be handed to the library to worry about. What you have at the moment
is simply: broken socket code - nothing to do with protobuf.

If you don't want to have to worry about that: just ask the library to read
from the NetworkStream for you. When using the DeserializeWithLengthPrefix
methods it deliberately reads the prefix bytes very carefully to prevent
over-reading.

Marc
On 12 Sep 2014 22:45, "Antonio Ramos" <ninira...@gmail.com> wrote:

> But for use this constructor i have to know the message size, isĀ“nt it?
> how can i do it? with a sizeof of the proto class??
>
> 2014-09-12 21:22 GMT+02:00 Marc Gravell <marc.grav...@gmail.com>:
>
>> My first thought is: what makes you think that you have read an entire
>> frame of data, and a *single* frame of data? socket read very rarely
>> conveniently forms itself into complete frames. Please see
>> http://tiny.cc/io. My second thought is: you told it to use the *entire*
>> buffer, not just the "valo" bytes that you know are valid - in which case
>> the message is *basically* right - you have garbage at the end of your
>> buffer. You should use the MemoryStream constructor that lets you control
>> this:
>>
>>     new MemoryStream(buffer, 0, valo);
>>
>> (note this should be after checking "valo" is positive, and you also need
>> to think about things like back-buffers if your messages turn out to be
>> larger than "buffer.Length")
>>
>> Thirdly: how was the data serialized? Did it use the WithLengthPrefix and
>> the same PrefixStyle?
>>
>> Marc (protobuf-net)
>>
>
>
>
> --
> Antonio Ramos Recoder. <http://antonioramosfotografia.es>
>

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