NitroFfiCodec<T extends Object> class abstract

Codec for a type T that can be transported across the C FFI bridge as an optional value. This is the Dart/FFI equivalent of RN Nitro's JSIConverter<std::optional<T>>.

Built-in codecs: NitroIntCodec, NitroDoubleCodec, NitroBoolCodec.

Example custom codec:

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

  @override Pointer<Uint8> encode(Color? v, Arena alloc) {
    final ptr = alloc<Uint8>(5);
    ptr[0] = v != null ? 1 : 0;
    if (v != null) { ptr[1] = v.r; ptr[2] = v.g; ptr[3] = v.b; ptr[4] = v.a; }
    return ptr;
  }

  @override Color? decode(Pointer<Uint8> ptr) {
    if (ptr[0] == 0) return null;
    return Color(ptr[1], ptr[2], ptr[3], ptr[4]);
  }
}
Implementers

Constructors

NitroFfiCodec()
const

Properties

encodedSize → int
Number of bytes this optional type occupies in native memory.
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

decode(Pointer<Uint8> ptr) → T?
Decode from native memory. First byte is the hasValue flag. Does NOT free the pointer — caller is responsible.
encode(T? value, Arena alloc) → Pointer<Uint8>
Encode value (possibly null) into Arena-allocated native memory. Returns a pointer valid for the lifetime of alloc.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

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