solana_kit_codecs library

Classes

ArrayLikeCodecSize
Determines how the size of an array-like codec is specified.
BinaryFixedPoint
A binary fixed-point value.
BinaryFixedPointBase10
Exact base-10 representation of a binary fixed-point value.
BooleanCodecConfig
Configuration options for boolean codecs.
Codec<TFrom, TTo>
An object that can both encode and decode values.
ConstantNoneValue
null values are replaced with a predefined byte sequence.
ConstantOptionNoneValue
None values are replaced with a predefined byte sequence.
DecimalFixedPoint
A decimal fixed-point value.
Decoder<T>
An object that can decode a Uint8List into a value of type T.
Encoder<T>
An object that can encode a value of type T into a Uint8List.
FixedArraySize
The array has a fixed number of items.
FixedPointCodec<T>
Fixed-size codec for fixed-point values.
FixedPointDecoder<T>
Fixed-size decoder for fixed-point values.
FixedPointEncoder<T>
Fixed-size encoder for fixed-point values.
FixedPointToStringOptions
Options for fixed-point string formatting helpers.
FixedSizeCodec<TFrom, TTo>
A fixed-size codec where encoding always produces fixedSize bytes and decoding always consumes fixedSize bytes.
FixedSizeDecoder<T>
A fixed-size decoder that always reads exactly fixedSize bytes.
FixedSizeEncoder<T>
A fixed-size encoder where every encoded value occupies exactly fixedSize bytes.
None<T>
Represents an Option that contains no value.
NoneValue
Specifies how null values are represented in the encoded data.
NumberCodecConfig
Configuration for number codecs.
OffsetConfig
Configuration for modifying the offset of an encoder, decoder, or codec.
OmitNoneValue
null values are omitted from encoding (the default).
OmitOptionNoneValue
None values are omitted from encoding (the default).
Option<T>
A Rust-like Option<T> type for representing optional values.
OptionNoneValue
Specifies how None values are represented in the encoded data.
PostOffsetScope
Extended scope for post-offset functions, which also includes the new pre-offset and the original post-offset.
PrefixedArraySize
The array size is prefixed with a number codec.
PreOffsetScope
Scope provided to pre-offset and post-offset functions.
RemainderArraySize
The array size is inferred from remaining bytes (only for fixed-size items).
Some<T>
Represents an Option that contains a value.
Union2<T0, T1>
A typed two-variant union value.
Union2Variant0<T0, T1>
Variant 0 for Union2.
Union2Variant1<T0, T1>
Variant 1 for Union2.
Union3<T0, T1, T2>
A typed three-variant union value.
Union3Variant0<T0, T1, T2>
Variant 0 for Union3.
Union3Variant1<T0, T1, T2>
Variant 1 for Union3.
Union3Variant2<T0, T1, T2>
Variant 2 for Union3.
VariableSizeCodec<TFrom, TTo>
A variable-size codec whose byte size depends on the value being encoded/decoded.
VariableSizeDecoder<T>
A variable-size decoder whose byte consumption depends on the data.
VariableSizeEncoder<T>
A variable-size encoder whose byte length depends on the value being encoded.
ZeroesNoneValue
The bytes allocated for the value are filled with zeroes. This requires a fixed-size codec.
ZeroesOptionNoneValue
The bytes allocated for the value are filled with zeroes. This requires a fixed-size codec for the item.

Enums

FixedPointEndian
Byte order used by fixed-point codecs.
FixedPointRoundingMode
Rounding strategy used by fixed-point operations that must coerce an exact mathematical result into a value with fewer bits of precision.
FixedPointSignedness
Whether a fixed-point value may be negative.
Utf8NullCharacterMode
Controls how UTF-8 decoders handle decoded null (\u0000) characters.

Functions

absoluteBinaryFixedPoint(BinaryFixedPoint value) BinaryFixedPoint
Returns the absolute value of value.
absoluteDecimalFixedPoint(DecimalFixedPoint value) DecimalFixedPoint
Returns the absolute value of value.
addBinaryFixedPoint(BinaryFixedPoint a, BinaryFixedPoint b) BinaryFixedPoint
Adds two binary fixed-point values of the same shape.
addCodecSentinel<TFrom, TTo>(Codec<TFrom, TTo> codec, Uint8List sentinel) Codec<TFrom, TTo>
Creates a codec that writes a sentinel byte sequence after the encoded value and, when decoding, reads until the sentinel is found.
addCodecSizePrefix<TFrom, TTo>(Codec<TFrom, TTo> codec, Codec<num, num> prefix) Codec<TFrom, TTo>
Stores the byte size of codec as an encoded number prefix.
addDecimalFixedPoint(DecimalFixedPoint a, DecimalFixedPoint b) DecimalFixedPoint
Adds two decimal fixed-point values of the same shape.
addDecoderSentinel<TTo>(Decoder<TTo> decoder, Uint8List sentinel) Decoder<TTo>
Creates a decoder that continues reading until a given sentinel byte sequence is found.
addDecoderSizePrefix<TTo>(Decoder<TTo> decoder, Decoder<num> prefix) Decoder<TTo>
Bounds the size of the nested decoder by reading its encoded prefix.
addEncoderSentinel<TFrom>(Encoder<TFrom> encoder, Uint8List sentinel) Encoder<TFrom>
Creates an encoder that writes a sentinel byte sequence after the encoded value.
addEncoderSizePrefix<TFrom>(Encoder<TFrom> encoder, Encoder<num> prefix) Encoder<TFrom>
Stores the size of the encoder in bytes as a prefix using the prefix encoder.
applyDecimalsOption(BigInt raw, int currentDecimals, [FixedPointToStringOptions options = const FixedPointToStringOptions()]) → ({int decimals, BigInt raw})
Applies the configured target decimal count to a base-10 scaled integer.
assertBigIntIsBetweenForCodec(String codecDescription, BigInt min, BigInt max, BigInt value) → void
Asserts that value is between min and max (inclusive) for a codec named codecDescription, using BigInt comparison.
assertByteArrayHasEnoughBytesForCodec(String codecDescription, int expected, Uint8List bytes, [int offset = 0]) → void
Asserts that the byte array has at least expected bytes remaining after offset.
assertByteArrayIsNotEmptyForCodec(String codecDescription, Uint8List bytes, [int offset = 0]) → void
Asserts that the byte array is not empty after the optional offset.
assertByteArrayOffsetIsNotOutOfRange(String codecDescription, int offset, int bytesLength) → void
Asserts that offset is within the valid range [0, bytesLength].
assertIsBinaryFixedPoint(Object? value, [FixedPointSignedness? signedness, int? totalBits, int? fractionalBits]) → void
Asserts that value is a BinaryFixedPoint matching the optional shape.
assertIsDecimalFixedPoint(Object? value, [FixedPointSignedness? signedness, int? totalBits, int? decimals]) → void
Asserts that value is a DecimalFixedPoint matching the optional shape.
assertIsFixedSize(Object? object) → void
Asserts that the given object is fixed-size.
assertIsVariableSize(Object? object) → void
Asserts that the given object is variable-size.
assertNumberIsBetweenForCodec(String codecDescription, num min, num max, num value) → void
Asserts that value is between min and max (inclusive) for a codec named codecDescription.
assertValidBaseString(String alphabet, String testValue, [String? givenValue]) → void
Asserts that a given string contains only characters from the specified alphabet.
assertValidNumberOfItemsForCodec(String codecDescription, int expected, int actual) → void
Checks the number of items in an array-like structure is expected.
binaryFixedPoint(FixedPointSignedness signedness, int totalBits, int fractionalBits) BinaryFixedPoint Function(String value, [FixedPointRoundingMode rounding])
Returns a factory that parses decimal strings into BinaryFixedPoint values.
binaryFixedPointToBase10(BinaryFixedPoint value) BinaryFixedPointBase10
Converts value to an exact base-10 (raw, decimals) representation.
binaryFixedPointToNumber(BinaryFixedPoint value) double
Converts a binary fixed-point value to a Dart double.
binaryFixedPointToString(BinaryFixedPoint value, [FixedPointToStringOptions options = const FixedPointToStringOptions()]) String
Formats a binary fixed-point value as a canonical decimal string.
bytesEqual(Uint8List bytes1, Uint8List bytes2) bool
Returns true if bytes1 and bytes2 are element-wise equal.
cmpBinaryFixedPoint(BinaryFixedPoint a, BinaryFixedPoint b) int
Compares two binary fixed-point values with the same fractional bit count.
cmpDecimalFixedPoint(DecimalFixedPoint a, DecimalFixedPoint b) int
Compares two decimal fixed-point values with the same decimal scale.
combineCodec<TFrom, TTo>(Encoder<TFrom> encoder, Decoder<TTo> decoder) Codec<TFrom, TTo>
Combines an Encoder and a Decoder into a Codec.
containsBytes(Uint8List data, Uint8List bytes, int offset) bool
Returns true if data contains bytes at the given offset.
createDecoderThatConsumesEntireByteArray<T>(Decoder<T> decoder) Decoder<T>
Creates a Decoder that asserts the bytes provided to decode or read are fully consumed by the inner decoder.
decimalFixedPoint(FixedPointSignedness signedness, int totalBits, int decimals) DecimalFixedPoint Function(String value, [FixedPointRoundingMode rounding])
Returns a factory that parses decimal strings into DecimalFixedPoint values.
decimalFixedPointToNumber(DecimalFixedPoint value) double
Converts a decimal fixed-point value to a Dart double.
decimalFixedPointToString(DecimalFixedPoint value, [FixedPointToStringOptions options = const FixedPointToStringOptions()]) String
Formats a decimal fixed-point value as a canonical decimal string.
decoderFromCodec<T>(Codec<Object?, T> codec) Decoder<T>
Extracts a Decoder view from a Codec.
divideBinaryFixedPoint(BinaryFixedPoint a, Object b, [FixedPointRoundingMode rounding = FixedPointRoundingMode.strict]) BinaryFixedPoint
Divides a by b and returns a value with a's shape.
divideDecimalFixedPoint(DecimalFixedPoint a, Object b, [FixedPointRoundingMode rounding = FixedPointRoundingMode.strict]) DecimalFixedPoint
Divides a by b and returns a value with a's shape.
encoderFromCodec<T>(Codec<T, Object?> codec) Encoder<T>
Extracts an Encoder view from a Codec.
eqBinaryFixedPoint(BinaryFixedPoint a, BinaryFixedPoint b) bool
Returns whether a and b represent the same binary fixed-point value.
eqDecimalFixedPoint(DecimalFixedPoint a, DecimalFixedPoint b) bool
Returns whether a and b represent the same decimal fixed-point value.
fixBytes(Uint8List bytes, int length) Uint8List
Fixes bytes to exactly length bytes.
fixCodecSize<TFrom, TTo>(Codec<TFrom, TTo> codec, int fixedBytes) FixedSizeCodec<TFrom, TTo>
Creates a fixed-size codec from a given codec.
fixDecoderSize<TTo>(Decoder<TTo> decoder, int fixedBytes) FixedSizeDecoder<TTo>
Creates a fixed-size decoder from a given decoder.
fixEncoderSize<TFrom>(Encoder<TFrom> encoder, int fixedBytes) FixedSizeEncoder<TFrom>
Creates a fixed-size encoder from a given encoder.
floatDecoderFactory({required String name, required int size, required double get(ByteData data, int offset, Endian endian), NumberCodecConfig? config}) FixedSizeDecoder<double>
Creates a FixedSizeDecoder for a floating-point type using ByteData operations.
formatBinaryFixedPoint(String formatter(String scientificNotation), BinaryFixedPoint value) String
Formats a binary fixed-point value using a caller-provided formatter.
formatDecimalFixedPoint(String formatter(String scientificNotation), DecimalFixedPoint value) String
Formats a decimal fixed-point value using a caller-provided formatter.
formatScaledBigInt(BigInt raw, int decimals, {bool padTrailingZeros = false}) String
Formats a base-10 scaled integer as a decimal string.
getArrayCodec<T>(Codec<T, T> item, {ArrayLikeCodecSize? size, String? description}) Codec<List<T>, List<T>>
Returns a codec for encoding and decoding arrays of values.
getArrayDecoder<T>(Decoder<T> item, {ArrayLikeCodecSize? size, String? description}) Decoder<List<T>>
Returns a decoder for arrays of values.
getArrayEncoder<T>(Encoder<T> item, {ArrayLikeCodecSize? size, String? description}) Encoder<List<T>>
Returns an encoder for arrays of values.
getBase10Codec() VariableSizeCodec<String, String>
Returns a codec for encoding and decoding base-10 strings.
getBase10Decoder() VariableSizeDecoder<String>
Returns a decoder for base-10 strings.
getBase10Encoder() VariableSizeEncoder<String>
Returns an encoder for base-10 strings.
getBase16Codec() VariableSizeCodec<String, String>
Returns a codec for encoding and decoding base-16 (hexadecimal) strings.
getBase16Decoder() VariableSizeDecoder<String>
Returns a decoder for base-16 (hexadecimal) strings.
getBase16Encoder() VariableSizeEncoder<String>
Returns an encoder for base-16 (hexadecimal) strings.
getBase58Codec() VariableSizeCodec<String, String>
Returns a codec for encoding and decoding base-58 strings.
getBase58Decoder() VariableSizeDecoder<String>
Returns a decoder for base-58 strings.
getBase58Encoder() VariableSizeEncoder<String>
Returns an encoder for base-58 strings.
getBase64Codec() VariableSizeCodec<String, String>
Returns a codec for encoding and decoding base-64 strings.
getBase64Decoder() VariableSizeDecoder<String>
Returns a decoder for base-64 strings.
getBase64Encoder() VariableSizeEncoder<String>
Returns an encoder for base-64 strings.
getBaseXCodec(String alphabet) VariableSizeCodec<String, String>
Returns a codec for encoding and decoding base-X strings.
getBaseXDecoder(String alphabet) VariableSizeDecoder<String>
Returns a decoder for base-X encoded strings.
getBaseXEncoder(String alphabet) VariableSizeEncoder<String>
Returns an encoder for base-X encoded strings.
getBaseXResliceCodec(String alphabet, int bits) VariableSizeCodec<String, String>
Returns a codec for encoding and decoding base-X strings using bit re-slicing.
getBaseXResliceDecoder(String alphabet, int bits) VariableSizeDecoder<String>
Returns a decoder for base-X encoded strings using bit re-slicing.
getBaseXResliceEncoder(String alphabet, int bits) VariableSizeEncoder<String>
Returns an encoder for base-X encoded strings using bit re-slicing.
getBinaryFixedPointCodec(FixedPointSignedness signedness, int totalBits, int fractionalBits, {FixedPointEndian endian = FixedPointEndian.little}) FixedPointCodec<BinaryFixedPoint>
Returns a codec for BinaryFixedPoint values with the given shape.
getBinaryFixedPointDecoder(FixedPointSignedness signedness, int totalBits, int fractionalBits, {FixedPointEndian endian = FixedPointEndian.little}) FixedPointDecoder<BinaryFixedPoint>
Returns a decoder for BinaryFixedPoint values with the given shape.
getBinaryFixedPointEncoder(FixedPointSignedness signedness, int totalBits, int fractionalBits, {FixedPointEndian endian = FixedPointEndian.little}) FixedPointEncoder<BinaryFixedPoint>
Returns an encoder for BinaryFixedPoint values with the given shape.
getBitArrayCodec(int size, {bool backward = false}) FixedSizeCodec<List<bool>, List<bool>>
Returns a codec that encodes and decodes boolean arrays as compact bit representations.
getBitArrayDecoder(int size, {bool backward = false}) FixedSizeDecoder<List<bool>>
Returns a decoder that unpacks bits into an array of booleans.
getBitArrayEncoder(int size, {bool backward = false}) FixedSizeEncoder<List<bool>>
Returns an encoder that packs an array of booleans into bits.
getBooleanCodec({Codec<num, num>? size}) Codec<bool, bool>
Returns a codec for encoding and decoding boolean values.
getBooleanDecoder({Decoder<num>? size}) Decoder<bool>
Returns a decoder for boolean values.
getBooleanEncoder({Encoder<num>? size}) Encoder<bool>
Returns an encoder for boolean values.
getBytesCodec() VariableSizeCodec<Uint8List, Uint8List>
Returns a codec for encoding and decoding raw byte arrays.
getBytesDecoder() VariableSizeDecoder<Uint8List>
Returns a decoder for raw byte arrays.
getBytesEncoder() VariableSizeEncoder<Uint8List>
Returns an encoder for raw byte arrays.
getConstantCodec(Uint8List constant) FixedSizeCodec<void, void>
Returns a codec that encodes and decodes a predefined constant byte sequence.
getConstantDecoder(Uint8List constant) FixedSizeDecoder<void>
Returns a decoder that verifies a predefined constant byte sequence.
getConstantEncoder(Uint8List constant) FixedSizeEncoder<void>
Returns an encoder that always writes a predefined constant byte sequence.
getDecimalFixedPointCodec(FixedPointSignedness signedness, int totalBits, int decimals, {FixedPointEndian endian = FixedPointEndian.little}) FixedPointCodec<DecimalFixedPoint>
Returns a codec for DecimalFixedPoint values with the given shape.
getDecimalFixedPointDecoder(FixedPointSignedness signedness, int totalBits, int decimals, {FixedPointEndian endian = FixedPointEndian.little}) FixedPointDecoder<DecimalFixedPoint>
Returns a decoder for DecimalFixedPoint values with the given shape.
getDecimalFixedPointEncoder(FixedPointSignedness signedness, int totalBits, int decimals, {FixedPointEndian endian = FixedPointEndian.little}) FixedPointEncoder<DecimalFixedPoint>
Returns an encoder for DecimalFixedPoint values with the given shape.
getDiscriminatedUnionCodec(List<(Object?, Codec<Object?, Object?>)> variants, {String discriminator = '__kind', Codec<num, num>? size}) Codec<Map<String, Object?>, Map<String, Object?>>
Returns a codec for encoding and decoding discriminated unions.
getDiscriminatedUnionDecoder(List<(Object?, Decoder<Object?>)> variants, {String discriminator = '__kind', Decoder<num>? size}) Decoder<Map<String, Object?>>
Returns a decoder for discriminated unions.
getDiscriminatedUnionEncoder(List<(Object?, Encoder<Object?>)> variants, {String discriminator = '__kind', Encoder<num>? size}) Encoder<Map<String, Object?>>
Returns an encoder for discriminated unions.
getEncodedSize<T>(T value, Encoder<T> encoder) int
Gets the encoded size of value using the provided encoder.
getF32Codec([NumberCodecConfig? config]) FixedSizeCodec<num, double>
Creates a FixedSizeCodec for 32-bit IEEE 754 floating-point numbers (f32).
getF32Decoder([NumberCodecConfig? config]) FixedSizeDecoder<double>
Creates a FixedSizeDecoder for 32-bit IEEE 754 floating-point numbers (f32).
getF32Encoder([NumberCodecConfig? config]) FixedSizeEncoder<num>
Creates a FixedSizeEncoder for 32-bit IEEE 754 floating-point numbers (f32).
getF64Codec([NumberCodecConfig? config]) FixedSizeCodec<num, double>
Creates a FixedSizeCodec for 64-bit IEEE 754 floating-point numbers (f64).
getF64Decoder([NumberCodecConfig? config]) FixedSizeDecoder<double>
Creates a FixedSizeDecoder for 64-bit IEEE 754 floating-point numbers (f64).
getF64Encoder([NumberCodecConfig? config]) FixedSizeEncoder<num>
Creates a FixedSizeEncoder for 64-bit IEEE 754 floating-point numbers (f64).
getFixedSize(Object codec) int?
Returns the fixed size of a codec, encoder, or decoder, or null if it is variable-size.
getHiddenPrefixCodec<T>(Codec<T, T> codec, List<Codec<void, void>> prefixedCodecs) Codec<T, T>
Returns a codec that encodes and decodes values with a hidden prefix.
getHiddenPrefixDecoder<T>(Decoder<T> decoder, List<Decoder<void>> prefixedDecoders) Decoder<T>
Returns a decoder that skips hidden prefixed data before decoding the main value.
getHiddenPrefixEncoder<T>(Encoder<T> encoder, List<Encoder<void>> prefixedEncoders) Encoder<T>
Returns an encoder that prefixes encoded values with hidden data.
getHiddenSuffixCodec<T>(Codec<T, T> codec, List<Codec<void, void>> suffixedCodecs) Codec<T, T>
Returns a codec that encodes and decodes values with a hidden suffix.
getHiddenSuffixDecoder<T>(Decoder<T> decoder, List<Decoder<void>> suffixedDecoders) Decoder<T>
Returns a decoder that skips hidden suffixed data after decoding the main value.
getHiddenSuffixEncoder<T>(Encoder<T> encoder, List<Encoder<void>> suffixedEncoders) Encoder<T>
Returns an encoder that appends hidden data after the encoded value.
getI128Codec([NumberCodecConfig? config]) FixedSizeCodec<BigInt, BigInt>
Creates a FixedSizeCodec for signed 128-bit integers (i128).
getI128Decoder([NumberCodecConfig? config]) FixedSizeDecoder<BigInt>
Creates a FixedSizeDecoder for signed 128-bit integers (i128).
getI128Encoder([NumberCodecConfig? config]) FixedSizeEncoder<BigInt>
Creates a FixedSizeEncoder for signed 128-bit integers (i128).
getI16Codec([NumberCodecConfig? config]) FixedSizeCodec<num, int>
Creates a FixedSizeCodec for signed 16-bit integers (i16).
getI16Decoder([NumberCodecConfig? config]) FixedSizeDecoder<int>
Creates a FixedSizeDecoder for signed 16-bit integers (i16).
getI16Encoder([NumberCodecConfig? config]) FixedSizeEncoder<num>
Creates a FixedSizeEncoder for signed 16-bit integers (i16).
getI32Codec([NumberCodecConfig? config]) FixedSizeCodec<num, int>
Creates a FixedSizeCodec for signed 32-bit integers (i32).
getI32Decoder([NumberCodecConfig? config]) FixedSizeDecoder<int>
Creates a FixedSizeDecoder for signed 32-bit integers (i32).
getI32Encoder([NumberCodecConfig? config]) FixedSizeEncoder<num>
Creates a FixedSizeEncoder for signed 32-bit integers (i32).
getI64Codec([NumberCodecConfig? config]) FixedSizeCodec<BigInt, BigInt>
Creates a FixedSizeCodec for signed 64-bit integers (i64).
getI64Decoder([NumberCodecConfig? config]) FixedSizeDecoder<BigInt>
Creates a FixedSizeDecoder for signed 64-bit integers (i64).
getI64Encoder([NumberCodecConfig? config]) FixedSizeEncoder<BigInt>
Creates a FixedSizeEncoder for signed 64-bit integers (i64).
getI8Codec() FixedSizeCodec<num, int>
Creates a FixedSizeCodec for signed 8-bit integers (i8).
getI8Decoder() FixedSizeDecoder<int>
Creates a FixedSizeDecoder for signed 8-bit integers (i8).
getI8Encoder() FixedSizeEncoder<num>
Creates a FixedSizeEncoder for signed 8-bit integers (i8).
getLiteralUnionCodec(List<Object?> variants, {Codec<num, num>? size}) Codec<Object?, Object?>
Returns a codec for encoding and decoding literal unions.
getLiteralUnionDecoder(List<Object?> variants, {Decoder<num>? size}) Decoder<Object?>
Returns a decoder for literal unions.
getLiteralUnionEncoder(List<Object?> variants, {Encoder<num>? size}) Encoder<Object?>
Returns an encoder for literal unions.
getMapCodec<K, V>(Codec<K, K> key, Codec<V, V> value, {ArrayLikeCodecSize? size}) Codec<Map<K, V>, Map<K, V>>
Returns a codec for encoding and decoding maps.
getMapDecoder<K, V>(Decoder<K> key, Decoder<V> value, {ArrayLikeCodecSize? size}) Decoder<Map<K, V>>
Returns a decoder for maps.
getMapEncoder<K, V>(Encoder<K> key, Encoder<V> value, {ArrayLikeCodecSize? size}) Encoder<Map<K, V>>
Returns an encoder for maps.
getMaxSize(Object codec) int?
Returns the max size of a codec, encoder, or decoder. For fixed-size objects, returns the fixed size. For variable-size objects, returns maxSize (which may be null).
getNullableCodec<T>(Codec<T, T> item, {Codec<num, num>? prefix, bool hasPrefix = true, NoneValue noneValue = const OmitNoneValue()}) Codec<T?, T?>
Returns a codec for encoding and decoding optional (nullable) values.
getNullableDecoder<T>(Decoder<T> item, {Decoder<num>? prefix, bool hasPrefix = true, NoneValue noneValue = const OmitNoneValue()}) Decoder<T?>
Returns a decoder for optional (nullable) values.
getNullableEncoder<T>(Encoder<T> item, {Encoder<num>? prefix, bool hasPrefix = true, NoneValue noneValue = const OmitNoneValue()}) Encoder<T?>
Returns an encoder for optional (nullable) values.
getOptionCodec<TFrom, TTo extends TFrom>(Codec<TFrom, TTo> item, {Codec<num, num>? prefix, bool hasPrefix = true, OptionNoneValue noneValue = const OmitOptionNoneValue()}) Codec<Object?, Option<TTo>>
Returns a codec for encoding and decoding optional values using the Option type.
getOptionDecoder<TTo>(Decoder<TTo> item, {Decoder<num>? prefix, bool hasPrefix = true, OptionNoneValue noneValue = const OmitOptionNoneValue()}) Decoder<Option<TTo>>
Returns a decoder for optional values using the Option type.
getOptionEncoder<TFrom>(Encoder<TFrom> item, {Encoder<num>? prefix, bool hasPrefix = true, OptionNoneValue noneValue = const OmitOptionNoneValue()}) Encoder<Object?>
Returns an encoder for optional values using the Option type.
getPatternMatchCodec<TFrom, TTo>(List<PatternMatchCodecEntry<TFrom, TTo>> patterns) Codec<TFrom, TTo>
Returns a codec that selects which variant codec to use based on pattern matching.
getPatternMatchDecoder<TTo>(List<PatternMatchDecoderEntry<TTo>> patterns) Decoder<TTo>
Returns a decoder that selects which variant decoder to use based on pattern matching.
getPatternMatchEncoder<TFrom>(List<PatternMatchEncoderEntry<TFrom>> patterns) Encoder<TFrom>
Returns an encoder that selects which variant encoder to use based on pattern matching.
getPredicateCodec<TFrom, TTo extends TFrom>(bool encodePredicate(TFrom value), bool decodePredicate(Uint8List value), Codec<TFrom, TTo> ifTrue, Codec<TFrom, TTo> ifFalse) Codec<TFrom, TTo>
Returns a codec that selects between two codecs using predicates.
getPredicateDecoder<TTo>(bool predicate(Uint8List value), Decoder<TTo> ifTrue, Decoder<TTo> ifFalse) Decoder<TTo>
Returns a decoder that selects between two decoders using predicate.
getPredicateEncoder<TFrom>(bool predicate(TFrom value), Encoder<TFrom> ifTrue, Encoder<TFrom> ifFalse) Encoder<TFrom>
Returns an encoder that selects between two encoders using predicate.
getRawRange(FixedPointSignedness signedness, int totalBits) → ({BigInt max, BigInt min})
Returns the inclusive raw integer range for a fixed-point value.
getSetCodec<T>(Codec<T, T> item, {ArrayLikeCodecSize? size}) Codec<Set<T>, Set<T>>
Returns a codec for encoding and decoding sets.
getSetDecoder<T>(Decoder<T> item, {ArrayLikeCodecSize? size}) Decoder<Set<T>>
Returns a decoder for sets.
getSetEncoder<T>(Encoder<T> item, {ArrayLikeCodecSize? size}) Encoder<Set<T>>
Returns an encoder for sets.
getShortU16Codec() VariableSizeCodec<num, int>
Creates a VariableSizeCodec for Solana's shortU16 compact encoding.
getShortU16Decoder() VariableSizeDecoder<int>
Creates a VariableSizeDecoder for Solana's shortU16 compact encoding.
getShortU16Encoder() VariableSizeEncoder<num>
Creates a VariableSizeEncoder for Solana's shortU16 compact encoding.
getStrictUtf8Codec() VariableSizeCodec<String, String>
Returns a codec for encoding and decoding UTF-8 strings that rejects decoded null characters.
getStrictUtf8Decoder() VariableSizeDecoder<String>
Returns a decoder for UTF-8 strings that rejects decoded null characters.
getStructCodec(List<(String, Codec<Object?, Object?>)> fields) Codec<Map<String, Object?>, Map<String, Object?>>
Returns a codec for encoding and decoding custom objects (structs).
getStructDecoder(List<(String, Decoder<Object?>)> fields) Decoder<Map<String, Object?>>
Returns a decoder for custom objects (structs).
getStructEncoder(List<(String, Encoder<Object?>)> fields) Encoder<Map<String, Object?>>
Returns an encoder for custom objects (structs).
getTupleCodec(List<Codec<Object?, Object?>> items, {String? description}) Codec<List<Object?>, List<Object?>>
Returns a codec for encoding and decoding tuples.
getTupleDecoder(List<Decoder<Object?>> items) Decoder<List<Object?>>
Returns a decoder for tuples (fixed-length lists with heterogeneous item decoders).
getTupleEncoder(List<Encoder<Object?>> items, {String? description}) Encoder<List<Object?>>
Returns an encoder for tuples (fixed-length lists with heterogeneous item encoders).
getU128Codec([NumberCodecConfig? config]) FixedSizeCodec<BigInt, BigInt>
Creates a FixedSizeCodec for unsigned 128-bit integers (u128).
getU128Decoder([NumberCodecConfig? config]) FixedSizeDecoder<BigInt>
Creates a FixedSizeDecoder for unsigned 128-bit integers (u128).
getU128Encoder([NumberCodecConfig? config]) FixedSizeEncoder<BigInt>
Creates a FixedSizeEncoder for unsigned 128-bit integers (u128).
getU16Codec([NumberCodecConfig? config]) FixedSizeCodec<num, int>
Creates a FixedSizeCodec for unsigned 16-bit integers (u16).
getU16Decoder([NumberCodecConfig? config]) FixedSizeDecoder<int>
Creates a FixedSizeDecoder for unsigned 16-bit integers (u16).
getU16Encoder([NumberCodecConfig? config]) FixedSizeEncoder<num>
Creates a FixedSizeEncoder for unsigned 16-bit integers (u16).
getU32Codec([NumberCodecConfig? config]) FixedSizeCodec<num, int>
Creates a FixedSizeCodec for unsigned 32-bit integers (u32).
getU32Decoder([NumberCodecConfig? config]) FixedSizeDecoder<int>
Creates a FixedSizeDecoder for unsigned 32-bit integers (u32).
getU32Encoder([NumberCodecConfig? config]) FixedSizeEncoder<num>
Creates a FixedSizeEncoder for unsigned 32-bit integers (u32).
getU64Codec([NumberCodecConfig? config]) FixedSizeCodec<BigInt, BigInt>
Creates a FixedSizeCodec for unsigned 64-bit integers (u64).
getU64Decoder([NumberCodecConfig? config]) FixedSizeDecoder<BigInt>
Creates a FixedSizeDecoder for unsigned 64-bit integers (u64).
getU64Encoder([NumberCodecConfig? config]) FixedSizeEncoder<BigInt>
Creates a FixedSizeEncoder for unsigned 64-bit integers (u64).
getU8Codec() FixedSizeCodec<num, int>
Creates a FixedSizeCodec for unsigned 8-bit integers (u8).
getU8Decoder() FixedSizeDecoder<int>
Creates a FixedSizeDecoder for unsigned 8-bit integers (u8).
getU8Encoder() FixedSizeEncoder<num>
Creates a FixedSizeEncoder for unsigned 8-bit integers (u8).
getUnion2Codec<T0From, T0To, T1From, T1To>(Codec<T0From, T0To> variant0, Codec<T1From, T1To> variant1, int getIndexFromBytes(Uint8List bytes, int offset)) Codec<Union2<T0From, T1From>, Union2<T0To, T1To>>
Returns a codec for a two-variant typed union.
getUnion2Decoder<T0, T1>(Decoder<T0> variant0, Decoder<T1> variant1, int getIndexFromBytes(Uint8List bytes, int offset)) Decoder<Union2<T0, T1>>
Returns a decoder for a two-variant typed union.
getUnion2Encoder<T0, T1>(Encoder<T0> variant0, Encoder<T1> variant1) Encoder<Union2<T0, T1>>
Returns an encoder for a two-variant typed union.
getUnion3Codec<T0From, T0To, T1From, T1To, T2From, T2To>(Codec<T0From, T0To> variant0, Codec<T1From, T1To> variant1, Codec<T2From, T2To> variant2, int getIndexFromBytes(Uint8List bytes, int offset)) Codec<Union3<T0From, T1From, T2From>, Union3<T0To, T1To, T2To>>
Returns a codec for a three-variant typed union.
getUnion3Decoder<T0, T1, T2>(Decoder<T0> variant0, Decoder<T1> variant1, Decoder<T2> variant2, int getIndexFromBytes(Uint8List bytes, int offset)) Decoder<Union3<T0, T1, T2>>
Returns a decoder for a three-variant typed union.
getUnion3Encoder<T0, T1, T2>(Encoder<T0> variant0, Encoder<T1> variant1, Encoder<T2> variant2) Encoder<Union3<T0, T1, T2>>
Returns an encoder for a three-variant typed union.
getUnionCodec(List<Codec<Object?, Object?>> variants, int getIndexFromValue(Object? value), int getIndexFromBytes(Uint8List bytes, int offset)) Codec<Object?, Object?>
Returns a codec for encoding and decoding union types.
getUnionDecoder(List<Decoder<Object?>> variants, int getIndexFromBytes(Uint8List bytes, int offset)) Decoder<Object?>
Returns a decoder for union types.
getUnionEncoder(List<Encoder<Object?>> variants, int getIndexFromValue(Object? value)) Encoder<Object?>
Returns an encoder for union types.
getUnitCodec() FixedSizeCodec<void, void>
Returns a codec for void values.
getUnitDecoder() FixedSizeDecoder<void>
Returns a decoder for void values.
getUnitEncoder() FixedSizeEncoder<void>
Returns an encoder for void values.
getUtf8Codec({Utf8NullCharacterMode nullCharacterMode = Utf8NullCharacterMode.compatibilityStrip}) VariableSizeCodec<String, String>
Returns a codec for encoding and decoding UTF-8 strings.
getUtf8Decoder({Utf8NullCharacterMode nullCharacterMode = Utf8NullCharacterMode.compatibilityStrip}) VariableSizeDecoder<String>
Returns a decoder for UTF-8 strings.
getUtf8Encoder() VariableSizeEncoder<String>
Returns an encoder for UTF-8 strings.
gtBinaryFixedPoint(BinaryFixedPoint a, BinaryFixedPoint b) bool
Returns whether a is strictly greater than b.
gtDecimalFixedPoint(DecimalFixedPoint a, DecimalFixedPoint b) bool
Returns whether a is strictly greater than b.
gteBinaryFixedPoint(BinaryFixedPoint a, BinaryFixedPoint b) bool
Returns whether a is greater than or equal to b.
gteDecimalFixedPoint(DecimalFixedPoint a, DecimalFixedPoint b) bool
Returns whether a is greater than or equal to b.
isBinaryFixedPoint(Object? value, [FixedPointSignedness? signedness, int? totalBits, int? fractionalBits]) bool
Returns whether value is a BinaryFixedPoint matching the optional shape.
isDecimalFixedPoint(Object? value, [FixedPointSignedness? signedness, int? totalBits, int? decimals]) bool
Returns whether value is a DecimalFixedPoint matching the optional shape.
isFixedSize(Object? object) bool
Returns true if the given encoder, decoder, or codec is fixed-size.
isNone<T>(Option<T> option) bool
Returns true if option is a None.
isOption(Object? input) bool
Returns true if input is an Option (either Some or None).
isSome<T>(Option<T> option) bool
Returns true if option is a Some.
isVariableSize(Object? object) bool
Returns true if the given encoder, decoder, or codec is variable-size.
keccak256(Uint8List input) Uint8List
Computes the Keccak-256 hash of input.
ltBinaryFixedPoint(BinaryFixedPoint a, BinaryFixedPoint b) bool
Returns whether a is strictly less than b.
ltDecimalFixedPoint(DecimalFixedPoint a, DecimalFixedPoint b) bool
Returns whether a is strictly less than b.
lteBinaryFixedPoint(BinaryFixedPoint a, BinaryFixedPoint b) bool
Returns whether a is less than or equal to b.
lteDecimalFixedPoint(DecimalFixedPoint a, DecimalFixedPoint b) bool
Returns whether a is less than or equal to b.
maxCodecSizes(List<int?> sizes) int?
Returns the maximum from a list of nullable codec sizes. Returns null if any size is null.
mergeBytes(List<Uint8List> byteArrays) Uint8List
Concatenates a list of Uint8Lists into a single Uint8List.
multiplyBinaryFixedPoint(BinaryFixedPoint a, Object b, [FixedPointRoundingMode rounding = FixedPointRoundingMode.strict]) BinaryFixedPoint
Multiplies a by b and returns a value with a's shape.
multiplyDecimalFixedPoint(DecimalFixedPoint a, Object b, [FixedPointRoundingMode rounding = FixedPointRoundingMode.strict]) DecimalFixedPoint
Multiplies a by b and returns a value with a's shape.
negateBinaryFixedPoint(BinaryFixedPoint value) BinaryFixedPoint
Returns the additive inverse of a signed binary fixed-point value.
negateDecimalFixedPoint(DecimalFixedPoint value) DecimalFixedPoint
Returns the additive inverse of a signed decimal fixed-point value.
none<T>() Option<T>
Creates a new Option with no value.
numberDecoderFactory({required String name, required int size, required int get(ByteData data, int offset, Endian endian), NumberCodecConfig? config}) FixedSizeDecoder<int>
Creates a FixedSizeDecoder for a numeric type using ByteData operations.
numberEncoderFactory({required String name, required int size, required void set(ByteData data, int offset, num value, Endian endian), NumberCodecConfig? config, (num, num)? range}) FixedSizeEncoder<num>
Creates a FixedSizeEncoder for a numeric type using ByteData operations.
offsetCodec<TFrom, TTo>(Codec<TFrom, TTo> codec, OffsetConfig config) Codec<TFrom, TTo>
Moves the offset of a given codec before and/or after encoding and decoding.
offsetDecoder<T>(Decoder<T> decoder, OffsetConfig config) Decoder<T>
Moves the offset of a given decoder before and/or after decoding.
offsetEncoder<T>(Encoder<T> encoder, OffsetConfig config) Encoder<T>
Moves the offset of a given encoder before and/or after encoding.
padBytes(Uint8List bytes, int length) Uint8List
Pads bytes with trailing zeroes to reach length.
padLeftCodec<TFrom, TTo>(Codec<TFrom, TTo> codec, int offset) Codec<TFrom, TTo>
Adds left padding to codec, shifting encoding and decoding positions forward by offset bytes.
padLeftDecoder<T>(Decoder<T> decoder, int offset) Decoder<T>
Adds left padding to decoder, shifting the decoding position forward by offset bytes and increasing the decoder size accordingly.
padLeftEncoder<T>(Encoder<T> encoder, int offset) Encoder<T>
Adds left padding to encoder, shifting the encoded value forward by offset bytes and increasing the encoder size accordingly.
padNullCharacters(String value, int chars) String
Pads a string with null characters (\u0000) at the end to reach a fixed length.
padRightCodec<TFrom, TTo>(Codec<TFrom, TTo> codec, int offset) Codec<TFrom, TTo>
Adds right padding to codec, extending the encoded/decoded value by offset bytes.
padRightDecoder<T>(Decoder<T> decoder, int offset) Decoder<T>
Adds right padding to decoder, extending the post-offset by offset bytes and increasing the decoder size accordingly.
padRightEncoder<T>(Encoder<T> encoder, int offset) Encoder<T>
Adds right padding to encoder, extending the encoded value by offset bytes and increasing the encoder size accordingly.
ratioBinaryFixedPoint(FixedPointSignedness signedness, int totalBits, int fractionalBits) BinaryFixedPoint Function(BigInt numerator, BigInt denominator, [FixedPointRoundingMode rounding])
Returns a factory that converts ratios into BinaryFixedPoint values.
ratioDecimalFixedPoint(FixedPointSignedness signedness, int totalBits, int decimals) DecimalFixedPoint Function(BigInt numerator, BigInt denominator, [FixedPointRoundingMode rounding])
Returns a factory that converts ratios into DecimalFixedPoint values.
rawBinaryFixedPoint(FixedPointSignedness signedness, int totalBits, int fractionalBits) BinaryFixedPoint Function(BigInt raw)
Returns a factory that wraps raw scaled integers as BinaryFixedPoint values.
rawDecimalFixedPoint(FixedPointSignedness signedness, int totalBits, int decimals) DecimalFixedPoint Function(BigInt raw)
Returns a factory that wraps raw scaled integers as DecimalFixedPoint values.
readBigIntSigned(Uint8List bytes, int offset, int size, Endian endian) BigInt
Reads a signed BigInt value from bytes starting at offset, using size bytes in the given endian byte order.
readBigIntUnsigned(Uint8List bytes, int offset, int size, Endian endian) BigInt
Reads an unsigned BigInt value from bytes starting at offset, using size bytes in the given endian byte order.
removeNullCharacters(String value) String
Removes all null characters (\u0000) from a string.
rescaleBinaryFixedPoint(BinaryFixedPoint value, int newTotalBits, int newFractionalBits, [FixedPointRoundingMode rounding = FixedPointRoundingMode.strict]) BinaryFixedPoint
Rescales value to newTotalBits and newFractionalBits.
rescaleDecimalFixedPoint(DecimalFixedPoint value, int newTotalBits, int newDecimals, [FixedPointRoundingMode rounding = FixedPointRoundingMode.strict]) DecimalFixedPoint
Rescales value to newTotalBits and newDecimals.
resizeCodec<TFrom, TTo>(Codec<TFrom, TTo> codec, int resize(int size)) Codec<TFrom, TTo>
Updates the size of a given codec using a resize function.
resizeDecoder<T>(Decoder<T> decoder, int resize(int size)) Decoder<T>
Updates the size of a given decoder using a resize function.
resizeEncoder<T>(Encoder<T> encoder, int resize(int size)) Encoder<T>
Updates the size of a given encoder using a resize function.
reverseCodec<TFrom, TTo>(FixedSizeCodec<TFrom, TTo> codec) FixedSizeCodec<TFrom, TTo>
Reverses the bytes of a fixed-size codec.
reverseDecoder<TTo>(FixedSizeDecoder<TTo> decoder) FixedSizeDecoder<TTo>
Reverses the bytes of a fixed-size decoder.
reverseEncoder<TFrom>(FixedSizeEncoder<TFrom> encoder) FixedSizeEncoder<TFrom>
Reverses the bytes of a fixed-size encoder.
some<T>(T value) Option<T>
Creates a new Option containing value.
subtractBinaryFixedPoint(BinaryFixedPoint a, BinaryFixedPoint b) BinaryFixedPoint
Subtracts b from a, requiring both values to have the same shape.
subtractDecimalFixedPoint(DecimalFixedPoint a, DecimalFixedPoint b) DecimalFixedPoint
Subtracts b from a, requiring both values to have the same shape.
sumCodecSizes(List<int?> sizes) int?
Sums a list of nullable codec sizes. Returns null if any size is null.
toSignedBinaryFixedPoint(BinaryFixedPoint value) BinaryFixedPoint
Converts value to a signed binary fixed-point value with the same raw value, total bit width, and fractional bit count.
toSignedDecimalFixedPoint(DecimalFixedPoint value) DecimalFixedPoint
Converts value to a signed decimal fixed-point value with the same raw value, total bit width, and decimal scale.
toUnsignedBinaryFixedPoint(BinaryFixedPoint value) BinaryFixedPoint
Converts value to an unsigned binary fixed-point value with the same raw value, total bit width, and fractional bit count.
toUnsignedDecimalFixedPoint(DecimalFixedPoint value) DecimalFixedPoint
Converts value to an unsigned decimal fixed-point value with the same raw value, total bit width, and decimal scale.
transformCodec<TOldFrom, TNewFrom, TOldTo, TNewTo>(Codec<TOldFrom, TOldTo> codec, TOldFrom unmap(TNewFrom value), [TNewTo map(TOldTo value, Uint8List bytes, int offset)?]) Codec<TNewFrom, TNewTo>
Transforms a codec by mapping its input and output values.
transformDecoder<TOldTo, TNewTo>(Decoder<TOldTo> decoder, TNewTo map(TOldTo value, Uint8List bytes, int offset)) Decoder<TNewTo>
Transforms a decoder by mapping its output values.
transformEncoder<TOldFrom, TNewFrom>(Encoder<TOldFrom> encoder, TOldFrom unmap(TNewFrom value)) Encoder<TNewFrom>
Transforms an encoder by mapping its input values.
unwrapOption<T>(Option<T> option) → T?
Unwraps the value of an Option, returning its contained value or null.
unwrapOptionOr<T>(Option<T> option, T fallback()) → T
Unwraps the value of an Option, returning its contained value or the result of fallback.
unwrapOptionRecursively(Object? input, [Object? fallback()?]) Object?
Recursively unwraps all nested Option types within a value.
wrapNullable<T>(T? nullable) Option<T>
Wraps a nullable value into an Option.
writeBigIntSigned(Uint8List bytes, int offset, int size, BigInt value, Endian endian) → void
Writes a signed BigInt value to bytes starting at offset, using size bytes in the given endian byte order.
writeBigIntUnsigned(Uint8List bytes, int offset, int size, BigInt value, Endian endian) → void
Writes an unsigned BigInt value to bytes starting at offset, using size bytes in the given endian byte order.

Typedefs

PatternMatchCodecEntry<TFrom, TTo> = (bool Function(TFrom value), bool Function(Uint8List bytes), Codec<TFrom, TTo>)
A pattern entry for getPatternMatchCodec: a value predicate, a byte predicate, and a codec.
PatternMatchDecoderEntry<TTo> = (bool Function(Uint8List bytes), Decoder<TTo>)
A pattern entry for getPatternMatchDecoder: a byte predicate and a decoder.
PatternMatchEncoderEntry<TFrom> = (bool Function(TFrom value), Encoder<TFrom>)
A pattern entry for getPatternMatchEncoder: a predicate and an encoder.
PostOffsetFunction = int Function(PostOffsetScope scope)
A function that modifies the post-offset after encoding or decoding.
PreOffsetFunction = int Function(PreOffsetScope scope)
A function that modifies the pre-offset before encoding or decoding.