![]() |
F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
|
#include <Fw/Buffer/Buffer.hpp>
Public Types | |
| enum | OwnershipState { OwnershipState::NOT_OWNED, OwnershipState::OWNED } |
| enum | { SERIALIZED_SIZE = 3 * sizeof(SizeType) + sizeof(U32) + sizeof(U8*), NO_CONTEXT = 0xFFFFFFFF } |
| using | SizeType = FwSizeType |
| The size type for a buffer - for backwards compatibility. More... | |
Public Types inherited from Fw::Serializable | |
| using | SizeType = FwSizeType |
Friends | |
| class | Fw::BufferTester |
Additional Inherited Members | |
Protected Member Functions inherited from Fw::Serializable | |
| Serializable () | |
| Default constructor. More... | |
| virtual | ~Serializable () |
| Virtual destructor. More... | |
Buffer used for wrapping pointer to data for efficient transmission
Fw::Buffer is a wrapper for a pointer to data. It allows for data to be passed around the system without a copy of the data itself. However, it comes with the expectation that the user maintain and protect this memory as it moves about the system until such a time as it is returned.
Fw::Buffer is composed of several elements: a U8* pointer to the original allocation, an offset into that allocation, a size of the represented data, a capacity recording the original allocation size, and a U32 context describing the origin of that data, such that it may be freed at some later point. The default context of 0xFFFFFFFF should not be used for tracking purposes, as it represents a context-free buffer.
The original allocation pointer is always recoverable via getOriginalData(). Consuming leading bytes (e.g. a header) is done with advance(), which adjusts the offset and size without losing the original pointer. setData() and setSize() are bounds-checked against the original allocation: to wrap unrelated memory, construct a new Fw::Buffer or call set().
Fw::Buffer also comes with functions to return a representation of the data as a LinearBufferBase. These two functions allow easy access to the data as if it were a serialize or deserialize buffer. This can aid in writing and reading the wrapped data whereas the standard serialize and deserialize methods treat the data as a pointer to prevent excessive copying.
Definition at line 53 of file Buffer.hpp.
| using Fw::Buffer::SizeType = FwSizeType |
The size type for a buffer - for backwards compatibility.
Definition at line 67 of file Buffer.hpp.
| anonymous enum |
| Enumerator | |
|---|---|
| SERIALIZED_SIZE | Size of Fw::Buffer when serialized. |
| NO_CONTEXT | Value representing no context. |
Definition at line 69 of file Buffer.hpp.
|
strong |
Buffer ownership state
A convenience enumeration to help users implement ownership tracking of buffers.
| Enumerator | |
|---|---|
| NOT_OWNED | The buffer is currently not owned. |
| OWNED | The buffer is currently owned. |
Definition at line 60 of file Buffer.hpp.
| Fw::Buffer::Buffer | ( | ) |
Construct a buffer with no context nor data
Constructs a buffer setting the context to the default no-context value of 0xffffffff. In addition, the size and data pointers are zeroed-out.
Definition at line 23 of file Buffer.cpp.
| Fw::Buffer::Buffer | ( | const Buffer & | src | ) |
Construct a buffer by copying members from a reference to another buffer. Does not copy wrapped data.
Definition at line 32 of file Buffer.cpp.
| Fw::Buffer::Buffer | ( | U8 * | data, |
| FwSizeType | size, | ||
| U32 | context = NO_CONTEXT |
||
| ) |
Construct a buffer to wrap the given data pointer of given size
Wraps the given data pointer with given size in a buffer. The context by default is set to NO_CONTEXT but can be set to specify a specific context.
| data | data pointer to wrap |
| size | size of data located at data pointer |
| context | user-specified context to track creation. Default: no context |
Definition at line 45 of file Buffer.cpp.
| void Fw::Buffer::advance | ( | FwSignedSizeType | amount | ) |
Moves the offset forward (positive) or backward (negative) by the given amount
The size is updated such that the end of the represented data is unchanged. Asserts if the resulting offset is outside [0, capacity] or the resulting size would be negative.
| amount | signed number of bytes to move the offset by |
Definition at line 106 of file Buffer.cpp.
| Fw::Buffer::DEPRECATED | ( | LinearBufferBase & | getSerializeRepr(), |
| "Switch to .getSerializer() and .getDeserializer()" | |||
| ) |
Returns a LinearBufferBase representation of the wrapped data for serializing
Returns a LinearBufferBase representation of the wrapped data allowing for serializing other types of data to the wrapped buffer. Once obtained the user should call one of two functions: sbb.resetSer(); to setup for serialization, or sbb.setBuffLen(buffer.getSize()); to setup for deserializing.
|
virtual |
Deserializes this buffer from a LinearBufferBase
This deserializes the buffer from a LinearBufferBase, however, it DOES NOT handle serialized data. It only deserializes the pointer to said data, the size, and context. This is done for efficiency in moving around data, and is the primary usage of Fw::Buffer. To deserialize the wrapped data, use either the data pointer accessor or the serialize buffer base representation and deserialize from that.
| buffer | serialize buffer to read data into |
Implements Fw::Serializable.
Definition at line 201 of file Buffer.cpp.
| FwSizeType Fw::Buffer::getCapacity | ( | ) | const |
Returns the capacity (size of the original allocation)
Definition at line 94 of file Buffer.cpp.
| U32 Fw::Buffer::getContext | ( | ) | const |
Returns creation context
Definition at line 102 of file Buffer.cpp.
| U8 * Fw::Buffer::getData | ( | ) | const |
Returns pointer to the current data (original allocation pointer plus offset)
Definition at line 82 of file Buffer.cpp.
| Fw::ExternalSerializeBufferWithMemberCopy Fw::Buffer::getDeserializer | ( | ) |
Returns a ExternalSerializeBufferWithMemberCopy representation of the wrapped data for deserializing
Definition at line 165 of file Buffer.cpp.
| FwSizeType Fw::Buffer::getOffset | ( | ) | const |
Returns the current offset from the original allocation pointer
Definition at line 98 of file Buffer.cpp.
| U8 * Fw::Buffer::getOriginalData | ( | ) | const |
Returns the original allocation pointer, regardless of any advance/setData adjustments
Definition at line 86 of file Buffer.cpp.
| Fw::ExternalSerializeBufferWithMemberCopy Fw::Buffer::getSerializer | ( | ) |
Returns a ExternalSerializeBufferWithMemberCopy representation of the wrapped data for serializing
Definition at line 155 of file Buffer.cpp.
| FwSizeType Fw::Buffer::getSize | ( | ) | const |
Returns size of wrapped data
Definition at line 90 of file Buffer.cpp.
| bool Fw::Buffer::isValid | ( | ) | const |
Returns true if the buffer is valid (data pointer != nullptr and size > 0)
Definition at line 78 of file Buffer.cpp.
Assignment operator to set given buffer's members from another without copying wrapped data
Definition at line 58 of file Buffer.cpp.
| bool Fw::Buffer::operator== | ( | const Buffer & | src | ) | const |
Equality operator returning true when buffers are equivalent
Buffers are deemed equivalent if they contain a pointer to the same data, with the same size, and the same context. The representation of that buffer for use with serialization and deserialization need not be equivalent.
| src | buffer to test against |
Definition at line 73 of file Buffer.cpp.
|
virtual |
Serializes this buffer to a LinearBufferBase
This serializes the buffer to a LinearBufferBase, however, it DOES NOT serialize the wrapped data. It only serializes the pointer to said data, the size, and context. This is done for efficiency in moving around data, and is the primary usage of Fw::Buffer. To serialize the wrapped data, use either the data pointer accessor or the serialize buffer base representation and serialize from that.
| serialBuffer | serialize buffer to write data into |
Implements Fw::Serializable.
Definition at line 176 of file Buffer.cpp.
| void Fw::Buffer::set | ( | U8 * | data, |
| FwSizeType | size, | ||
| U32 | context = NO_CONTEXT |
||
| ) |
Sets all values, resetting the original allocation pointer, with capacity = size and offset = 0
| data | data pointer to wrap |
| size | size of data located at data pointer |
| context | user-specified context to track creation. Default: no context |
Definition at line 144 of file Buffer.cpp.
| void Fw::Buffer::setContext | ( | U32 | context | ) |
Sets creation context
Definition at line 140 of file Buffer.cpp.
| void Fw::Buffer::setData | ( | U8 * | data | ) |
Sets pointer to current data within the original allocation
The supplied pointer must lie within the original allocation (original pointer + capacity); the offset is updated accordingly and the size is adjusted such that the end of the represented data is unchanged. Asserts when the pointer is outside the original allocation. To wrap unrelated memory, construct a new Fw::Buffer or call set().
| data | pointer within the original allocation |
Definition at line 125 of file Buffer.cpp.
| void Fw::Buffer::setSize | ( | FwSizeType | size | ) |
Sets size of wrapped data
Asserts unless offset + size <= capacity.
| size | new size of the represented data |
Definition at line 131 of file Buffer.cpp.
|
friend |
Definition at line 54 of file Buffer.hpp.