Skip to content

Instantly share code, notes, and snippets.

@yfakariya
Created August 5, 2012 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yfakariya/3264869 to your computer and use it in GitHub Desktop.
Save yfakariya/3264869 to your computer and use it in GitHub Desktop.
An idea to resolve incompatibility of DataMemberAttribute.Order's lower bound between msgpack and protobuf.
// Initialize SerializationContext, which can be singleton.
var context = new SerializationContext();
// Set compatibility option, which set array lower bounds to 1 instead of 0.
context.CompatibilityOptions.OneDataMemberLowerBound = true;
// Following is as is...
var serializer = MessagePackSerializer.Create<Foo>( context );
using( var stream = new MemoryStream() )
{
serializer.PackTo( stream, foo );
// Assume Foo is:
// class Foo { [DataMember(Order = 1)]int Bar = 1; }
// stream should be { 0x91, 0x1 } instead of { 0x92, 0xC0, 0x1 }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment