Use bytes for protocol fields #62
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #61
add ByteType (derived from IntegerType), and use this for protocol fields (SNMP version, error status / non-repeaters, error index / repeaters).
add _knownLen to IntegerType: defaults to 4 (1 for ByteType), and is set to the decoded _length in fromBuffer().
this is then used in serialise(), where it selectively outputs extra bytes only when needed.
with all that, the resultant outgoing packet will be at least 9 bytes shorter.
for certain packets, it could be 10 bytes shorter, if the decrease by 9 forces a containing struct's length to drop from requiring 2 bytes to encode its length down to 1, etc.
that is the case for the test packet returned by the test.cpp GenerateTestSNMPRequestPacket() function.
it was generating a 133 byte packet, but now is only 123.
update the unit tests to now use a const (const int expected_length = 123;) throughout.