Coder Social home page Coder Social logo

newtonsoft.msgpack's Introduction

#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.

newtonsoft.msgpack's People

Contributors

darkl avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.