Created
August 5, 2012 13:40
-
-
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.
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
// 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