field_fixed library

Field-level encoding for protobuf fixed-width integer and floating-point types.

Wraps the wire primitives from wire_fixed.dart with field tag emission and proto3 default-value skipping (zero values are not serialized).

Fixed-width wire types:

  • Wire type 5 (I32): fixed32, sfixed32, float — 4 bytes little-endian
  • Wire type 1 (I64): fixed64, sfixed64, double — 8 bytes little-endian

IEEE 754 float/double encoding uses dart:typed_data.ByteData for correct bit-level conversion. This is a Dart-native solution; other Ball target languages will need equivalent std_memory operations.

References:

Test vectors: encodeFixed32Field([], 1, 0) -> [] (proto3 default skipped) encodeFixed32Field([], 1, 1) -> 13, 1, 0, 0, 0 encodeFixed64Field([], 1, 0) -> [] (proto3 default skipped) encodeFixed64Field([], 1, 1) -> 9, 1, 0, 0, 0, 0, 0, 0, 0 encodeFloatField([], 1, 0.0) -> [] (proto3 default skipped) encodeFloatField([], 1, 1.0) -> 13, 0, 0, 128, 63 encodeDoubleField([], 1, 0.0) -> [] (proto3 default skipped) encodeDoubleField([], 1, 1.0) -> 9, 0, 0, 0, 0, 0, 0, 240, 63 decodeFloat(0, 0, 128, 63, 0) -> 1.0 decodeDouble(0, 0, 0, 0, 0, 0, 240, 63, 0) -> 1.0

Functions

decodeDouble(List<int> buffer, int offset) double
Decodes 8 little-endian bytes from buffer at offset as an IEEE 754 double-precision float.
decodeFloat(List<int> buffer, int offset) double
Decodes 4 little-endian bytes from buffer at offset as an IEEE 754 single-precision float.
encodeDoubleField(List<int> buffer, int fieldNumber, double value) List<int>
Encodes a double field (wire type 1) into buffer.
encodeFixed32Field(List<int> buffer, int fieldNumber, int value) List<int>
Encodes a fixed32 field (wire type 5) into buffer.
encodeFixed64Field(List<int> buffer, int fieldNumber, int value) List<int>
Encodes a fixed64 field (wire type 1) into buffer.
encodeFloatField(List<int> buffer, int fieldNumber, double value) List<int>
Encodes a float field (wire type 5) into buffer.
encodeSfixed32Field(List<int> buffer, int fieldNumber, int value) List<int>
Encodes an sfixed32 field (wire type 5) into buffer.
encodeSfixed64Field(List<int> buffer, int fieldNumber, int value) List<int>
Encodes an sfixed64 field (wire type 1) into buffer.