Design and implement an in-memory key-value store with a 'medium' layer that serializes the store to bytes for persistence. Provide four functions: set(key, value), get(key), shutdown(), and restore(). On shutdown(), flush all data to the medium; on restore(), rebuild state from the medium. Specify: (a) the medium interface for writing/reading bytes, (b) the serialization format and handling of arbitrary values, (c) error handling and data integrity (atomic flush, crash consistency), (d) complexity and performance considerations, and (e) minimal tests and example usage.