PcapPlusPlus  22.11
pcpp::TLVRecord< TRecType, TRecLen > Class Template Referenceabstract

#include <TLVData.h>

Classes

struct  TLVRawData
 

Public Member Functions

 TLVRecord (uint8_t *recordRawData)
 
 TLVRecord (const TLVRecord &other)
 
virtual ~TLVRecord ()
 
void assign (uint8_t *recordRawData)
 
TLVRecordoperator= (const TLVRecord &other)
 
bool operator== (const TLVRecord &rhs) const
 
bool operator!= (const TLVRecord &rhs) const
 
TRecType getType () const
 
uint8_t * getValue () const
 
bool isNull () const
 
bool isNotNull () const
 
uint8_t * getRecordBasePtr () const
 
void purgeRecordData ()
 
template<typename T >
getValueAs (size_t offset=0) const
 
template<typename T >
bool setValue (T newValue, int valueOffset=0)
 
virtual size_t getTotalSize () const =0
 
virtual size_t getDataSize () const =0
 

Detailed Description

template<typename TRecType, typename TRecLen>
class pcpp::TLVRecord< TRecType, TRecLen >

A wrapper class for a Type-Length-Value (TLV) record. This class does not create or modify TLV records, but rather serves as a wrapper and provides useful methods for retrieving data from them. This class has several abstract methods that should be implemented in derived classes. These methods are for record length value calculation (the 'L' in TLV) which is implemented differently in different protocols

Constructor & Destructor Documentation

◆ TLVRecord() [1/2]

template<typename TRecType, typename TRecLen>
pcpp::TLVRecord< TRecType, TRecLen >::TLVRecord ( uint8_t *  recordRawData)
inline

A c'tor for this class that gets a pointer to the TLV record raw data (byte array)

Parameters
[in]recordRawDataA pointer to the TLV record raw data

◆ TLVRecord() [2/2]

template<typename TRecType, typename TRecLen>
pcpp::TLVRecord< TRecType, TRecLen >::TLVRecord ( const TLVRecord< TRecType, TRecLen > &  other)
inline

A copy c'tor for this class. This copy c'tor doesn't copy the TLV data, but only the pointer to it, which means that after calling it both the old and the new instance will point to the same TLV raw data

Parameters
[in]otherThe TLVRecord instance to copy from

◆ ~TLVRecord()

template<typename TRecType, typename TRecLen>
virtual pcpp::TLVRecord< TRecType, TRecLen >::~TLVRecord ( )
inlinevirtual

A d'tor for this class, currently does nothing

Member Function Documentation

◆ assign()

template<typename TRecType, typename TRecLen>
void pcpp::TLVRecord< TRecType, TRecLen >::assign ( uint8_t *  recordRawData)
inline

Assign a pointer to the TLV record raw data (byte array)

Parameters
[in]recordRawDataA pointer to the TLV record raw data

◆ getDataSize()

template<typename TRecType, typename TRecLen>
virtual size_t pcpp::TLVRecord< TRecType, TRecLen >::getDataSize ( ) const
pure virtual

◆ getRecordBasePtr()

template<typename TRecType, typename TRecLen>
uint8_t* pcpp::TLVRecord< TRecType, TRecLen >::getRecordBasePtr ( ) const
inline
Returns
A pointer to the TLV record raw data byte stream

◆ getTotalSize()

template<typename TRecType, typename TRecLen>
virtual size_t pcpp::TLVRecord< TRecType, TRecLen >::getTotalSize ( ) const
pure virtual

◆ getType()

template<typename TRecType, typename TRecLen>
TRecType pcpp::TLVRecord< TRecType, TRecLen >::getType ( ) const
inline
Returns
The type field of the record (the 'T' in Type-Length-Value)

◆ getValue()

template<typename TRecType, typename TRecLen>
uint8_t* pcpp::TLVRecord< TRecType, TRecLen >::getValue ( ) const
inline
Returns
A pointer to the value of the record as byte array (the 'V' in Type-Length- Value)

◆ getValueAs()

template<typename TRecType, typename TRecLen>
template<typename T >
T pcpp::TLVRecord< TRecType, TRecLen >::getValueAs ( size_t  offset = 0) const
inline

A templated method to retrieve the record data as a certain type T. For example, if record data is 4B long (integer) then this method should be used as getValueAs<int>() and it will return the record data as an integer.
Notice this return value is a copy of the data, not a pointer to the actual data

Parameters
[in]offsetThe offset in the record data to start reading the value from. Useful for cases when you want to read some of the data that doesn't start at offset 0. This is an optional parameter and the default value is 0, meaning start reading the value at the beginning of the record data
Returns
The record data as type T

◆ isNotNull()

template<typename TRecType, typename TRecLen>
bool pcpp::TLVRecord< TRecType, TRecLen >::isNotNull ( ) const
inline
Returns
True if the TLV record raw data is not NULL, false otherwise

◆ isNull()

template<typename TRecType, typename TRecLen>
bool pcpp::TLVRecord< TRecType, TRecLen >::isNull ( ) const
inline
Returns
True if the TLV record raw data is NULL, false otherwise

◆ operator!=()

template<typename TRecType, typename TRecLen>
bool pcpp::TLVRecord< TRecType, TRecLen >::operator!= ( const TLVRecord< TRecType, TRecLen > &  rhs) const
inline

Overload of the not equal operator.

Parameters
[in]rhsThe object to compare to
Returns
True if objects are not equal, false otherwise

◆ operator=()

template<typename TRecType, typename TRecLen>
TLVRecord& pcpp::TLVRecord< TRecType, TRecLen >::operator= ( const TLVRecord< TRecType, TRecLen > &  other)
inline

Overload of the assignment operator. This operator doesn't copy the TLV data, but rather copies the pointer to it, which means that after calling it both the old and the new instance will point to the same TLV raw data

Parameters
[in]otherThe TLVRecord instance to assign

◆ operator==()

template<typename TRecType, typename TRecLen>
bool pcpp::TLVRecord< TRecType, TRecLen >::operator== ( const TLVRecord< TRecType, TRecLen > &  rhs) const
inline

Overload of the equality operator. Two record are equal if both of them point to the same data, or if they point to different data but their total size is equal and the raw data they both contain is similar.

Parameters
[in]rhsThe object to compare to
Returns
True if both objects are equal, false otherwise

◆ purgeRecordData()

template<typename TRecType, typename TRecLen>
void pcpp::TLVRecord< TRecType, TRecLen >::purgeRecordData ( )
inline

Free the memory of the TLV record raw data

◆ setValue()

template<typename TRecType, typename TRecLen>
template<typename T >
bool pcpp::TLVRecord< TRecType, TRecLen >::setValue ( newValue,
int  valueOffset = 0 
)
inline

A templated method to copy data of type T into the TLV record data. For example: if record data is 4[Bytes] long use this method with <int> to set an integer value into the record data: setValue<int>(num)

Parameters
[in]newValueThe value of type T to copy to the record data
[in]valueOffsetAn optional parameter that specifies where to start setting the record data (default set to 0). For example: if record data is 20 bytes long and you only need to set the 4 last bytes as integer then use this method like this: setValue<int>(num, 16)
Returns
True if value was set successfully or false if the size of T is larger than the record data size