What format I should use in struct.unpack to decode data packed in perl using w format character (as doc says ‘BER compressed integer’)?
What format I should use in struct.unpack to decode data packed in perl using
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t believe python’s struct module has support for that format, it mainly supports only the encodings that are commonly found in C structs. BER & DER encodings are generally only encountered within ASN.1 encoded streams… one of the Python ASN.1 modules might be helpful in that case (I should note they are not that user-friendly).
If not, you may have to implement a decoder yourself. The following bit of code will read off an int, and return where in the string that unpacking should pick up at…
Sadly, this will probably require breaking up your unpack call into unpack, decode_ber_int, and unpack the rest.