Skip to content

Bridging between Newtonsoft.Json and msgpack-cli

License

Notifications You must be signed in to change notification settings

Code-Sharp/Newtonsoft.Msgpack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

73 Commits

Repository files navigation

#Newtonsoft.Msgpack

AppVeyor BuildNuGet 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

Productproduct=newProduct{ExpiryDate=DateTime.Parse("2009-04-05T14:45:00Z"),Name="Carlos' Spicy Wieners",Price=9.95m,Sizes=new[]{"Small","Medium","Large"}};MemoryStreammemoryStream=newMemoryStream();JsonSerializerserializer=newJsonSerializer();// serialize product to MessagePackMessagePackWriterwriter=newMessagePackWriter(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-E0memoryStream.Seek(0,SeekOrigin.Begin);// deserialize product from MessagePackMessagePackReaderreader=newMessagePackReader(memoryStream);ProductdeserializedProduct=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