Deserializing a type at the current stream position with protobuf-net
- by Arne Claassen
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?