senf::ConcretePacket< PacketType > Class Template Reference

Protocol specific packet handle. More...

#include <senf/Packets/Packet.hh>

Inheritance diagram for senf::ConcretePacket< PacketType >:

Classes

struct  ParserProxy
 

Public Types

typedef PacketType type
 
typedef PacketType::parser Parser
 
- Public Types inherited from senf::Packet
typedef void type
 Type of the packet. More...
 
typedef senf::detail::packet::byte byte
 
typedef senf::detail::packet::size_type size_type
 
typedef senf::detail::packet::difference_type difference_type
 Unsigned type to represent packet size. More...
 
typedef PacketInterpreterBase::factory_t factory_t
 Packet factory type (see below) More...
 

Public Member Functions

ParserProxy operator-> () const
 Access packet fields. More...
 
Parser parser () const
 Access packet field parser directly. More...
 
- Public Member Functions inherited from senf::Packet
 Packet ()
 Create uninitialized packet handle. More...
 
Packet clone () const
 Create copy packet. More...
 
template<class PacketType >
 Packet (ConcretePacket< PacketType > const &packet)
 Copy-construct Packet from ConcretePacket. More...
 
Packetoperator= (Packet const &)
 
 Packet (Packet const &other)
 
 Packet (Packet &&other) noexcept
 
 ~Packet ()
 
Packet next () const
 Get next packet in chain. More...
 
Packet next (NoThrow_t) const
 Get next packet in chain. More...
 
template<class OtherPacket >
OtherPacket next () const
 Get next packet in chain and cast to OtherPacket. More...
 
template<class OtherPacket >
OtherPacket next (NoThrow_t) const
 Get next packet in chain and cast to OtherPacket. More...
 
template<class OtherPacket >
OtherPacket find () const
 Search chain forward for packet of type OtherPacket. More...
 
template<class OtherPacket >
OtherPacket find (NoThrow_t) const
 Search chain forward for packet of type OtherPacket. More...
 
Packet prev () const
 Get previous packet in chain. More...
 
Packet prev (NoThrow_t) const
 Get previous packet in chain. More...
 
template<class OtherPacket >
OtherPacket prev () const
 Get previous packet in chain and cast to OtherPacket. More...
 
template<class OtherPacket >
OtherPacket prev (NoThrow_t) const
 Get previous packet in chain and cast to OtherPacket. More...
 
template<class OtherPacket >
OtherPacket rfind () const
 Search chain backwards for packet of type OtherPacket. More...
 
template<class OtherPacket >
OtherPacket rfind (NoThrow_t) const
 Search chain backwards for packet of type OtherPacket. More...
 
Packet first () const
 Return first packet in chain. More...
 
template<class OtherPacket >
OtherPacket first () const
 Return first packet in chain and cast. More...
 
Packet last () const
 Return last packet in chain. More...
 
template<class OtherPacket >
OtherPacket last () const
 Return last packet in chain and cast. More...
 
template<class OtherPacket >
OtherPacket parseNextAs () const
 Interpret payload of this as OtherPacket. More...
 
Packet parseNextAs (factory_t factory) const
 Interpret payload of this as factory type packet. More...
 
template<class OtherPacket >
bool is () const
 Check, whether this packet is of the given type. More...
 
template<class OtherPacket >
OtherPacket const & as () const
 Cast current packet to the given type. More...
 
template<class OtherPacket >
OtherPacket & as ()
 
template<class OtherPacket >
OtherPacket const & as (NoThrow_t) const
 Cast current packet to the given type. More...
 
template<class OtherPacket >
OtherPacket & as (NoThrow_t)
 
Packet append (Packet const &packet) const
 Append the given packet to this packet. More...
 
void reparse () const
 Reparse the payload the packet. More...
 
template<class OtherPacket >
OtherPacket replaceAs (difference_type offset=0, difference_type tailOffset=0)
 Replace the complete packet chain with a new chain. More...
 
PacketDatadata () const
 Access the packets raw data container. More...
 
size_type size () const
 Return size of packet in bytes. More...
 
template<class Annotation >
Annotation & annotation ()
 Get packet annotation. More...
 
template<class Annotation >
Annotation const & annotation () const
 Get packet annotation. More...
 
void clearAnnotations ()
 Clear all packet annotations. More...
 
bool operator== (Packet const &other) const
 Check for packet identity. More...
 
bool boolean_test () const
 Check, whether the packet is valid() (not null) More...
 
void finalizeThis ()
 Update calculated fields. More...
 
template<class Other >
void finalizeTo ()
 Update calculated fields. More...
 
void finalizeTo (Packet const &other)
 Update calculated fields. More...
 
void finalizeAll ()
 Update calculated fields. More...
 
void dump (std::ostream &os, DumpPacketAnnotations_t dumpAnnotationsSwitch=dumpAnnotations) const
 Write out a printable packet representation. More...
 
TypeIdValue typeId () const
 Get type of this packet. More...
 
factory_t factory () const
 Return factory instance of this packet. More...
 
unsigned long id () const
 Unique packet id. More...
 
bool is_shared () const
 check if this packet shares data with any another packet handle. More...
 
void memDebug (std::ostream &os) const
 
- Public Member Functions inherited from senf::comparable_safe_bool< class >
 operator bool_type () const
 
bool operator! () const
 

Structors and default members

 ConcretePacket ()
 Create uninitialized packet handle. More...
 
ConcretePacket clone () const
 
static factory_t factory ()
 Return factory for packets of specific type. More...
 
static ConcretePacket create ()
 Create default initialized packet. More...
 
static ConcretePacket create (senf::NoInit_t)
 Create uninitialized empty packet. More...
 
static ConcretePacket create (size_type size)
 Create default initialized packet. More...
 
static ConcretePacket create (size_type size, senf::NoInit_t)
 Create uninitialized packet. More...
 
template<class ForwardReadableRange >
static ConcretePacket create (ForwardReadableRange const &range)
 Create packet from given data. More...
 
static ConcretePacket create (byte *data, size_type size, size_type totalSize=0u, size_type offset=0u)
 Create packet utilizing external storage. More...
 
static ConcretePacket createAfter (Packet const &packet)
 Create default initialized packet after packet. More...
 
static ConcretePacket createAfter (Packet const &packet, senf::NoInit_t)
 Create uninitialized empty packet afterpacket. More...
 
static ConcretePacket createAfter (Packet const &packet, size_type size)
 Create default initialized packet after packet. More...
 
static ConcretePacket createAfter (Packet const &packet, size_type size, senf::NoInit_t)
 Create uninitialized packet after packet. More...
 
template<class ForwardReadableRange >
static ConcretePacket createAfter (Packet const &packet, ForwardReadableRange const &range)
 Create packet from given data after packet. More...
 
static ConcretePacket createBefore (Packet const &packet)
 Create default initialized packet before packet. More...
 
static ConcretePacket createBeforeNoZero (Packet const &packet)
 Create default initialized packet before packet. More...
 
static ConcretePacket createBefore (Packet const &packet, senf::NoInit_t, size_type space=0, size_type tailSpace=0)
 Create uninitialized empty packet before packet. More...
 
static ConcretePacket createInsertBefore (Packet const &packet)
 Insert default initialized packet before packet. More...
 
static ConcretePacket createInsertBefore (Packet const &packet, senf::NoInit_t)
 Insert uninitialized empty packet before packet. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from senf::Packet
static std::int32_t const & pktCount ()
 
- Protected Types inherited from senf::safe_bool_base
typedef void(safe_bool_base::* bool_type) () const
 
- Protected Member Functions inherited from senf::Packet
 Packet (PacketInterpreterBase::ptr const &packet)
 
PacketInterpreterBase::ptr const & ptr () const
 
PacketInterpreterBase::ptr parseNextAs (factory_t factory, PacketInterpreterBase::optional_range const &range) const
 
PacketInterpreterBase::ptr getNext (PacketInterpreterBase::optional_range const &range) const
 
Packet getLast () const
 
- Protected Member Functions inherited from senf::comparable_safe_bool< class >
 ~comparable_safe_bool ()
 
- Protected Member Functions inherited from senf::safe_bool_base
void this_type_does_not_support_comparisons () const
 
 safe_bool_base ()
 
 safe_bool_base (const safe_bool_base &)
 
safe_bool_baseoperator= (const safe_bool_base &)
 
 ~safe_bool_base ()
 

Detailed Description

template<class PacketType>
class senf::ConcretePacket< PacketType >

Protocol specific packet handle.

The ConcretePacket template class extends Packet to provide protocol/packet type specific aspects. These are packet constructors and access to the parsed packet fields.

The PacketType template argument to ConcretePacket is a protocol specific and internal policy class which defines the protocol specific behavior. To access a specific type of packet, the library provides corresponding typedefs of ConcretePacket < SomePacketType > (e.g. EthernetPacket as typedef for ConcretePacket < EthernetPacketType >).

The new members provided by ConcretePacket over packet are mostly comprised of the packet constructors. These come in three major flavors:

  • The create() family of constructors will create completely new packets.
  • The createAfter() family of constructors will create new packets (with new data for the packet) after a given existing packet thereby destroying and overwriting any possibly existing packets and data after the given packet.
  • The createBefore() family of constructors will create new packets (again with new data) before a given existing packet thereby destroying and overwriting any possibly existing packets and data before the given packet.
  • The createInsertBefore() family of constructors will create new packets before a given packet inserting them into the packet chain after any existing packets before the given packet.

Whereas create() will create a completely new packet with it's own chain and data storage, createAfter(), createBefore() and createInsertBefore() extend a packet with additional headers/interpreters. createAfter() will set the payload of the given packet to the new packet whereas createBefore() and createInsertBefore() will create a new packet with the existing packet as it's payload.

createAfter() differs from Packet::parseNextAs() in that the former creates a new packet replacing any possibly existing data whereas the latter will interpret the already existing data as given by the type argument.

See also
PacketTypeBase for a specification of the interface to be provided by the PacketType policy class.

Definition at line 87 of file Packet.hh.

Member Typedef Documentation

◆ Parser

template<class PacketType>
typedef PacketType::parser senf::ConcretePacket< PacketType >::Parser

Definition at line 590 of file Packet.hh.

◆ type

template<class PacketType>
typedef PacketType senf::ConcretePacket< PacketType >::type

Definition at line 589 of file Packet.hh.

Constructor & Destructor Documentation

◆ ConcretePacket()

template<class PacketType>
senf::ConcretePacket< PacketType >::ConcretePacket ( )

Create uninitialized packet handle.

An uninitialized handle is not valid(). It does not allow any operation except assignment and checking for validity.

Member Function Documentation

◆ clone()

template<class PacketType>
ConcretePacket senf::ConcretePacket< PacketType >::clone ( ) const

◆ create() [1/6]

template<class PacketType>
static ConcretePacket senf::ConcretePacket< PacketType >::create ( )
static

Create default initialized packet.

The packet will be initialized to it's default empty state.

◆ create() [2/6]

template<class PacketType>
static ConcretePacket senf::ConcretePacket< PacketType >::create ( senf::NoInit_t  )
static

Create uninitialized empty packet.

This will create a completely empty and uninitialized packet with size() == 0.

Parameters
[in]senf::noinitThis parameter must always have the value senf::noinit.

◆ create() [3/6]

template<class PacketType>
static ConcretePacket senf::ConcretePacket< PacketType >::create ( size_type  size)
static

Create default initialized packet.

This member will create a default initialized packet with the given size. If the size parameter is smaller than the minimum allowed packet size an exception will be thrown.

Parameters
[in]sizeSize of the packet to create in bytes.
Exceptions
TruncatedPacketExceptionif size is smaller than the smallest permissible size for this type of packet.

◆ create() [4/6]

template<class PacketType>
static ConcretePacket senf::ConcretePacket< PacketType >::create ( size_type  size,
senf::NoInit_t   
)
static

Create uninitialized packet.

Creates an uninitialized (all-zero) packet of the exact given size.

Parameters
[in]sizeSize of the packet to create in bytes
[in]senf::noinitThis parameter must always have the value senf::noinit.

◆ create() [5/6]

template<class PacketType>
template<class ForwardReadableRange >
static ConcretePacket senf::ConcretePacket< PacketType >::create ( ForwardReadableRange const &  range)
static

Create packet from given data.

The packet will be created from a copy of the given data. The data from the range will be copied directly into the packet representation. The data will not be validated in any way.

Parameters
[in]rangeBoost.Range of data to construct packet from.

◆ create() [6/6]

template<class PacketType>
static ConcretePacket senf::ConcretePacket< PacketType >::create ( byte data,
size_type  size,
size_type  totalSize = 0u,
size_type  offset = 0u 
)
static

Create packet utilizing external storage.

The packet will be created using size bytes at data. The data will not be copied, instead the packet will reference the memory at data. Changing the packet possibly changes data.

By specifying chunkSize and / or offset, you may inform the packet library of additional available space: chunkSize gives the complete size of the memory area at data. The packet library will make use of this space when resizing the packet as long as the data does fit into the available space. offset instructs the packet library to skip that amount of bytes at the beginning of data.

Parameters
[in]datapointer to data area
[in]sizeinitial size of packet data
[in]totalSizesize of the memory area at data, defaults to size + offset
[in]offsetbytes to skip a the beginning of data

◆ createAfter() [1/5]

template<class PacketType>
static ConcretePacket senf::ConcretePacket< PacketType >::createAfter ( Packet const &  packet)
static

Create default initialized packet after packet.

The packet will be initialized to it's default empty state. It will be appended as next header/interpreter after packet in that packets interpreter chain.

Parameters
[in]packetPacket to append new packet to.

◆ createAfter() [2/5]

template<class PacketType>
static ConcretePacket senf::ConcretePacket< PacketType >::createAfter ( Packet const &  packet,
senf::NoInit_t   
)
static

Create uninitialized empty packet afterpacket.

This will create a completely empty and uninitialized packet with size() == 0. It will be appended as next header/interpreter after packet in that packets interpreter chain.

Parameters
[in]packetPacket to append new packet to.
[in]senf::noinitThis parameter must always have the value senf::noinit.

◆ createAfter() [3/5]

template<class PacketType>
static ConcretePacket senf::ConcretePacket< PacketType >::createAfter ( Packet const &  packet,
size_type  size 
)
static

Create default initialized packet after packet.

This member will create a default initialized packet with the given size. If the size parameter is smaller than the minimum allowed packet size an exception will be thrown. It will be appended as next header/interpreter after packet in that packets interpreter chain.

Parameters
[in]packetPacket to append new packet to.
[in]sizeSize of the packet to create in bytes.
Exceptions
TruncatedPacketExceptionif size is smaller than the smallest permissible size for this type of packet.

◆ createAfter() [4/5]

template<class PacketType>
static ConcretePacket senf::ConcretePacket< PacketType >::createAfter ( Packet const &  packet,
size_type  size,
senf::NoInit_t   
)
static

Create uninitialized packet after packet.

Creates an uninitialized (all-zero) packet of the exact given size. It will be appended as next header/interpreter after packet in that packets interpreter chain.

Parameters
[in]packetPacket to append new packet to.
[in]sizeSize of the packet to create in bytes
[in]senf::noinitThis parameter must always have the value senf::noinit.

◆ createAfter() [5/5]

template<class PacketType>
template<class ForwardReadableRange >
static ConcretePacket senf::ConcretePacket< PacketType >::createAfter ( Packet const &  packet,
ForwardReadableRange const &  range 
)
static

Create packet from given data after packet.

The packet will be created from a copy of the given data. The data from the range will be copied directly into the packet representation. The data will not be validated in any way. It will be appended as next header/interpreter after packet in that packets interpreter chain.

Parameters
[in]packetPacket to append new packet to.
[in]rangeBoost.Range of data to construct packet from.

◆ createBefore() [1/2]

template<class PacketType>
static ConcretePacket senf::ConcretePacket< PacketType >::createBefore ( Packet const &  packet)
static

Create default initialized packet before packet.

The packet will be initialized to it's default empty state. It will be prepended as previous header/interpreter before packet in that packets interpreter chain.

Warning
This constructor will destroy any existing headers before packet and replace them with the new header.
Parameters
[in]packetPacket to prepend new packet to.

◆ createBefore() [2/2]

template<class PacketType>
static ConcretePacket senf::ConcretePacket< PacketType >::createBefore ( Packet const &  packet,
senf::NoInit_t  ,
size_type  space = 0,
size_type  tailSpace = 0 
)
static

Create uninitialized empty packet before packet.

Creates a completely empty and uninitialized packet. It will be prepended as previous header/interpreter before packet in that packets interpreter chain.

Warning
This constructor will destroy any existing headers before packet and replace them with the new header.
Parameters
[in]packetPacket to prepend new packet to.

◆ createBeforeNoZero()

template<class PacketType>
static ConcretePacket senf::ConcretePacket< PacketType >::createBeforeNoZero ( Packet const &  packet)
static

Create default initialized packet before packet.

The packet will not be initialized .It will be prepended as previous header/interpreter before packet in that packets interpreter chain.

Warning
This constructor will destroy any existing headers before packet and replace them with the new header.
Parameters
[in]packetPacket to prepend new packet to.

◆ createInsertBefore() [1/2]

template<class PacketType>
static ConcretePacket senf::ConcretePacket< PacketType >::createInsertBefore ( Packet const &  packet)
static

Insert default initialized packet before packet.

The new packet header will be initialized to it' s default empty state. It will be inserted into the packet chain before packet.

Parameters
[in]packetPacket before which to insert the new packet

◆ createInsertBefore() [2/2]

template<class PacketType>
static ConcretePacket senf::ConcretePacket< PacketType >::createInsertBefore ( Packet const &  packet,
senf::NoInit_t   
)
static

Insert uninitialized empty packet before packet.

Inserts a completely empty and uninitialized packet before packet into the header/interpreter chain.

Parameters
[in]packetPacket before which to insert the new packet

◆ factory()

template<class PacketType>
static factory_t senf::ConcretePacket< PacketType >::factory ( )
static

Return factory for packets of specific type.

This static member is like Packet::factory() for a specific packet of type PacketType

◆ operator->()

template<class PacketType>
ParserProxy senf::ConcretePacket< PacketType >::operator-> ( ) const

Access packet fields.

This operator allows to access the parsed fields of the packet using the notation packet->field(). The fields of the packet are specified by the PacketType's parser member.

The members are not strictly restricted to simple field access. The parser class may have any member which is needed for full packet access (e.g. checksum validation / recreation ...)

See also
The PacketParser facility for the parser interface.

◆ parser()

template<class PacketType>
Parser senf::ConcretePacket< PacketType >::parser ( ) const

Access packet field parser directly.

Access the parser of the packet. This is the same object returned by the operator->() operator. The operator however does not allow to access this object itself, only it's members.

See also
The PacketParser facility for the parser interface

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