Deserializing a type at the current stream position with protobuf-net
Posted
by Arne Claassen
on Stack Overflow
See other posts from Stack Overflow
or by Arne Claassen
Published on 2010-03-14T08:29:52Z
Indexed on
2010/03/14
8:35 UTC
Read the original article
Hit count: 347
c#
|protobuf-net
I'm serializing several objects into a single stream, but when i try to read them back, i can't seem to get anything but the last object:
ProtoBuf.Serializer.Serialize(stream, postA1);
ProtoBuf.Serializer.Serialize(stream, postB2);
stream.Position = 0;
var postA2 = ProtoBuf.Serializer.Deserialize<Post>(stream);
var postB2 = ProtoBuf.Serializer.Deserialize<Post>(stream);
The first deserialize moves the stream to the end and postA2 contains the value of postB2, while postB2 is just an uninitialized instance. Is this expected behavior, and if so, how do you deserialize an object from a random position in a stream?
© Stack Overflow or respective owner