sofa_buffers_corelib library

SofaBuffers — Structured Objects For Anyone.

A compact, self-describing, fully streamable binary serialization format. This is corelib-dart, the high-speed Dart core library. It is byte-for-byte compatible with every other SofaBuffers port and validated against the shared conformance vectors.

The public surface uses the fixed sofab namespace (CORELIB_PLAN §6). Import it aliased:

import 'package:sofa_buffers_corelib/sofa_buffers_corelib.dart' as sofab;

// Encode
final bytes = sofab.Encoder.encodeToBytes((e) {
  e.writeUnsigned(1, 0xDEADBEEF);
  e.writeString(5, 'sofab');
});

// Decode
final v = MyVisitor();
final status = sofab.Decoder.decode(bytes, v);
assert(status == sofab.DecodeStatus.complete);

See the Encoder (streaming out) and Decoder (push-feed / pull-read in) classes for the full streaming API, and the example/ directory for the generated-object pattern built on top of these primitives.

Classes

BlobSeq
Collects the elements of a blob wrapper array into out.
Decoder
Streaming SofaBuffers decoder (CORELIB_PLAN §5.2).
ElemRange
The inclusive range an integer array's elements may take under the schema — the range of an InlineInt64Array — or, as ElemRange.boolean, the rule of a boolean array.
Encoder
Streaming SofaBuffers encoder (CORELIB_PLAN §5.1, §6).
FixlenType
The fixlen subtype — the low 3 bits of a fixlen_word (CORELIB_PLAN §4.6).
Float32ArrayDefault
The declared default of an fp32 array field, prepared once so that the test "does this field still equal its default" costs a plain element loop.
Float32MatrixSeq
Collects the rows of an fp32 matrix, each row decoded straight into its slot of out. A row of fp64 elements contradicts the declared element type and is skipped (§7.3).
Float64ArrayDefault
Float32ArrayDefault for an fp64 array field: Float64Lists, 64-bit patterns.
Float64MatrixSeq
Collects the rows of an fp64 matrix — the twin of Float32MatrixSeq.
InlineBytes
A destination for a blob field — and, through InlineString, for a string.
InlineFloat32Array
A destination for an fp32 array field.
InlineFloat64Array
A destination for an fp64 array field.
InlineInt64Array
A destination for an integer array field (arrayUnsigned or arraySigned) — 64-bit elements, which is what both wire types decode to (the declared element width is a schema matter, §4.7).
InlineString
A destination for a string field: its UTF-8 bytes.
IntMatrixSeq
Collects the rows of an integer matrix — an array whose elements are compact integer arrays — each row decoded straight into its slot of out.
MessageSeq<T>
Collects the elements of a struct/union wrapper array into out.
MessageVisitor
A consumer of a SofaBuffers stream (CORELIB_PLAN §5.2, §5.3 — the visitor pattern), and the only decode surface (§5.3.1).
NestedSeq<T>
Collects the rows of an array whose elements are themselves WRAPPER arrays.
StringSeq
Collects the elements of a string wrapper array into out.
WireType
The eight wire types — the low 3 bits of a field header (CORELIB_PLAN §4.3).

Enums

DecodeStatus
The three-valued decode outcome (CORELIB_PLAN §5.2), plus limitExceeded which surfaces a receiver-side policy limit distinctly (CORELIB_PLAN §6.2.1, §6.3): the four-outcome option the spec explicitly permits.
SofabError
Result / error codes for fallible operations (CORELIB_PLAN §6.3). In Dart — an exception-idiomatic language — encoder failures throw SofabException carrying one of these; the decoder reports DecodeStatus instead.

Constants

apiVersion → const int
The integer API version (CORELIB_PLAN §6.2).
arrayMax → const int
fixlenMax → const int
idMax → const int
Field-ID / length / count ceiling: 2^31 − 1 (CORELIB_PLAN §6.2).
maxDepth → const int
Maximum nested-sequence depth (CORELIB_PLAN §4.9, §6.2).
minOutputBuffer → const int
The smallest output buffer this port accepts for streaming (CORELIB_PLAN §5.1).

Functions

decodeUtf8Strict(Uint8List bytes) → String?
Strictly decodes UTF-8 bytes to a Dart String, returning null if they are not well-formed UTF-8 per RFC 3629 — the decode-side twin of encodeUtf8Strict, and never lossy: no U+FFFD substitution, no dropped byte (CORELIB_PLAN §6.4).
elementsEqual<T>(List<T> a, List<T> b) → bool
Whether a and b have the same length and pairwise == elements.
encodeUtf8Strict(String s) → Uint8List?
Strictly encodes a Dart String to UTF-8 bytes, returning null if the string contains an unpaired surrogate (the only way a Dart String can fail to be valid Unicode). Never emits U+FFFD — a strict/fatal encoder as CORELIB_PLAN §6.4 requires (Dart's utf8.encode/TextEncoder are lossy on unpaired surrogates and must not be used here).
floatBitsEqual(List<double> a, List<double> b, {int? length}) → bool
Whether a and b have the same length and the same IEEE-754 bit pattern at every index.
utf8Length(String s) → int
The exact number of UTF-8 bytes s encodes to, without allocating the transcode buffer encodeUtf8Strict would.
utf8LengthStrict(String s) → int
The exact number of UTF-8 bytes s encodes to, or −1 when it holds an unpaired surrogate and therefore cannot be encoded at all.
utf8Valid(Uint8List bytes, [int start = 0, int? end]) → bool
Validates that bytes (optionally the sub-range [start, end)) is well-formed UTF-8 per RFC 3629. Rejects overlong encodings (including the C0 80 "Modified UTF-8" NUL), surrogate code points U+D800–U+DFFF, and code points above U+10FFFF. A bare/embedded U+0000 (single 0x00) is valid.

Typedefs

FlushCallback = void Function(Uint8List chunk)
A flush/drain callback (CORELIB_PLAN §5.1). Receives a view of the newly filled bytes; the encoder reuses its buffer immediately afterwards, so a callback that keeps the data must copy it. The view is only valid for the duration of the call.

Exceptions / Errors

SofabException
Thrown by encoder operations and by convenience decoders on failure.