MessagePack class
A high-performance MessagePack codec with custom extension support.
Supports standard MessagePack types and provides a flexible API for registering custom extensions and grouped types.
Example:
final mp = MessagePack(
extensions: (mp) {
mp.register<BigInt>(
extId: 1,
encoder: (v, p) => p.packString(v.toString()),
decoder: (u, l) => BigInt.parse(u.unpackString()!),
);
},
);
final bytes = mp.pack(BigInt.from(42));
final value = mp.unpack<BigInt>(bytes);
Constructors
- MessagePack({void extensions(MessagePack mp)?, int bufferSize = 1024, bool allowOverwrite = false})
- Creates a MessagePack instance.
Properties
- bufferSize → int
-
Default buffer capacity for the internal serializer.
final
-
decoder
→ Converter<
Uint8List, dynamic> -
Exposes the decoder converter for use in standard Dart APIs.
no setteroverride
-
encoder
→ Converter<
dynamic, Uint8List> -
Exposes the encoder converter for use in standard Dart APIs.
no setteroverride
- hashCode → int
-
The hash code for this object.
no setterinherited
-
inverted
→ Codec<
Uint8List, dynamic> -
Inverts
this.no setterinherited - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
streamDecoder
→ StreamTransformer<
List< int> , dynamic> -
Returns a StreamTransformer that decodes a stream of MessagePack bytes
into a stream of objects.
no setter
Methods
-
decode(
Uint8List encoded) → dynamic -
Decodes
encodeddata.inherited -
encode(
dynamic input) → Uint8List -
Encodes
input.inherited -
fuse<
R> (Codec< Uint8List, R> other) → Codec<dynamic, R> -
Fuses
thiswithother.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pack(
dynamic value) → Uint8List -
Encodes
valueinto MessagePack bytes. -
packAll(
Iterable values) → Uint8List -
Encodes a sequence of
valuesinto a single MessagePack buffer. -
register<
T> ({required int extId, required Encoder< T> encoder, required Decoder<T> decoder, bool polymorphic = false}) → void -
Registers a custom extension for type
T. -
registerGroup(
{required int extId, required void builder(MessagePackGroup group)}) → void -
Registers a group of related types under a single
extId. -
toString(
) → String -
A string representation of this object.
inherited
-
unpack<
T> (Uint8List data) → T -
Decodes a single value of type
Tfromdata. -
unpackAll(
Uint8List data) → List -
Decodes every MessagePack value in
datainto a list.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited