wire_fixed library

Fixed-width (32-bit / 64-bit) and field tag encoding/decoding for protobuf wire format.

These functions implement:

  • Fixed-width little-endian encoding for 32-bit and 64-bit unsigned integers (wire types 5 and 1 respectively).
  • Field tag encoding/decoding, where a tag is (fieldNumber << 3) | wireType serialized as a varint.

No imports beyond implicit dart:core. All operations use only standard Dart integer arithmetic, bitwise ops, and list manipulation -- primitives that map directly to Ball std base functions.

References:

Test vectors: encodeFixed32([], 0) -> 0, 0, 0, 0 encodeFixed32([], 1) -> 1, 0, 0, 0 encodeFixed32([], 256) -> 0, 1, 0, 0 encodeFixed32([], 0xFFFFFFFF) -> 255, 255, 255, 255 decodeFixed32(1, 0, 0, 0, 0) -> {value: 1, bytesRead: 4}

encodeFixed64([], 0) -> 0, 0, 0, 0, 0, 0, 0, 0 encodeFixed64([], 1) -> 1, 0, 0, 0, 0, 0, 0, 0 encodeFixed64([], 256) -> 0, 1, 0, 0, 0, 0, 0, 0 decodeFixed64(1, 0, 0, 0, 0, 0, 0, 0, 0) -> {value: 1, bytesRead: 8}

encodeTag([], 1, 0) -> 8 (field 1, varint) encodeTag([], 2, 2) -> 18 (field 2, length-delimited) decodeTag(8, 0) -> {fieldNumber: 1, wireType: 0, bytesRead: 1}

Functions

decodeFixed32(List<int> buffer, int offset) Map<String, int>
Decodes 4 little-endian bytes from buffer starting at offset as an unsigned 32-bit integer.
decodeFixed64(List<int> buffer, int offset) Map<String, int>
Decodes 8 little-endian bytes from buffer starting at offset as an unsigned 64-bit integer.
decodeTag(List<int> buffer, int offset) Map<String, int>
Decodes a protobuf field tag from buffer starting at offset.
encodeFixed32(List<int> buffer, int value) List<int>
Appends 4 little-endian bytes representing value as an unsigned 32-bit integer to buffer.
encodeFixed64(List<int> buffer, int value) List<int>
Appends 8 little-endian bytes representing value as an unsigned 64-bit integer to buffer.
encodeTag(List<int> buffer, int fieldNumber, int wireType) List<int>
Encodes a protobuf field tag and appends the varint-encoded bytes to buffer.