struct module
The Python standard library module that packs values into bytes, and unpacks them, according to a format string.
In more detail
In the format string, B is an unsigned byte, H a two-byte unsigned integer and I a four-byte unsigned integer. A leading ! or > selects big-endian network byte order. The course uses it to show how small a hand-made binary record is compared with JSON.
Example
struct.pack('!BIH', 1, 42, 99)Related terms
- binary encoding — Representing data as raw bytes laid out by a fixed plan rather than as readable text.
- endianness — The order in which the bytes of a multi-byte number are stored: most significant first (big-endian) or least significant first (little-endian).
- bytes object — A Python value holding raw bytes, numbers from 0 to 255, written like b"abc", as opposed to a string of characters.
Taught in
- Twelve Lines Instead Of Four Hundred — Confluent Apache Kafka Certifications (CCDAK and CCAAK) Exam Prep
- Bytes On The Wire: JSON, Avro And Protobuf — Apache Kafka & Event Streaming
- The Schema Registry — Apache Kafka & Event Streaming