Last updated:
0 purchases
msg pck
Using with objects #
class MyClass with MessagePackObject {
late int id;
late String name;
late DateTime time;
@override
List get messagePackFields => [id, name, time];
MyClass();
MyClass.fromMessagePack(List<dynamic> items) {
id = items[0];
name = items[1];
time = items[2];
}
}
copied to clipboard
To serialize an object to Message Pack format:
MyClass mc = MyClass()
..id = 1
..name = "aeb"
..time = DateTime.now();
Uint8List data = mc.toMessagePack();
copied to clipboard
To deserialize an object from Message Pack format:
Uint8List data = ... data from somewhere;
MyClass mc = fromMessagePack(data, MyClass.fromMessagePack);
copied to clipboard
Manually writing #
MessagePackWriter writer = MessagePackWriter();
writer.writeString("Hello");
Uint8List data = writer.takeBytes();
copied to clipboard
Manually reading #
Uint8List data = ... data from somewhere;
MessagePackReader reader = MessagePackReader.fromTypedData(data); // there are other alternatives
String sValue = reader.readString();
int iValue = reader.readInt();
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.