Parse Protocol Buffer Text Format Configs Into Nested Dictionaries
Last updated: November 29, 2026
Quick Overview
Write a parser for a subset of protobuf text format, the syntax Google uses for many configuration files: fields name: value, nested messages name { ... } or name < ... >, repeated fields as repeated entries or [a, b] lists, quoted strings with escapes, numbers, booleans, enums, and # comments.
0
0
0 solved
Write a parser for a subset of protobuf text format, the syntax Google uses for many configuration files: fields name: value, nested messages name { ... } or name < ... >, repeated fields as repeated entries or [a, b] lists, quoted strings with escapes, numbers, booleans, enums, and # comments.
Text-format protos are everywhere inside Google (service configs, test data, Borg-style job specs), so this onsite question is grounded in daily work. The interviewer evaluates lexer and parser separation, recursion for nested messages, handling of repeated fields, and error messages that point at the problem.
What the Interviewer Expects
- Separates a regex-based lexer from a recursive descent parser
- Supports nested messages with optional colon and both brace styles
- Accumulates repeated fields, including list syntax
- Decodes string escapes and distinguishes ints, floats, booleans, and enum names
- Fails clearly on unterminated messages or missing values
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Validate the parsed result against a schema, so a typo in a field name is reported with a line number.
- Preserve comments and field order so tools can rewrite the file without losing formatting.
- Without a schema, a field that appears once is a scalar but twice is a list; why is that a problem, and how does real protobuf avoid it?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Fields:
name: value, with value a quoted string, an integer or float,true/false, or an identifier (enum). - Nested messages:
name { ... }orname < ... >, colon optional. - Repeated field...
High-Level Design
The lexer is one regex with alternatives for comments (dropped), punctuation, strings with backslash escapes, identifiers (letters, digits, underscores, dots), and numbers. The parser has `message(clo...