Stage #VT6: Expected string length to be 126 bytes, got 0 bytes

I’m stuck on Stage #VT6

I’ve tried debugging the code by putting a lot of print statements and also reading manually the output, but I couldn’t find the problem.

Here are my logs:

remote: [tester::#VT6] Running tests for Stage #VT6 (Listing Partitions - List for an unknown topic)
remote: [tester::#VT6] $ ./your_program.sh /tmp/server.properties
remote: [tester::#VT6] Connecting to broker at: localhost:9092
remote: [your_program] Logs from your program will appear here!
remote: [tester::#VT6] Connection to broker at localhost:9092 successful
remote: [tester::#VT6] Sending "DescribeTopicPartitions" (version: 0) request (Correlation id: 20146068)
remote: [tester::#VT6] Hexdump of sent "DescribeTopicPartitions" request: 
remote: [tester::#VT6] Idx  | Hex                                             | ASCII
remote: [tester::#VT6] -----+-------------------------------------------------+-----------------
remote: [tester::#VT6] 0000 | 00 00 00 31 00 4b 00 00 01 33 67 94 00 0c 6b 61 | ...1.K...3g...ka
remote: [tester::#VT6] 0010 | 66 6b 61 2d 74 65 73 74 65 72 00 02 12 75 6e 6b | fka-tester...unk
remote: [tester::#VT6] 0020 | 6e 6f 77 6e 2d 74 6f 70 69 63 2d 73 61 7a 00 00 | nown-topic-saz..
remote: [tester::#VT6] 0030 | 00 00 01 ff 00                                  | .....
remote: [tester::#VT6] 
remote: [your_program] accepted new connection
remote: [your_program] Header: 5
remote: [tester::#VT6] Hexdump of received "DescribeTopicPartitions" response: 
remote: [tester::#VT6] Idx  | Hex                                             | ASCII
remote: [your_program] Body: 51
remote: [tester::#VT6] -----+-------------------------------------------------+-----------------
remote: [tester::#VT6] 0000 | 00 00 00 38 01 33 67 94 00 00 00 00 00 02 00 03 | ...8.3g.........
remote: [tester::#VT6] 0010 | 12 75 6e 6b 6e 6f 77 6e 2d 74 6f 70 69 63 2d 73 | .unknown-topic-s
remote: [tester::#VT6] 0020 | 61 7a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | az..............
remote: [tester::#VT6] 0030 | 00 00 00 00 01 00 00 00 00 00 ff 00             | ............
remote: [tester::#VT6] 
remote: [tester::#VT6] [Decoder] - .ResponseHeader
remote: [tester::#VT6] [Decoder]   - .correlation_id (20146068)
remote: [tester::#VT6] [Decoder]   - .TAG_BUFFER
remote: [tester::#VT6] [Decoder] - .ResponseBody
remote: [tester::#VT6] [Decoder]   - .throttle_time_ms (0)
remote: [tester::#VT6] [Decoder]   - .topic.length (1)
remote: [tester::#VT6] [Decoder]   - .Topics[0]
remote: [tester::#VT6] [Decoder]     - .error_code (3)
remote: [tester::#VT6] [Decoder]     - .name (unknown-topic-saz)
remote: [tester::#VT6] [Decoder]     - .topic_id (00000000-0000-0000-0000-000000000000)
remote: [tester::#VT6] [Decoder]     - .is_internal (false)
remote: [tester::#VT6] [Decoder]     - .num_partitions (0)
remote: [tester::#VT6] [Decoder]     - .topic_authorized_operations (16777216)
remote: [tester::#VT6] [Decoder]     - .TAG_BUFFER
remote: [tester::#VT6] [Decoder]   - .next_cursor
remote: [tester::#VT6] Received:
remote: [tester::#VT6] Hex (bytes 51-55)                               | ASCII
remote: [tester::#VT6] ------------------------------------------------+------------------
remote: [tester::#VT6] 00 00 00 ff 00                                  | .....
remote: [tester::#VT6]                 ^                                      ^
remote: [tester::#VT6] Error: Expected string length to be 126 bytes, got 0 bytes
remote: [tester::#VT6] Context:
remote: [tester::#VT6] - DescribeTopicPartitions v0
remote: [tester::#VT6]   - Response Body
remote: [tester::#VT6]     - next_cursor
remote: [tester::#VT6]       - topic_name
remote: [tester::#VT6]         - COMPACT_STRING
remote: [tester::#VT6] 
remote: [tester::#VT6] Test failed
remote: [tester::#VT6] Terminating program
remote: [tester::#VT6] Program terminated successfully

And here’s my code:

https://github.com/prcastro/codecrafters-kafka-rust/blob/master/src/main.rs#L100-L169

Found the issue: Off-by-one mistake when reading and writing the topic name length. I had to do two things:

  • Subtract one when reading the topic name length
  • Add one when writing the topic name length

I found the issue because I was writing the name as having length 0x12 = 18, which means the name should have 18-1 = 17 bytes, but I was writing 18 bytes.

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.