You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
withKaitaiStream(open(filename, 'rb')) as_io:
rec=RecTypePack(_io)
rec._read()
ifrec.crc16!=crc16(rec._raw_buffer[:-2]): # How to get _raw_buffer?print("invalid record:", rec)
The text was updated successfully, but these errors were encountered:
In the ideal world, you'd want your packet (which you'll be calculating CRC for) in a separate user type, with it's own substream backing it, for example:
rec_type_pack_and_crc:
seq:
- id: packtype: rec_type_packsize: 123# or somehow limit the stream otherwise
- id: crc16type: u2
Then in your app code, you could access _raw_pack or _pack._io or something along these lines.
However, as you've pointed out this needs to designate that substream (with size or term) beforehand, and you don't see to have that knowledge at that stage.
Alternative approach might be (old school) using _io.pos memorization and arithmetics:
This way you can ensure that save_pos1 and save_pos2 are invoked at the right time in your parser, and this will keep positions in the stream to beginning of your packet and end of it. Length of your packet will be save_pos2 - save_pos1. You can read it raw again by doing something like:
How to get the size of the read record and its source buffer for crc validation?
For Example:
The text was updated successfully, but these errors were encountered: