Skip to content

Bridging between Newtonsoft.Json and msgpack-cli

License

Notifications You must be signed in to change notification settings

sdwfrost/Newtonsoft.Msgpack

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#Newtonsoft.Msgpack

AppVeyor Build NuGet Version

This project brings msgpack-cli to Json.NET.

It actually contains an implementation of JsonReader/JsonWriter using msgpack-cli Unpacker/Packer classes.

##Why?

Both libraries are great libraries, but it seems that Json.NET is more extendable and customizable for serializing objects - i.e: there are a lot of extension points where you can change serialization behavior.

This allows you to read/write from Msgpack streams with your favorite Json.NET attributes and custom behaviors (null handling, JsonConverters, ContractResolvers and etc).

##Why not?

This supports only Msgpack map serialization method, I think that array serialization method doesn't really fit here.

##Status

Should handle simple scenarios. If it doesn't work for you, please open an issue.

A NuGet package is available.

###Performance

Currently this libary isn't very fast - both Newtonsoft.Json and msgpack-cli perform faster. Profiling a benchmark test shows that a lot of time is spent on msgpack-cli methods, in particular on Packer/Unpacker string methods.

##Usage

Example based on Newtonsoft.Json BSON support sample

Product product = new Product
    {
        ExpiryDate = DateTime.Parse("2009-04-05T14:45:00Z"),
        Name = "Carlos' Spicy Wieners",
        Price = 9.95m,
        Sizes = new[] {"Small", "Medium", "Large"}
    };

MemoryStream memoryStream = new MemoryStream();
JsonSerializer serializer = new JsonSerializer();

// serialize product to MessagePack
MessagePackWriter writer = new MessagePackWriter(memoryStream);
serializer.Serialize(writer, product);

Console.WriteLine(BitConverter.ToString(memoryStream.ToArray()));

// 84-A4-4E-61-6D-65-B5-43-61-72-6C-6F-73-27-20-53-70-69-
// 63-79-20-57-69-65-6E-65-72-73-A5-50-72-69-63-65-A4-39-
// 2E-39-35-A5-53-69-7A-65-73-93-A5-53-6D-61-6C-6C-A6-4D-
// 65-64-69-75-6D-A5-4C-61-72-67-65-AA-45-78-70-69-72-79-
// 44-61-74-65-D3-00-00-01-20-76-BD-51-E0

memoryStream.Seek(0, SeekOrigin.Begin);

// deserialize product from MessagePack
MessagePackReader reader = new MessagePackReader(memoryStream);
Product deserializedProduct = serializer.Deserialize<Product>(reader);

Console.WriteLine(deserializedProduct.Name);
// Carlos' Spicy Wieners

##Want to help?

Contribute in any way! pull requests will be appreciated.

About

Bridging between Newtonsoft.Json and msgpack-cli

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%