BsatnEncoder class

Encodes Dart values into BSATN (Binary Spacetime Algebraic Type Notation) format

BSATN is SpacetimeDB's binary serialization format. Use this encoder to:

  • Create reducer/procedure arguments
  • Encode custom data structures
  • Build binary messages for SpacetimeDB

All integers are encoded in little-endian byte order.

Example:

final encoder = BsatnEncoder();

// Encode primitive types
encoder.writeString('Hello');
encoder.writeU32(42);
encoder.writeBool(true);

// Encode optional values
encoder.writeOption<String>('value', (v) => encoder.writeString(v));
encoder.writeOption<String>(null, (v) => encoder.writeString(v));

// Encode arrays
encoder.writeArray([1, 2, 3], (item) => encoder.writeU32(item));

// Get the encoded bytes
final bytes = encoder.toBytes();

// Send to SpacetimeDB
connection.send(bytes);

Constructors

BsatnEncoder()

Properties

hashCode int
The hash code for this object.
no setterinherited
length int
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toBytes() Uint8List
Returns the encoded bytes
toString() String
A string representation of this object.
inherited
writeArray<T>(List<T> items, void writeItem(T)) → void
Encodes an array with length prefix
writeBool(bool value) → void
Encodes a boolean value (false = 0, true = 1)
writeByteArray(List<int> value) → void
writeBytes(Uint8List bytes) → void
writeF32(double value) → void
writeF64(double value) → void
writeI16(int value) → void
writeI32(int value) → void
writeI64(Int64 value) → void
writeI8(int value) → void
writeIdentity(Identity value) → void
writeList<T>(List<T> items, void writeItems(T)) → void
writeMap<K, V>(Map<K, V> map, void writeKey(K), void writeValue(V)) → void
Encodes a map with length prefix
writeOption<T>(T? value, void writeValue(T)) → void
Encodes an optional value
writeProduct(List<void Function()> writeFields) → void
writeString(String value) → void
Encodes a UTF-8 string with length prefix
writeSum(int tag, void writeVariant()) → void
writeU16(int value) → void
Encodes an unsigned 16-bit integer (0-65535) in little-endian
writeU32(int value) → void
Encodes an unsigned 32-bit integer (0-4294967295) in little-endian
writeU64(Int64 value) → void
writeU8(int value) → void
Encodes an unsigned 8-bit integer (0-255)

Operators

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