Unpacker extension type
A high-performance MessagePack deserializer.
Unpacker is implemented as an extension type over a BinaryReader from
pro_binary, providing a zero-overhead wrapper for decoding MessagePack
data.
Features:
- Zero-Overhead: No extra memory or object allocation for the wrapper.
- Efficient Decoding: Stream-like parsing with minimal branching.
- Buffer Reuse: Supports rebind to switch buffers without re-allocating the reader or unpacker instances.
Example:
final unpacker = Unpacker(buffer: bytes);
final data = unpacker.unpack();
- on
-
- _UnpackerState
Constructors
Properties
- hasBytesAvailable → bool
-
Whether there are more bytes to read in the current buffer.
no setter
- offset → int
-
The current read position in the underlying buffer.
no setter
- remainingBytes → Uint8List
-
Returns the bytes remaining in the buffer from the current position.
no setter
Methods
-
readBytes(
int length) → Uint8List -
Reads
lengthbytes directly from the underlying buffer. -
rebind(
Uint8List buffer) → void -
Rebinds the underlying
BinaryReaderto a newbufferwithout creating a new Unpacker instance. -
skip(
) → void - Advances past exactly one complete value of any type (scalar, string, binary, array, map, ext, nil), leaving the reader positioned at the next value. For an array or map it skips the header and all nested elements recursively.
-
unpack(
) → dynamic - Unpacks the next object from the buffer, automatically detecting its type.
-
unpackArray(
) → List? - Unpacks the next value as an array (List).
-
unpackArrayLength(
) → int - Reads only the next array header and returns its element count.
-
unpackArrayOf<
T> () → List< T> -
Unpacks the next value as an array of a specific type
T. -
unpackAs<
T> () → T -
Unpacks the next value as the expected type
T. -
unpackBinary(
) → Uint8List? - Unpacks the next value as binary data (Uint8List).
-
unpackBool(
) → bool? - Unpacks the next value as a boolean.
-
unpackDouble(
) → double? - Unpacks the next value as a double (float 32 or float 64).
-
unpackExt<
T> () → T -
Unpacks the next value as a custom extension type
T. -
unpackInt(
) → int? - Unpacks the next value as an integer.
-
unpackMap(
) → Map? - Unpacks the next value as a Map.
-
unpackMapLength(
) → int - Reads only the next map header and returns its entry count.
-
unpackMapOf<
K, V> () → Map< K, V> -
Unpacks the next value as a map with keys of type
Kand values of typeV. -
unpackString(
) → String? - Unpacks the next value as a String.
-
unpackTimestamp(
) → DateTime? - Unpacks the next value as a MessagePack timestamp extension (DateTime).