Parse and build binary data in Python

Quick Overview

This question evaluates proficiency in binary data handling and serialization/deserialization in Python, including little-endian integer encoding, length-prefixed payloads, robust error handling for short reads and invalid lengths, and testability and performance considerations.

Parse and build binary data in Python

Company: OpenAI

Role: Software Engineer

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Technical Screen

Using provided interfaces ByteReader(read(n), read_uint32_le, read_string) and ByteWriter(write(b), write_uint32_le, write_string), implement functions to pack and unpack messages for a simple binary protocol: message = {id:uint32 LE, payload_len:uint32 LE, payload:bytes}. Write parse_message(reader)->Message and build_message(writer, Message)->None with error handling for short reads, invalid lengths, and overflow. Avoid printing for debugging; design tests instead, and explain how you would verify correctness and performance.

Quick Answer: This question evaluates proficiency in binary data handling and serialization/deserialization in Python, including little-endian integer encoding, length-prefixed payloads, robust error handling for short reads and invalid lengths, and testability and performance considerations.

|Home/Data Manipulation (SQL/Python)/OpenAI
OpenAI logo
OpenAI
Sep 6, 2025, 12:00 AM
mediumSoftware EngineerTechnical ScreenData Manipulation (SQL/Python)
18
0

Using provided interfaces ByteReader(read(n), read_uint32_le, read_string) and ByteWriter(write(b), write_uint32_le, write_string), implement functions to pack and unpack messages for a simple binary protocol: message = {id:uint32 LE, payload_len:uint32 LE, payload:bytes}. Write parse_message(reader)->Message and build_message(writer, Message)->None with error handling for short reads, invalid lengths, and overflow. Avoid printing for debugging; design tests instead, and explain how you would verify correctness and performance.

Loading comments...