|
| SerializerBase ()=default |
|
| SerializerBase (uint8_t *ptr, size_t capacity, size_t offset=0) |
|
| SerializerBase (const uint8_t *ptr, size_t size, size_t offset=0) |
|
| SerializerBase (microstrain::Span< const uint8_t > buffer, size_t offset=0) |
|
uint8_t * | getPointer (size_t required_size) |
| Obtains a pointer to the current offset for reading/writing a value of the specified size. This function does NOT advance the offset value. Generally, you should use getPtrAndAdvance() instead. More...
|
|
uint8_t * | getPtrAndAdvance (size_t size) |
| Obtains a pointer to the current offset for reading/writing a value of specified size, and post-increments the offset by that size. Use this function just like pointer(). More...
|
|
void | invalidate () |
| Marks the buffer as invalid, i.e. overrun/error state. All further accesses via pointer(), getPtrAndAdvance(), etc. will fail. (basePointer() and capacity() remain valid) More...
|
|
size_t | setOffset (size_t offset) |
| Sets a new offset and returns the old value. This can be used to save/restore the current offset. Calling setOffset() after an overrun with an in-range (i.e. non-overrun) value restores the non-overrun status. More...
|
|
Represents a view of a buffer of bytes of known capacity.
The class maintains 3 attributes:
- A pointer to the first byte of the buffer.
- A capacity indicating the total size of the buffer.
- An offset, representing the number of bytes read or written.
This class works for either reading or writing data. As data is written/ read, the offset is incremented. Through functions such as pointer() and getPtrAndAdvance(), the next readable/writable location can be accessed. Both of these take a 'required_size' parameter indicating the amount of data intending to be read/written. If sufficient data/space remains, a valid pointer is returned. Otherwise, NULL is returned. The offset is incremented in getPtrAndAdvance() regardless. This means the offset can exceed the size/capacity of the buffer. This is an "overrun" condition, and it can be checked with the isOk(), isFinished(), or hasRemaining() functions. This behavior prevents bugs where an object is partially read/written in the case where a larger parameter (say u32) fails but then a smaller one (say u8) succeeds. With this class an overflowing access will cause every following access to fail. Note that "overrun" here does NOT mean that an out-of-bounds access has occurred.
- Note
- This class can be constructed with a const buffer, however constness is not enforced. It is up to the user to ensure const buffers are not written.