F´ Flight Software - C/C++ Documentation
devel
A framework for building embedded system applications to NASA flight quality standards.
|
#include <Fw/Buffer/Buffer.hpp>
Public Types | |
enum | { SERIALIZED_SIZE = sizeof(U32) + sizeof(U32) + sizeof(U8*) , NO_CONTEXT = 0xFFFFFFFF } |
Public Types inherited from Fw::Serializable | |
using | SizeType = NATIVE_UINT_TYPE |
Public Member Functions | |
Buffer () | |
Buffer (const Buffer &src) | |
Buffer (U8 *data, U32 size, U32 context=NO_CONTEXT) | |
Buffer & | operator= (const Buffer &src) |
bool | operator== (const Buffer &src) const |
SerializeBufferBase & | getSerializeRepr () |
Fw::SerializeStatus | serialize (Fw::SerializeBufferBase &serialBuffer) const |
Fw::SerializeStatus | deserialize (Fw::SerializeBufferBase &buffer) |
bool | isValid () const |
U8 * | getData () const |
U32 | getSize () const |
U32 | getContext () const |
void | setData (U8 *data) |
void | setSize (U32 size) |
void | setContext (U32 context) |
void | set (U8 *data, U32 size, U32 context=NO_CONTEXT) |
Additional Inherited Members | |
Protected Member Functions inherited from Fw::Serializable | |
Serializable () | |
Default constructor. More... | |
virtual | ~Serializable () |
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 data, a U32 size of that data, 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.
Fw::Buffer also comes with functions to return a representation of the data as a SerializeBufferBase. 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 43 of file Buffer.hpp.
anonymous enum |
Enumerator | |
---|---|
SERIALIZED_SIZE | Size of Fw::Buffer when serialized. |
NO_CONTEXT | Value representing no context. |
Definition at line 47 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 30 of file Buffer.cpp.
Fw::Buffer::Buffer | ( | U8 * | data, |
U32 | 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 41 of file Buffer.cpp.
|
virtual |
Deserializes this buffer from a SerializeBufferBase
This deserializes the buffer from a SerializeBufferBase, 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 134 of file Buffer.cpp.
U32 Fw::Buffer::getContext | ( | ) | const |
Returns creation context
Definition at line 76 of file Buffer.cpp.
U8 * Fw::Buffer::getData | ( | ) | const |
Returns wrapped data pointer
Definition at line 68 of file Buffer.cpp.
Fw::SerializeBufferBase & Fw::Buffer::getSerializeRepr | ( | ) |
Returns a SerializeBufferBase representation of the wrapped data for serializing
Returns a SerializeBufferBase 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.
Definition at line 107 of file Buffer.cpp.
U32 Fw::Buffer::getSize | ( | ) | const |
Returns size of wrapped data
Definition at line 72 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 64 of file Buffer.cpp.
Assignment operator to set given buffer's members from another without copying wrapped data
Definition at line 52 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 60 of file Buffer.cpp.
|
virtual |
Serializes this buffer to a SerializeBufferBase
This serializes the buffer to a SerializeBufferBase, 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 111 of file Buffer.cpp.
void Fw::Buffer::set | ( | U8 * | data, |
U32 | size, | ||
U32 | context = NO_CONTEXT |
||
) |
Sets all values
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 98 of file Buffer.cpp.
void Fw::Buffer::setContext | ( | U32 | context | ) |
Sets creation context
Definition at line 94 of file Buffer.cpp.
void Fw::Buffer::setData | ( | U8 * | data | ) |
Sets pointer to wrapped data and the size of the given data
Definition at line 80 of file Buffer.cpp.
void Fw::Buffer::setSize | ( | U32 | size | ) |
Sets pointer to wrapped data and the size of the given data
Definition at line 87 of file Buffer.cpp.