I’m facing some problems on Stage #SM4, but this can be extended to the entire ‘RDB Persistence’ extension.
The goal is to find the key-value pairs in the hashmap. I have been using the key/value length to extract the key/value. However, some keys/values in the tests don’t provide the length beforehand, making it unclear how to determine when the key/value terminates. My code works correctly for other well-formed test cases.
I don’t know if this is a problem with the tests, or an oversight in reading the instructions on my behalf.
I’ve tried re-reading the instructions repeatedly, and finding a way to extract keys/values without needing the length, but was unsuccessful.
Here are my logs: (RDB file contents are logged to stdout for debugging - apologies for the large length)
[tester::#SM4] Running tests for Stage #SM4 (RDB Persistence - Read value with expiry)
[tester::#SM4] Created RDB file with 5 key-value pairs: {"pineapple": "orange", "grape": "raspberry", "strawberry": "grape", "banana": "apple", "raspberry": "strawberry"}
[tester::#SM4] $ ./your_program.sh --dir /tmp/rdbfiles523881512 --dbfilename pineapple.rdb
[your_program] Logs from your program will appear here!
[tester::#SM4] client: $ redis-cli GET pineapple
[your_program] RDB file contents:
[your_program] 524544495330303131fa72656469732d62697473c040fa0972656469732d76657205372e322e30fe00fb0505fc009cef127e010000000970696e656170706c65066f72616e6765fc000c288ac70100000005677261706509726173706265727279fc000c288ac70100000073747261776265727279056772617065fc000c288ac7010000000662616e616e61056170706c65fc000c288ac7010000000972617370626572727973747261776265727279ffdf0d97f1ff705c07
[your_program] Problem: could not find key data
[tester::#SM4] Received: "" (no content received)
[tester::#SM4] ^ error
[tester::#SM4] Error: Expected start of a new RESP2 value (either +, -, :, $ or *)
[tester::#SM4] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)
As can be seen, the true length of ‘strawberry’ (i.e. 0xA or 10) is not listed before the key of the 3rd pair.
Ultimately, I want to know whether there is something wrong with the test case, or I need to dig deeper.