Not published yet
amalgame-msgpack
MessagePack codec (1.0 subset) over the JsonValue tree.
Not published yet
The package has no release in the registry yet: amc package add msgpack fails for now. The codec already ships with amc: with amc 0.8.92, import Amalgame.Formats.MsgPack is enough, nothing to install.
Overview
MessagePack is a binary format, more compact than JSON. MsgPack.EncodeJson turns a JsonValue into bytes, MsgPack.DecodeJson does the reverse. Code that already builds JSON switches to MessagePack by changing one call.
Features
- ✓
MsgPack.EncodeJson(JsonValue)returns aList<int> - ✓
MsgPack.DecodeJson(List<int>)returns aJsonValue - ✓nil, booleans, arrays and maps up to 65,535 items
- ✓Strings up to 65,535 bytes
- ✓Positive integers up to 2,147,483,647, negative ones down to -128
- ✓Pure Amalgame, no C dependency
Limits
- –No floats: a decimal number becomes
null. - –Negative integers below -128: the result is wrong for now.
- –Strings: outside printable ASCII, each byte (accent, newline) becomes
?. - –No bin, ext or timestamp types.
Example
With amc 0.8.92, put this code in main.am and run amc run main.am: no package to install.
import Amalgame.Formats.Json
import Amalgame.Formats.MsgPack
public class Program {
public static void Main() {
let json: string = "{\"name\":\"ada\",\"age\":36,\"tags\":[\"a\",\"b\"]}" // 40 bytes
let r: JsonResult = Json.Parse(json)
let doc: JsonValue = r.Value
let bytes: List<int> = MsgPack.EncodeJson(doc)
Console.WriteLine(String_FromInt(bytes.Count()) + " bytes") // 25 bytes
let back: JsonValue = MsgPack.DecodeJson(bytes)
Console.WriteLine(Json.Encode(back)) // {"name":"ada","age":36,"tags":["a","b"]}
}
}
At a glance
- License: Apache-2.0
- Install: not in the registry yet; the codec ships with amc
- Source: amalgame-lang/amalgame-msgpack
- Official index: amalgame-lang/packages-index