public void Serialize_Deserialize() { var serializer = new ProtobufMessageSerializer(); var testMessage = new TestMessage { Boolean = true, Guid = Guid.NewGuid(), Int32 = -1234, Int64 = -12345678, String = "some text" }; var serializedMessage = serializer.Serialize(testMessage); using (var mem = new MemoryStream(serializedMessage)) { mem.Position = 2; var deserializedMessage = Serializer.Deserialize<TestMessage>(mem); Assert.AreEqual(testMessage.Boolean, deserializedMessage.Boolean); Assert.AreEqual(testMessage.Guid, deserializedMessage.Guid); Assert.AreEqual(testMessage.Int32, deserializedMessage.Int32); Assert.AreEqual(testMessage.Int64, deserializedMessage.Int64); Assert.AreEqual(testMessage.String, deserializedMessage.String); } }
public void Serialize_serializes_MessageTypeId() { var serializer = new ProtobufMessageSerializer(); var testMessage = new TestMessage(); var serializedMessage = serializer.Serialize(testMessage); using (var mem = new MemoryStream(serializedMessage)) using (var reader = new BinaryReader(mem)) { var messageTypeId = reader.ReadUInt16(); Assert.AreEqual(messageTypeId, testMessage.MessageTypeId); } }