F´ Flight Software - C/C++ Documentation
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(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
 

Public Member Functions

 Buffer ()
 
 Buffer (const Buffer &src)
 
 Buffer (U8 *data, FwSizeType size, U32 context=NO_CONTEXT)
 
Bufferoperator= (const Buffer &src)
 
bool operator== (const Buffer &src) const
 
 DEPRECATED (SerializeBufferBase &getSerializeRepr(), "Switch to .getSerializer() and .getDeserializer()")
 
ExternalSerializeBufferWithMemberCopy getSerializer ()
 
ExternalSerializeBufferWithMemberCopy getDeserializer ()
 
Fw::SerializeStatus serializeTo (Fw::SerializeBufferBase &serialBuffer) const
 
Fw::SerializeStatus deserializeFrom (Fw::SerializeBufferBase &buffer)
 
bool isValid () const
 
U8getData () const
 
FwSizeType getSize () const
 
U32 getContext () const
 
void setData (U8 *data)
 
void setSize (FwSizeType size)
 
void setContext (U32 context)
 
void set (U8 *data, FwSizeType size, U32 context=NO_CONTEXT)
 
- Public Member Functions inherited from Fw::Serializable
SerializeStatus serialize (SerializeBufferBase &buffer) const
 
SerializeStatus deserialize (SerializeBufferBase &buffer)
 

Friends

class Fw::BufferTester
 

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 47 of file Buffer.hpp.

Member Typedef Documentation

◆ SizeType

The size type for a buffer - for backwards compatibility.

Definition at line 52 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 54 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 25 of file Buffer.cpp.

◆ Buffer() [3/3]

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.

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

Definition at line 32 of file Buffer.cpp.

Member Function Documentation

◆ DEPRECATED()

Fw::Buffer::DEPRECATED ( SerializeBufferBase getSerializeRepr(),
"Switch to .getSerializer() and .getDeserializer()"   
)

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

◆ deserializeFrom()

Fw::SerializeStatus Fw::Buffer::deserializeFrom ( 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 139 of file Buffer.cpp.

◆ getContext()

U32 Fw::Buffer::getContext ( ) const

Returns creation context

Definition at line 64 of file Buffer.cpp.

◆ getData()

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

Returns wrapped data pointer

Definition at line 56 of file Buffer.cpp.

◆ getDeserializer()

Fw::ExternalSerializeBufferWithMemberCopy Fw::Buffer::getDeserializer ( )

Returns a ExternalSerializeBufferWithMemberCopy representation of the wrapped data for deserializing

Warning
The entire buffer (up to getSize) is available for deserialization.
Returns
representation of the wrapped data to aid in deserializing to it

Definition at line 105 of file Buffer.cpp.

◆ getSerializer()

Fw::ExternalSerializeBufferWithMemberCopy Fw::Buffer::getSerializer ( )

Returns a ExternalSerializeBufferWithMemberCopy representation of the wrapped data for serializing

Warning
The serialization pointer of the returned ExternalSerializeBufferWithMemberCopy object is set to zero
so that serialization will start at the beginning of the memory pointed to by the Fw::Buffer. If that
behavior is not desired the caller may manipulate the serialization offsets with moveSerToOffset
and serializeSkip methods prior to serialization.
Returns
representation of the wrapped data to aid in serializing to it

Definition at line 95 of file Buffer.cpp.

◆ getSize()

FwSizeType Fw::Buffer::getSize ( ) const

Returns size of wrapped data

Definition at line 60 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 52 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 39 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 47 of file Buffer.cpp.

◆ serializeTo()

Fw::SerializeStatus Fw::Buffer::serializeTo ( 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 116 of file Buffer.cpp.

◆ set()

void Fw::Buffer::set ( U8 data,
FwSizeType  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 86 of file Buffer.cpp.

◆ setContext()

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

Sets creation context

Definition at line 82 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 68 of file Buffer.cpp.

◆ setSize()

void Fw::Buffer::setSize ( FwSizeType  size)

Sets pointer to wrapped data and the size of the given data

Definition at line 75 of file Buffer.cpp.

Friends And Related Function Documentation

◆ Fw::BufferTester

friend class Fw::BufferTester
friend

Definition at line 48 of file Buffer.hpp.


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