Level 1 Snapshot to a single blob
Build KVStore(fs), a string-to-string store that can be written to storage and read back by a brand-new instance.
The tests hand you a fake file system fs with two methods:
fs.save_blob(data: bytes) -> Nonereplaces the stored blob.fs.get_blob() -> bytes | Nonereturns the last saved blob, orNoneif nothing has been saved yet.
Your class:
put(key, value)andget(key)work in memory;getreturnsNonefor a missing key.shutdown()encodes the whole store intobytesand saves it.restore()loads the blob and replaces the in-memory contents with it (an empty store if nothing was saved).
The catch: design the byte format yourself. Don't use json, pickle, marshal, shelve, repr/eval or similar. Keys and values can contain anything: :, ,, =, quotes, newlines, \x00, emoji, or text that looks like your own length markers. Picking a separator character and hoping it never appears in the data is the classic mistake.
The starter gives you helpers: serialize_int(n) turns an unsigned int into exactly 4 bytes, serialize_str(s) UTF-8-encodes a string, plus their deserialize_* inverses. Note that a string's byte length differs from its character length once it has non-ASCII characters.
kv = KVStore(fs)
kv.put("time:now", "a,b=c")
kv.put("multi\nline", "")
kv.shutdown()
again = KVStore(fs)
again.restore()
again.get("time:now") # "a,b=c"
again.get("multi\nline") # ""
again.get("nope") # None
Loading must be linear in the blob size.
Show hint
Escaping is fiddly; instead, prefix every string with its length in bytes. When loading, walk the blob with a position index rather than repeatedly slicing off the part you've read.