Skip to content

aeb-dev/message_pack_dart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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];
  }
}

To serialize an object to Message Pack format:

MyClass mc = MyClass()
  ..id = 1
  ..name = "aeb"
  ..time = DateTime.now();
Uint8List data = mc.toMessagePack();

To deserialize an object from Message Pack format:

Uint8List data = ... data from somewhere;
MyClass mc = fromMessagePack(data, MyClass.fromMessagePack);

Manually writing

MessagePackWriter writer = MessagePackWriter();
writer.writeString("Hello");
Uint8List data = writer.takeBytes();

Manually reading

Uint8List data = ... data from somewhere;
MessagePackReader reader = MessagePackReader.fromTypedData(data); // there are other alternatives
String sValue = reader.readString();
int iValue = reader.readInt();

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages