01Given `*2\r\n$3\r\nGET\r\n$4\r\nna`, should the parser return an error or wait for more bytes? What fact makes the answer clear?introScenarioYour parser's buffer currently holds the bytes `*2\r\n$3\r\nGET\r\n$4\r\nna` received from one socket read.AReturn an error, because the bulk string `na` is shorter than its declared four bytes, making the frame malformed.BReturn an error, because a RESP array is only valid when it arrives within a single TCP segment.CWait, because a parser must always see a trailing newline before judging any frame, whatever the declared lengths say.DIt should wait for more bytes because the declared bulk length says the payload has not arrived completely yet.
02Why is `SET note "a b"` unsafe to parse by splitting on spaces, even before considering binary data?introScenarioA teammate prototypes command parsing with `input.split(" ")` and asks why that cannot ship.ASplitting on spaces is fine for inline commands, and the only real problem is its performance on long strings whose argument scanning cost grows with the input length.BSplitting on spaces loses RESP framing and quoted or binary-safe payload boundaries; the parser must respect explicit lengths.CThe space split fails only because the TCP layer strips quote characters from the byte stream in transit.DSplitting works if clients escape their spaces, since RESP's length prefixes exist only for binary payloads.
03A buffer contains two complete RESP arrays and half of a third. What should `consumed` represent after the first parse call?appliedScenarioYour parse function takes a buffer and returns parsed values plus a count of bytes it consumed.AConsumed should cover only the complete arrays actually emitted, leaving the half third frame in the buffer for a later read.BConsumed should include the half frame too, since the parser already examined those bytes while scanning.CConsumed should be zero until the buffer holds nothing but complete frames, keeping the bookkeeping simple.DConsumed should always equal the total bytes read from the socket, with the parser tracking its own position separately.
04Which layer should reject a nested array used as a command argument: the RESP parser or command dispatch? Defend one design.appliedScenarioA client sends a syntactically valid RESP array in which one element is itself a nested array, then uses it as a command.AThe RESP parser should reject it, since the grammar of commands forbids arrays inside arrays, and rejecting early spares dispatch from handling malformed shapes.BNeither layer should reject it; the receiving handler can coerce nested arrays into flat strings as needed.CCommand dispatch should reject a nested array as an invalid command argument after the RESP parser has faithfully decoded the RESP value.DThe parser should silently flatten nested arrays, so that dispatch only ever sees strings arrive.
05How does null bulk string output differ from an empty bulk string output on the wire?advancedScenarioYou are implementing GET's reply path and must encode both a missing key and a key holding an empty string.ABoth encode as $0, and clients tell them apart by a flag byte that follows the length line.BA null bulk string is encoded as $-1, while an empty bulk string is encoded with length zero followed by an empty payload.CA null bulk string is the absence of any reply at all, while an empty one is sent as length zero.DNull is sent as the literal word nil in a simple string, and empty as a simple string with no characters, matching what interactive clients print for missing keys.