Created
December 13, 2011 21:20
-
-
Save devoyster/1473950 to your computer and use it in GitHub Desktop.
protobuf-net plain example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Explicit proto contract | |
[ProtoContract] | |
public class MappedEntity | |
{ | |
[ProtoMember(1)] | |
public int Id { get; set; } | |
[ProtoMember(2)] | |
public string Name { get; set; } | |
} | |
var entity = new MappedEntity { Id = 1, Name = "123" }; | |
// Serialize/deserialize using protobuf-net | |
byte[] serialized; | |
using (var ms = new MemoryStream()) | |
{ | |
Serializer.Serialize(ms, entity); | |
serialized = ms.ToArray(); | |
} | |
MappedEntity deserialized; | |
using (var ms = new MemoryStream(serialized)) | |
{ | |
deserialized = Serializer.Deserialize<MappedEntity>(ms); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment