ericvana / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
Other
0 stars 0 forks source link

Add DeserializeWithLengthPrefix overload that accepts previously read length prefix as parameter #355

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Currently there are methods TryReadLengthPrefix and 
DeserealizeWithLengthPrefix. But if I first try to read the length prefix (to 
validate that following serialized object does not exceed my configured size 
limits), I then have to seek the stream back before calling 
DeserializeWithLengthPrefix. It would be nice to have and overload of 
DeserializeWithLengthPrefix, that would accept a previously read length prefix 
as parameter. This would improve performance by eliminating unnecessary seek 
and would allow using protobuf on non-seekable streams of protobuf-serialized 
messages.

Original issue reported on code.google.com by igor.babichev on 8 Feb 2013 at 11:27

GoogleCodeExporter commented 8 years ago
You can do this manually by creating a new ProtoReader on your stream 
specifying the length you want to read, then use the Deserialize overload that 
accepts ProtoReader instead of a stream. Is that enough ?

Original comment by marc.gravell on 8 Feb 2013 at 11:38

GoogleCodeExporter commented 8 years ago
Am I looking in the wrong place? I only see one Deserialize overload in 
Protobuf.Serializer class, and that overload accepts a stream. I'm looking at 
protobuf-net 2.0.0.622

Original comment by igor.babichev on 9 Feb 2013 at 12:08

GoogleCodeExporter commented 8 years ago
You may need to use RuntimeTypeModel.Default.Deserialize - this is the method 
that Serializer.Serialize calls.

Original comment by marc.gravell on 9 Feb 2013 at 1:14