Class MemoryBackedSerializer

Inheritance Relationships

Derived Types

Class Documentation

class MemoryBackedSerializer

An interface to write/read data to/from some underlying data stream.

Subclassed by gpa::playback::StreamDataSerializer, gpa::serialization::BufferSerializer, gpa::serialization::RandomAccessSerializer, gpa::serialization::StreamSerializer

Public Types

enum SeekOrigin

Values:

enumerator kBegin
enumerator kCurrent
enumerator kEnd

Public Functions

inline virtual ~MemoryBackedSerializer()
virtual size_t WriteRawData(void const *src, size_t size) = 0

Writes the given raw data to the underlying data stream.

virtual size_t ReadRawData(void *dst, size_t size) = 0

Reads raw data from the current position in the underlying data stream into the given destination.

virtual bool EnsureWriteCapacity(size_t const size) = 0

Ensures that there is enough space available for writing to the underlying data stream.

Returns

false if no space of the given size could be made available

virtual bool CheckAvailableData(size_t const size) const = 0

Checks if data is available for reading in the underlying data stream.

Returns

true if data of the given size is available, false otherwise.

virtual void Clear() = 0

Resets the underlying memory stream such that it behaves as an empty one.

virtual bool Seek(int64_t offset, SeekOrigin origin = SeekOrigin::kBegin) = 0

Seeks to the offset in the buffer in bytes.

The offset is based on the given seek origin. A positive number is forward, a negative is backward. If the requested offset is out-of-bounds, the current position is unchanged.

Returns

true on success and the current position is changed. TODO : allow Seek to resize buffer if outside buffer range

virtual size_t GetPosition() const = 0

Returns the offset the current read/write cursor is at.

virtual uint64_t GetAbsolutePosition() const = 0

Access the offset of the current read/write cursor relative to the beginning of the underlying storage.

virtual void *Get(uint64_t offset) const = 0

Return a pointer to the address referenced by offset, relative to the start of the underlying storage.

Parameters

offset -- Offset of memory address relative to start of storage

Returns

If the offset refers to memory within the bounds of the storage as visible to the process, then the method returns a pointer to that memory; nullptr otherwise.

template<typename T>
inline size_t Write(T const &src)

Writes data into the memory stream.

Default case is a direct assignment of the given data.

template<typename T>
inline size_t Read(T &dst)

Reads data from the memory stream.

Default case assigns data directly from the memory stream into the given destination.

template<typename T>
inline void ReadUnsafe(T &dst)

Reads data from the memory stream without safety checks.

Client is responsible for calling CheckAvailableData first.

template<typename T>
inline size_t Peek(T &dst)

Reads data from the memory stream, without updating the "current" pointer.

Useful when you want to see what the next item in a stream would be, without having to put it back

inline bool ResizeFailed() const

Returns true is a resize failed in the lifetime of this serialer. This would normally be due to running out of space to write to.

inline uint64_t AddRef()
inline uint64_t Release()
inline bool IsReferenced() const

Protected Attributes

uint64_t mRefCount = 0
uint8_t *mCurr = nullptr
uint8_t *mWritten = nullptr
bool mResizeFailed = {false}