Now that I’ve covered the essentials of the binary format, those interested might want to try their hand at translating an encoded message. This message uses many of the constructs you’ve seen plus a few more I’ll outline here.
- The record type 0x0B is an XML namespace declaration similar to the record type 0x09 we saw in part 4. With a 0x0B record, the address portion of the namespace is taken from the string table instead of inline character data.
- The range of records 0x0C through 0x25 represent prefixed attributes for the prefixes that are the lowercase letters “a” through “z” and names from the string table. These are the analog of the prefixed dictionary element record types 0x44 through 0x5D we saw in part 6.
- The record type 0x98 provides text content encoded in UTF-8. The record type is followed by the length of the string and then the bytes of the string itself. There are a large number of variations for encoding content but I’ll deliberately be inefficient here to avoid having to introduce more records to you at once.
You should be able to find everything else you might need in past parts of the series:
- Binary Encoding, Part 1
- Binary Encoding, Part 2
- Binary Encoding, Part 3
- Binary Encoding, Part 4
- Binary Encoding, Part 5
- Binary Encoding, Part 6
Now, here’s the message to work on.
0x56, 0x02, 0x0B, 0x01, 0x73, 0x06, 0x0B, 0x01, 0x61, 0x04, 0x56, 0x08, 0x44, 0x0A, 0x1E, 0x00, 0x98, 0x01, 0x31, 0x98, 0x01, 0x61, 0x01, 0x01, 0x56, 0x0E, 0x98, 0x07, 0x4D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x01, 0x01
There are 14 records in this message and you’ll first probably want to find all of the record boundaries. For each record, you need to determine its type and then based on the record type, the number of trailing bytes that are part of the record.