Skip to content

Instantly share code, notes, and snippets.

@devoyster
Created December 13, 2011 21:20
Show Gist options
  • Save devoyster/1473950 to your computer and use it in GitHub Desktop.
Save devoyster/1473950 to your computer and use it in GitHub Desktop.
protobuf-net plain example
// 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