Skip to content

Simplify the protocol code - #65

Merged
jadamcrain merged 1 commit into
mainfrom
simplify-protocol
Oct 14, 2026
Merged

jadamcrain merged 1 commit into
mainfrom
simplify-protocol

Conversation

@jadamcrain

Copy link
Copy Markdown
Member

Item 5 of #59.

Changes

  • Object headers. One ObjectHeader.parse, matched on the qualifier, replaces ObjectHeaderParser and its seven parser objects. A start/stop header now parses its objects by count, stop − start + 1, so Variation.parse(range) is gone. A variation that takes neither header gives a single message for both: "may not be used with a start/stop or count header". The "may not by used" typo is also fixed in the two prefix messages.
  • Little-endian decoding. Integers.fromBytesLE is now the only little-endian decoder. The field parsers, UInt16LE and the device attribute values all use it, and the byte-taking constructors of SInt16LE, SInt32LE, UInt32LE and UInt48LE are gone. One fixed-width field parser replaces the seven separate ones for the 16-, 32- and 48-bit integers and the floats.
  • Point builders. There's now one builder per kind of value: boolean, double-bit, integer and floating-point. Each variation passes in its point type: an event variation's points are events, and every other variation's are static. That replaces the eight Static/Event factory pairs. Before the change I checked that every variation's old factory matched its object type. The typed copy_with_timestamp overrides are unchanged.
  • Bit fields. BitFields packs and unpacks both single and double bits. It replaces BitFieldParser, DoubleBitFieldParser, DoubleBits, BitFieldBuilder and the now-unused Bits.
  • Frames. TestDriver.toFrames is the one place a message becomes link frames. frameBytes, writeMessage and sendDatagrams all use it, and the order of logging is unchanged.

Checks

A differential test ran a seeded corpus of about 775,000 inputs before and after the change. The corpus has:

  • every variation combined with every qualifier, an unknown qualifier, counts 0 to 3 and 0 to 30 random payload bytes
  • events with relative times that follow a common time of occurrence

For each input it recorded the parsed headers, their contents and points, the re-serialized bytes, and the result of parsing the input as a response. Before and after are identical except for the error message above.

- ObjectHeader.parse matches on the qualifier, in place of seven
  parser objects. Start/stop headers parse their objects by count, so
  Variation.parse(range) is gone, and a variation that takes neither
  says so in one message.
- Integers.fromBytesLE is the one little-endian decoder: the field
  parsers, UInt16LE and the device attribute values use it. One
  fixed-width field parser replaces the seven for 16-, 32- and 48-bit
  integers and floats.
- One point builder for each kind of value, given the point type by
  the variation: an event variation's points are events, and any
  other's static. The Static/Event factory pairs are gone.
- BitFields packs and unpacks single and double bits, in place of two
  parsers, two builders and Bits.
- TestDriver.toFrames is the one place a message becomes link frames.

A seeded corpus of every variation with every qualifier, counts and
payloads parses, iterates and serializes the same as before, apart
from the message above.

Part of #59.
@jadamcrain
jadamcrain merged commit 3248ecd into main Oct 14, 2026
5 checks passed
@jadamcrain
jadamcrain deleted the simplify-protocol branch October 14, 2026 22:03
@jadamcrain jadamcrain mentioned this pull request Oct 14, 2026
8 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant