Jump to content

MessagePack UDF


Ward
 Share

Recommended Posts

Introduction

"MessagePack is an efficient binary serialization format. It lets you exchange data among multiple languages like JSON. But it's faster and smaller." (by http://msgpack.org/).

There are already so many languages support MessagePack format, here comes AutoIt version. The backend coder is Charlie Gunyon's cmp. It supported MessagePack proposal v5.

This UDF only have two public functions: MsgPack_Pack() and MsgPack_Unpack(). It just like Json_Enocde() and Json_Decode() in my ?do=embed' frameborder='0' data-embedContent>>JSON UDF. The Map type will  be decoded into "Windows Scripting Dictionary Object" retuned from ObjCreate("Scripting.Dictionary"). So I suggest using Json.au3 to deal with the Map/Object data type. The main difference is MessagePack support Binary format, but Json not. For example (?do=embed' frameborder='0' data-embedContent>>Json.au3 is required to run this example):

Local $Obj1
Json_Put($Obj1, ".binary", Binary("0x00"))
Json_Put($Obj1, ".string", "abc")
Json_Put($Obj1, ".int", Random(0, 1000, 1))
Json_Put($Obj1, ".float", Random())
Json_Put($Obj1, ".bool", True)
Json_Put($Obj1, ".null", Null)

Local $Binary = MsgPack_Pack($Obj1)
Local $Obj2 = MsgPack_Unpack($Binary)

ConsoleWrite("Test2 $Obj1.binary is " & VarGetType(Json_Get($Obj2, ".binary")) & @LF) ; "Binary"

In my opinion, for human readable data storing or exchanging, of course choose Json. Otherwise, especially to exchange data on the internet, MessagePack may be a better choice. 

MsgPack.zip

Edited by Ward

新版 _ArrayAdd 的白痴作者,不管是誰,去死一死好了

 

Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...