3es  0.7
tes::PacketStream< HEADER > Class Template Reference

A utility class used for managing read/write operations to a PacketHeader payload. More...

#include <3espacketstream.h>

Classes

struct  IsConst
 Type traits: is T const? More...
 
struct  IsConst< const T >
 Type traits: is T const? More...
 

Public Types

enum  SeekPos { Begin, Current, End }
 Control values for seeking. More...
 
enum  Status {
  Ok = 0, EOP = (1 << 0), Fail = (1 << 1), ReadOnly = (1 << 2),
  CrcValid = (1 << 3)
}
 Status bits. More...
 
typedef uint16_t CrcType
 Defies the packet CRC type.
 

Public Member Functions

 PacketStream (HEADER &packet)
 Create a stream to read from beginning at packet. More...
 
uint32_t marker () const
 Fetch the marker bytes in local endian. More...
 
uint16_t versionMajor () const
 Fetch the major version bytes in local endian. More...
 
uint16_t versionMinor () const
 Fetch the minor version bytes in local endian. More...
 
uint16_t payloadSize () const
 Fetch the payload size bytes in local endian. More...
 
uint16_t packetSize () const
 Returns the size of the packet plus payload, giving the full data packet size including the CRC. More...
 
uint16_t routingId () const
 Fetch the routing ID bytes in local endian. More...
 
uint16_t messageId () const
 Fetch the message ID bytes in local endian. More...
 
CrcType crc () const
 Fetch the CRC bytes in local endian. More...
 
CrcTypecrcPtr ()
 Fetch a pointer to the CRC bytes. More...
 
const CrcTypecrcPtr () const
 
uint16_t status () const
 Report the Status bits. More...
 
bool isEop () const
 At end of packet/stream? More...
 
bool isOk () const
 Status OK? More...
 
bool isFail () const
 Fail bit set? More...
 
bool isReadOnly () const
 Read only stream? More...
 
bool isCrcValid () const
 CRC validated? More...
 
HEADER & packet () const
 Access the head of the packet buffer, for direct PacketHeader access. More...
 
uint16_t tell () const
 Tell the current stream position. More...
 
bool seek (int offset, SeekPos pos=Begin)
 Seek to the indicated position. More...
 
const uint8_t * payload () const
 Direct payload pointer access. More...
 

Protected Attributes

HEADER & _packet
 Packet header and buffer start address.
 
uint16_t _status
 Status bits.
 
uint16_t _payloadPosition
 Payload cursor.
 

Detailed Description

template<class HEADER>
class tes::PacketStream< HEADER >

A utility class used for managing read/write operations to a PacketHeader payload.

The template type is intended to be either a PacketReader or a const PacketHeader for use with PacketWriter and PacketReader respectively.

Member Enumeration Documentation

◆ SeekPos

template<class HEADER>
enum tes::PacketStream::SeekPos

Control values for seeking.

Enumerator
Begin 

Seek from the beginning of the stream.

Current 

Seek from the current position.

End 

Seek from the end of the stream.

◆ Status

template<class HEADER>
enum tes::PacketStream::Status

Status bits.

Enumerator
Ok 

No issues.

EOP 

End at of packet/stream.

Fail 

Set after an operation fails.

ReadOnly 

Read only stream?

CrcValid 

Is the CRC valid?

Constructor & Destructor Documentation

◆ PacketStream()

template<class HEADER>
tes::PacketStream< HEADER >::PacketStream ( HEADER &  packet)

Create a stream to read from beginning at packet.

Parameters
packetThe beginning of the data packet.

Member Function Documentation

◆ crc()

template<class HEADER>
CrcType tes::PacketStream< HEADER >::crc ( ) const
inline

Fetch the CRC bytes in local endian.

Invalid for packets with the PF_NoCrc flag set.

Returns
The packet's CRC value.

◆ crcPtr() [1/2]

template<class HEADER >
PacketStream< HEADER >::CrcType * tes::PacketStream< HEADER >::crcPtr ( )

Fetch a pointer to the CRC bytes.

Invalid for packets with the PF_NoCrc flag set.

Returns
A pointer to the CRC location.

Referenced by tes::PacketStream< PacketHeader >::crc().

◆ crcPtr() [2/2]

template<class HEADER >
const PacketStream< HEADER >::CrcType * tes::PacketStream< HEADER >::crcPtr ( ) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ isCrcValid()

template<class HEADER>
bool tes::PacketStream< HEADER >::isCrcValid ( ) const
inline

CRC validated?

Returns
True if CRC has been validated.

◆ isEop()

template<class HEADER>
bool tes::PacketStream< HEADER >::isEop ( ) const
inline

At end of packet/stream?

Returns
True if at end of packet.

◆ isFail()

template<class HEADER>
bool tes::PacketStream< HEADER >::isFail ( ) const
inline

Fail bit set?

Returns
True if fail bit is set.

Referenced by tes::PacketStream< PacketHeader >::isOk().

◆ isOk()

template<class HEADER>
bool tes::PacketStream< HEADER >::isOk ( ) const
inline

Status OK?

Returns
True if OK

◆ isReadOnly()

template<class HEADER>
bool tes::PacketStream< HEADER >::isReadOnly ( ) const
inline

Read only stream?

Returns
True if read only.

◆ marker()

template<class HEADER>
uint32_t tes::PacketStream< HEADER >::marker ( ) const
inline

Fetch the marker bytes in local endian.

Returns
The PacketHeader::marker bytes.

◆ messageId()

template<class HEADER>
uint16_t tes::PacketStream< HEADER >::messageId ( ) const
inline

Fetch the message ID bytes in local endian.

Returns
The PacketHeader::messageId bytes.

◆ packet()

template<class HEADER >
HEADER & tes::PacketStream< HEADER >::packet ( ) const
inline

Access the head of the packet buffer, for direct PacketHeader access.

Note: values are in network Endian.

Returns
A reference to the PacketHeader.

Referenced by tes::PacketStream< PacketHeader >::isCrcValid(), and tes::PacketStream< PacketHeader >::packetSize().

◆ packetSize()

template<class HEADER>
uint16_t tes::PacketStream< HEADER >::packetSize ( ) const
inline

Returns the size of the packet plus payload, giving the full data packet size including the CRC.

Returns
PacketHeader data size (bytes).

Referenced by tes::sendMessage().

◆ payload()

template<class HEADER >
const uint8_t * tes::PacketStream< HEADER >::payload ( ) const
inline

Direct payload pointer access.

Returns
The start of the payload bytes.

Referenced by tes::PacketStream< PacketHeader >::isCrcValid().

◆ payloadSize()

template<class HEADER>
uint16_t tes::PacketStream< HEADER >::payloadSize ( ) const
inline

Fetch the payload size bytes in local endian.

Returns
The PacketHeader::payloadSize bytes.

Referenced by tes::PacketStream< PacketHeader >::packetSize(), and tes::PacketStream< PacketHeader >::seek().

◆ routingId()

template<class HEADER>
uint16_t tes::PacketStream< HEADER >::routingId ( ) const
inline

Fetch the routing ID bytes in local endian.

Returns
The PacketHeader::routingId bytes.

◆ seek()

template<class HEADER >
bool tes::PacketStream< HEADER >::seek ( int  offset,
SeekPos  pos = Begin 
)

Seek to the indicated position.

Parameters
offsetSeek offset from pos.
posThe seek reference position.

Referenced by tes::PacketStream< PacketHeader >::isCrcValid().

◆ status()

template<class HEADER >
uint16_t tes::PacketStream< HEADER >::status ( ) const
inline

Report the Status bits.

Returns
The Status flags.

Referenced by tes::PacketStream< PacketHeader >::crc().

◆ tell()

template<class HEADER >
uint16_t tes::PacketStream< HEADER >::tell ( ) const
inline

Tell the current stream position.

Returns
The current position.

Referenced by tes::PacketStream< PacketHeader >::isCrcValid().

◆ versionMajor()

template<class HEADER>
uint16_t tes::PacketStream< HEADER >::versionMajor ( ) const
inline

Fetch the major version bytes in local endian.

Returns
The PacketHeader::versionMajor bytes.

◆ versionMinor()

template<class HEADER>
uint16_t tes::PacketStream< HEADER >::versionMinor ( ) const
inline

Fetch the minor version bytes in local endian.

Returns
The PacketHeader::versionMinor bytes.

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