HDLC-Daemon
Frame Class Referenceabstract

Class Frame. More...

#include <Frame.h>

Inheritance diagram for Frame:

Public Member Functions

 Frame ()
 The constructor of Frame objects. More...
 
virtual ~Frame ()
 The destructor of Frame objects. More...
 
virtual const std::vector< unsigned char > Serialize () const =0
 The purely virtual serializer method. More...
 
size_t BytesNeeded () const
 Query the amount of outstanding data during reception for frame assembly. More...
 
bool ParseBytes (const unsigned char *a_ReadBuffer, size_t &a_ReadBufferOffset, size_t &a_BytesAvailable)
 Deliver a chunk of received bytes in the phase of deserialization. More...
 

Protected Member Functions

virtual bool Deserialize ()=0
 The purely virtual deserializer method. More...
 

Protected Attributes

std::vector< unsigned char > m_Buffer
 The buffer containing partly received frames or higher-layer payload. More...
 
size_t m_BytesRemaining
 The amount of bytes required to finalize frame assembly during reception. More...
 

Detailed Description

Class Frame.

This is the base class of arbitrary frames that can be easily sent and received with the help of FrameEndpoint entities. The serializer and deserializer methods are purely virtual and have to be implemented in the derived class. Besides that, all members, getters and setters related to the specific fields of a user-defined frame also have to be provided in the derived class.

Thus, if creating a derived frame for a specific frame, one solely has to concentrate on the relevant stuff:

  • which data has to be communicated via this frame (members) and
  • how are the data arranged in the frame, i.e., the frame format, by specifying the serializer and deserializer.
  • All sending / receiving / creation of incoming frames entities is performed "under the hood" by a FrameEndpoint entity.

Definition at line 59 of file Frame.h.

Constructor & Destructor Documentation

Frame::Frame ( )
inline

The constructor of Frame objects.

All internal members are initialized here. No need for the user of this class to adapt something here.

Definition at line 65 of file Frame.h.

virtual Frame::~Frame ( )
inlinevirtual

The destructor of Frame objects.

Definition at line 69 of file Frame.h.

Here is the call graph for this function:

Member Function Documentation

size_t Frame::BytesNeeded ( ) const
inline

Query the amount of outstanding data during reception for frame assembly.

This method is called by a FrameEndpoint entity in the phase of reception. It is used to query the amount of bytes that are required to assemble a full frame of the specific type by reading from a TCP socket. Depending on the internal structure of a frame it is possible that it read in multiple stages, e.g., if at first a length field of a known length has to be read followed by the remainder containing a dynamic amount of bytes. Such a logic has to be implemented in the Deserialize() method of the derived class.

Returns
size_t the amount subsequent bytes required to assemble the frame

Definition at line 91 of file Frame.h.

virtual bool Frame::Deserialize ( )
protectedpure virtual

The purely virtual deserializer method.

This purely virtual deserializer method has to be implemented in the derived class. Here the user specifies the format of the frame's fields for frames that are received. This method is solely called by the ParseBytes() method after a specified amount of bytes was successfully received.

Return values
trueno error occured
falsea protocol violation was detected
Returns
Indicates success or failure of parsing the provided chunk of bytes

Here is the caller graph for this function:

bool Frame::ParseBytes ( const unsigned char *  a_ReadBuffer,
size_t &  a_ReadBufferOffset,
size_t &  a_BytesAvailable 
)
inline

Deliver a chunk of received bytes in the phase of deserialization.

This method is called by a FrameEndpoint entity in the phase of reception. Here, a chunk of data is copied to an internal buffer for later evaluation within the Deserialze() method. The Deserialize() method is called automatically if the required amount of bytes is available.

Parameters
a_ReadBufferthe incoming buffer of bytes containing the raw byte stream read from the TCP socket
a_ReadBufferOffsetthe read offset within the provided incoming byte buffer to start with
a_BytesAvailablethe remaining amount of bytes in the read buffer to evaluate
Return values
trueno error occured
falsea protocol violation was detected. The stream is invalid now and the TCP socket must be closed
Returns
Indicates success or failure of parsing the provided chunk of bytes

Definition at line 107 of file Frame.h.

Here is the call graph for this function:

virtual const std::vector<unsigned char> Frame::Serialize ( ) const
pure virtual

The purely virtual serializer method.

This purely virtual serializer method has to be implemented in the derived class. Here the user specifies the format of the frame's fields for frames that are transmitted. This method is solely called by an FrameEndpoint entity.

Returns
A buffer containing the serialized frame ready for transmission

Here is the caller graph for this function:

Member Data Documentation

std::vector<unsigned char> Frame::m_Buffer
protected

The buffer containing partly received frames or higher-layer payload.

Definition at line 154 of file Frame.h.

size_t Frame::m_BytesRemaining
protected

The amount of bytes required to finalize frame assembly during reception.

Definition at line 155 of file Frame.h.


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