If you use the vanilla message via Serialize
/ Deserialize
, then no: this is not part of the specification (since the format is for adding).
If, however, you use SerializeWithLengthPrefix
, it will unload the length at the beginning of the message; he will know in advance how much data is expected. You deserialize with DeserializeWithLengthPrefix
and it will complain loudly if it doesn't have enough data. However! He will not complain if you have additional data, as this is also intended to be added.
In terms of John’s answer, the use of the *WithLengthPrefix
method by default refers to data stored exactly identical to what John suggests; he pretends that there is a shell object and behaves accordingly. The differences are as follows:
- there is actually no wrapper object.
- the "withlengthprefix" methods explicitly stop after one event, and do not combine any later data into the same object (useful, for example, for sending several discrete objects to a single file or down one socket).
The difference in the two "incremental" here is that the first means "merge into one object", where - as the second means "I expect several records."
Unrelated sentence:
s.Write(m.GetBuffer(), 0, m.ToArray().Length);
it should be:
s.Write(m.GetBuffer(), 0, (int)m.Length);
(no need to create an additional buffer)
source share