A persistent storage container for variable-length serialized data. Rather than allowing direct access to the underlying buffer for random-access mutations, PersistentBuffer
is mutable through a PersistentBufferWriter
that implements the pw::stream::Writer
interface. This removes the potential for logical errors due to RAII or open()
/close()
semantics as both the PersistentBuffer
and PersistentBufferWriter
can be used validly as long as their access is serialized.
When a PersistentBuffer is statically allocated in persistent memory, its state will persist across soft resets in accordance with the expected behavior of the underlying RAM. This object is completely safe to use before static constructors are called as its constructor is effectively a no-op.
While the stored data can be read via the public functions of PersistentBuffer
, each public function must validate the integrity of the stored data. It's typically more performant to get a handle to a PersistentBufferWriter
instead, as data is validated on creation of the PersistentBufferWriter
, which allows access to the underlying data without needing to validate the data's integrity with each call to PersistentBufferWriter
functions.
Public Member Functions | |
PersistentBuffer (const PersistentBuffer &)=delete | |
PersistentBuffer (PersistentBuffer &&)=delete | |
PersistentBufferWriter | GetWriter () |
size_t | size () const |
const std::byte * | data () const |
void | clear () |
bool | has_value () const |