In python construct library (for parsing binary data), how to group the rest of data as one field? -
I am using the Python Construction Library to parse the Bluetooth protocol. The link of the library is
As the protocols are really complex, I've divided the parsing in several steps, instead of building a gyzy construction. I have already parsed large raw data in this structure:
container ({'CRC': 'DCACT', 'CRC_OK': 1, 'Channel': 38, 'RSS': 43, 'access_addr': 2391391958 L, 'Header': Container ({'TxAd': wrong, 'PDU_langue': 34, 'PDU type': 'ADV_ind', 'RxAd': incorrect)), 'Payload': '2 \ x15 \ x00a \ x02 \ x00 \ x02 \ x01 \ x06 \ x07 \ x03 \ x03 \ x18 \ x02 \ x18 \ x04 \ x18 \ x03 \ x19 \ x00 \ x02 \ x02 \ n \ xFE \ T \ tAS-D1532 '}) As you can see that the length of the payload is in the form of PDU_length Shai's went to a 34. The payload has the following structure: octet: adress] [0-31] The rest of the octets: Advertisement] However, when I started parsing the payload as a standalone structure , Then I lost the length of 34 in terms of its construction. How do I create a payload that will first explain 6 octets as an ad address and say the remaining data data as advert data?
My current solution looks like this:
length = lane (payload) # I did not use PDU_length but Lennon (payload) also gives me 34 back. ADVERT_PAYLOAD = structure ("ADVERT_PAYLOAD", field ("ad entry", 6), field ("addata", length-6), print) ADVERT_PAYLOAD.parse (payload) This is the correct output but apparently all payload sizes are of 34. For this method, I need to create this ADVERT_PAYLOAD eveytime I need to parse a new payload. I have read the documentation several times, there is no way to pass the knowledge of payload length in the context of some related search ADVERT_PAYLOAD , and neither does it pars Is able to get the length of the passage passed in the method. Perhaps there is no solution to this problem. But then, how do most people parse such protocol data? As you go ahead in the payload, it is divided into more types and you need to build more small to parse them. Should I build an original production, embedding small constructions, which also embed small productions?
Thanks in advance.
greedy range will get a list of four, and JoinEditor will be included in all the letters at one time: class JoinAdapter (adapter): Def _decode (auto, obj, context): return "". Adapter (gridirenge (field ("addata", 1)))) payload = '2 \ x15 \ x00a \ x02 \ x00 (Obj) ADVERT_PAYLOAD = structure ("ADVERT_PAYLOAD", field ("ad entry", 6) \ X02 \ x01 \ x06 \ x07 \ x03 \ x03 \ x18 \ x02 \ x18 \ x04 \ x18 \ x03 \ x19 \ x00 \ x02 \ x02 \ n \ xfe Output: < / P>
Container: Adress = '2 \ x15 \ x00a \ x02 \' X00 'AdvertData =' \ x02 \ x01 \ x06 \ x18 \ x02 \ x18 \ x04 \ x18 \ x03 \ X19 \ x00 \ x02 \ x02 \ n \ xfe \ t \ tAS-D1532 \ '
Comments
Post a Comment