python-suitcase icon indicating copy to clipboard operation
python-suitcase copied to clipboard

Support dynamic start/end offsets for CRCField

Open mikewadsten opened this issue 5 years ago • 0 comments

Suppose there exists a protocol whose messages are laid out as follows:

Offset Size (octets) Description
0 1 Bitfield (request ID, header type, etc)
1 varies Header (length depends on type bits)
1 + len(header) 2 CRC16 from header through end of payload (CRC value = 0)
1 + len(header) + 2 varies Payload (0+ bytes)

We want to be able to place the CRC field into the message structure, and have it:

  • Dynamically compute the beginning offset of the data to be CRC'ed
  • Dynamically compute the end offset of the data to be CRC'ed
  • (Ideally) be able to know the offset and size of the CRC field itself, to replace it with 0 during CRC computation

Basically I would envision the result to look something like this:

class Message(Structure):
    bits = BitField(8, ..., type=BitNum(4))
    header = DispatchTarget(None, bits.type, { ... })
    crc = CRCField(UBInt16(), algo=(ALGORITHM),
                   start=header, end=None,
                   replacement=0x0000)
    payload = Payload()

mikewadsten avatar Mar 21 '19 21:03 mikewadsten