python-suitcase
python-suitcase copied to clipboard
Support dynamic start/end offsets for CRCField
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()