SimpleMsgPack. NET releases an open-source library for parsing the msgpack protocol C,

Source: Internet
Author: User
Tags unpack

SimpleMsgPack. NET releases an open-source library for parsing the msgpack protocol C,

Over the past two years, I have been paying attention to this IOCP application in network communication. Of course, data transmission is often required. This year, I came into contact with the MsgPack format and found that it was really nice to use it to pack data during transmission. Because it can directly package binary data without any conversion. Some people may say that packaging is not difficult. Yes, that's right. But there is a standard format protocol, why not directly use it. After reading the msgpack protocol format, the compression is basically maximized. Http://msgpack.org can understand its Protocol format.

My main job is to develop in Delphi, which contains qmsgpack. I also wrote a simpleMsgPack which is very comfortable to use. This evening I Want To See C #. After all, C # is also good for clients. I used MsgPack parsing in C # version. Maybe I am a Delphier. Later, I decided to write a NET version of SimpleMsgPack myself. Now it is basically shaped. Some new things will be added later. You can download it directly from git or find the input SimpleMsgPack in NuGet. Download the source code from github. If you have any bugs, please contact me and I will fix them as soon as possible.

 

Compiling environment:

VS2013 NET Framework 4.5 (it can also be compiled under vs2010, and other versions are not tested)

 

Open Source Address: https://github.com/ymofen/SimpleMsgPack.Net

 

I wrote some simple test code. Everyone should understand it.

MsgPack msgpack = new MsgPack (); msgpack. forcePathObject ("p. name "). asString = "Zhang San"; msgpack. forcePathObject ("p. age "). asInteger = 25; msgpack. forcePathObject ("p. datas "). asArray. add (90); msgpack. forcePathObject ("p. datas "). asArray. add (80); msgpack. forcePathObject ("p. datas "). asArray. add ("Li Si"); msgpack. forcePathObject ("p. datas "). asArray. add (3.1415926); // pack file msgpack. forcePathObject ("p. filedata "). loadFileAsBytes ("C: \ a.png"); // pack msgPack binary byte [] packData = msgpack. encode2Bytes (); MsgPack unpack_msgpack = new MsgPack (); // unpack msgpack unpack_msgpack.DecodeFromBytes (packData); System. console. writeLine ("name: {0}, age: {1}", unpack_msgpack.ForcePathObject ("p. name "). asString, unpack_msgpack.ForcePathObject ("p. age "). asInteger); Console. writeLine ("================================== "); system. console. writeLine ("use index property, Length {0 }:{ 1}", unpack_msgpack.ForcePathObject ("p. datas "). asArray. length, unpack_msgpack.ForcePathObject ("p. datas "). asArray [0]. asString); Console. writeLine ("================================== "); console. writeLine ("use foreach statement:"); foreach (MsgPack item in unpack_msgpack.ForcePathObject ("p. datas ") {Console. writeLine (item. asString);} // unpack filedata unpack_msgpack.ForcePathObject ("p. filedata "). saveBytesToFile ("C: \ B .png"); Console. read ();

Output result:

 

See if it is suitable for you. It is still under testing, and of course it is not used in specific projects. However, it will be used later. I plan to package data for communication. If you find a bug, contact me.

Qq: 185511468,
Email: ymofen@diocp.org
You can also enter the group [programmer's home 146605007] @ me

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.