NitroWireCodec<T extends Object> class abstract

Platform-neutral codec for a @NitroCustomType T transported across the bridge as an optional fixed-size value: [1B hasValue][encodedSize-1 bytes].

This is the byte-level counterpart of the native-only NitroFfiCodec<T> (which speaks Pointer<Uint8>): the same wire layout expressed over ByteData, so one codec implementation works on native AND web.

Web-targeting specs with @NitroCustomType must provide a NitroWireCodec; native-only specs may keep using NitroFfiCodec.

Example:

class ColorWireCodec extends NitroWireCodec<Color> {
  const ColorWireCodec();
  @override int get encodedSize => 5;   // 1B flag + 4B RGBA

  @override void write(ByteData out, int offset, Color? v) {
    out.setUint8(offset, v != null ? 1 : 0);
    if (v != null) { out.setUint8(offset + 1, v.r); /* ... */ }
  }

  @override Color? read(ByteData bytes, int offset) {
    if (bytes.getUint8(offset) == 0) return null;
    return Color(bytes.getUint8(offset + 1), /* ... */);
  }
}
Implementers

Constructors

NitroWireCodec()
const

Properties

encodedSize → int
Number of bytes this optional type occupies on the wire, including the leading hasValue flag byte.
no setter
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

decodeBytes(Uint8List bytes, [int byteOffset = 0]) → T?
Convenience: decodes a buffer produced by encodeBytes (or the bridge).
encodeBytes(T? value) → Uint8List
Convenience: encodes into a fresh buffer of exactly encodedSize bytes.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
read(ByteData bytes, int byteOffset) → T?
Decodes from byteOffset. First byte is the hasValue flag.
toString() → String
A string representation of this object.
inherited
write(ByteData out, int byteOffset, T? value) → void
Encodes value (possibly null) at byteOffset. Must write exactly encodedSize bytes (out is zeroed when freshly allocated, but a codec must not rely on that for the hasValue flag).

Operators

operator ==(Object other) → bool
The equality operator.
inherited