Skip to content

Instantly share code, notes, and snippets.

@gregoryyoung
Created January 8, 2014 13:01
Show Gist options
  • Save gregoryyoung/8316430 to your computer and use it in GitHub Desktop.
Save gregoryyoung/8316430 to your computer and use it in GitHub Desktop.
ouch
public static ArraySegment<byte> Serialize<T>(this T protoContract)
{
using (var memory = new MemoryStream())
{
Serializer.Serialize(memory, protoContract);
var res = new ArraySegment<byte>(memory.GetBuffer(), 0, (int) memory.Length);
return res;
}
}
public static byte[] SerializeToArray<T>(this T protoContract)
{
using (var memory = new MemoryStream())
{
Serializer.Serialize(memory, protoContract);
return memory.ToArray();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment