F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
Fw::Buffer Class Reference

#include <Fw/Buffer/Buffer.hpp>

Inheritance diagram for Fw::Buffer:
Fw::Serializable

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)
 
Bufferoperator= (const Buffer &src)
 
bool operator== (const Buffer &src) const
 
SerializeBufferBasegetSerializeRepr ()
 
Fw::SerializeStatus serialize (Fw::SerializeBufferBase &serialBuffer) const
 
Fw::SerializeStatus deserialize (Fw::SerializeBufferBase &buffer)
 
bool isValid () const
 
U8getData () 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...
 

Detailed Description

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.

Member Enumeration Documentation

◆ anonymous enum

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.

Constructor & Destructor Documentation

◆ Buffer() [1/3]

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.

◆ Buffer() [2/3]

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.

◆ Buffer() [3/3]

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.

Parameters
datadata pointer to wrap
sizesize of data located at data pointer
contextuser-specified context to track creation. Default: no context

Definition at line 41 of file Buffer.cpp.

Member Function Documentation

◆ deserialize()

Fw::SerializeStatus Fw::Buffer::deserialize ( Fw::SerializeBufferBase buffer)
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.

Parameters
bufferserialize buffer to read data into
Returns
: status of serialization

Implements Fw::Serializable.

Definition at line 134 of file Buffer.cpp.

◆ getContext()

U32 Fw::Buffer::getContext ( ) const

Returns creation context

Definition at line 76 of file Buffer.cpp.

◆ getData()

U8 * Fw::Buffer::getData ( ) const

Returns wrapped data pointer

Definition at line 68 of file Buffer.cpp.

◆ getSerializeRepr()

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.

Returns
representation of the wrapped data to aid in serializing to it

Definition at line 107 of file Buffer.cpp.

◆ getSize()

U32 Fw::Buffer::getSize ( ) const

Returns size of wrapped data

Definition at line 72 of file Buffer.cpp.

◆ isValid()

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.

◆ operator=()

Buffer & Fw::Buffer::operator= ( const Buffer src)

Assignment operator to set given buffer's members from another without copying wrapped data

Definition at line 52 of file Buffer.cpp.

◆ operator==()

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.

Parameters
srcbuffer to test against
Returns
: true if equivalent, false otherwise

Definition at line 60 of file Buffer.cpp.

◆ serialize()

Fw::SerializeStatus Fw::Buffer::serialize ( Fw::SerializeBufferBase serialBuffer) const
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.

Parameters
serialBufferserialize buffer to write data into
Returns
: status of serialization

Implements Fw::Serializable.

Definition at line 111 of file Buffer.cpp.

◆ set()

void Fw::Buffer::set ( U8 data,
U32  size,
U32  context = NO_CONTEXT 
)

Sets all values

Parameters
datadata pointer to wrap
sizesize of data located at data pointer
contextuser-specified context to track creation. Default: no context

Definition at line 98 of file Buffer.cpp.

◆ setContext()

void Fw::Buffer::setContext ( U32  context)

Sets creation context

Definition at line 94 of file Buffer.cpp.

◆ setData()

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.

◆ setSize()

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.


The documentation for this class was generated from the following files: