A MsgPack library for Beef programming language.
This library is work in progress.
TODO:
- Serialization and deserialization using reflection
- Support for extension types
- More tests, especially for deserialization
In this repository you will find two folders:
lib
is the MsgPackBf library.test
is a program to test MsgPackBf.
Serializing an object/map with the following structure {"compact":true,"schema":0}
:
uint8[] buffer = scope uint8[32];
MsgPacker packer = scope MsgPacker(buffer);
packer.WriteMapHeader(2);
packer.Write("compact");
packer.Write(true);
packer.Write("schema");
packer.Write(0);
Afterwards buffer
will contain your data and packer.Length
is how many bytes are used.
Deserializing the same object/map:
MsgUnpacker unpacker = scope MsgUnpacker(buffer);
let count = (int)unpacker.ReadMapHeader();
bool compact;
int schema;
for (int i < count)
{
let key = scope String();
unpacker.ReadString(key);
switch (key)
{
case "compact":
compact = unpacker.ReadBool().Get();
case "schema":
schema = unpacker.ReadInt32().Get();
default:
// Unknown key
}
}
To add MsgPackBf to your project:
- Clone the MsgPackBf library to a location of your choise.
- In Beef IDE, right click on Workspace->Add existing project.
- Select the
BeefProj.toml
file from the MsgPackBf/lib project. - Open your project's properties. Go to General->Dependencies.
- Tick MsgPackBf.
- You can now start using the library.