Protocol specific packet handle. More...
#include <senf/Packets/Packet.hh>
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... | |
Packet & | operator= (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... | |
PacketData & | data () 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_base & | operator= (const safe_bool_base &) |
~safe_bool_base () | |
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:
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.
typedef PacketType::parser senf::ConcretePacket< PacketType >::Parser |
typedef PacketType senf::ConcretePacket< PacketType >::type |
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.
ConcretePacket senf::ConcretePacket< PacketType >::clone | ( | ) | const |
|
static |
Create default initialized packet.
The packet will be initialized to it's default empty state.
|
static |
Create uninitialized empty packet.
This will create a completely empty and uninitialized packet with size() == 0
.
[in] | senf::noinit | This parameter must always have the value senf::noinit . |
|
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.
[in] | size | Size of the packet to create in bytes. |
TruncatedPacketException | if size is smaller than the smallest permissible size for this type of packet. |
|
static |
Create uninitialized packet.
Creates an uninitialized (all-zero) packet of the exact given size.
[in] | size | Size of the packet to create in bytes |
[in] | senf::noinit | This parameter must always have the value senf::noinit . |
|
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.
[in] | range | Boost.Range of data to construct packet from. |
|
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.
[in] | data | pointer to data area |
[in] | size | initial size of packet data |
[in] | totalSize | size of the memory area at data, defaults to size + offset |
[in] | offset | bytes to skip a the beginning of data |
|
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.
[in] | packet | Packet to append new packet to. |
|
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.
[in] | packet | Packet to append new packet to. |
[in] | senf::noinit | This parameter must always have the value senf::noinit . |
|
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.
[in] | packet | Packet to append new packet to. |
[in] | size | Size of the packet to create in bytes. |
TruncatedPacketException | if size is smaller than the smallest permissible size for this type of packet. |
|
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.
[in] | packet | Packet to append new packet to. |
[in] | size | Size of the packet to create in bytes |
[in] | senf::noinit | This parameter must always have the value senf::noinit . |
|
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.
[in] | packet | Packet to append new packet to. |
[in] | range | Boost.Range of data to construct packet from. |
|
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.
[in] | packet | Packet to prepend new packet to. |
|
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.
[in] | packet | Packet to prepend new packet to. |
|
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.
[in] | packet | Packet to prepend new packet to. |
|
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.
[in] | packet | Packet before which to insert the new packet |
|
static |
Insert uninitialized empty packet before packet.
Inserts a completely empty and uninitialized packet before packet into the header/interpreter chain.
[in] | packet | Packet before which to insert the new packet |
|
static |
Return factory for packets of specific type.
This static member is like Packet::factory() for a specific packet of type 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 ...)
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.