22 template <
typename TRecType,
typename TRecLen>
class TLVRecord
57 m_Data = other.m_Data;
71 m_Data =
reinterpret_cast<TLVRawData*
>(recordRawData);
80 static bool canAssign(
const uint8_t* recordRawData,
size_t tlvDataLen)
82 return recordRawData !=
nullptr &&
94 m_Data = other.m_Data;
106 if (m_Data == rhs.m_Data)
115 return (memcmp(m_Data, rhs.m_Data,
getTotalSize()) == 0);
133 if (m_Data ==
nullptr)
144 if (m_Data ==
nullptr)
155 return (m_Data ==
nullptr);
163 return (m_Data !=
nullptr);
171 return reinterpret_cast<uint8_t*
>(m_Data);
201 memcpy(&result, m_Data->
recordValue + getValueOffset() + offset,
sizeof(T));
214 template <
typename T>
bool setValue(T newValue,
int valueOffset = 0)
219 memcpy(m_Data->
recordValue + getValueOffset() + valueOffset, &newValue,
sizeof(T));
234 virtual size_t getValueOffset()
const
248 mutable size_t m_RecordCount;
256 m_RecordCount =
static_cast<size_t>(-1);
264 m_RecordCount = other.m_RecordCount;
278 m_RecordCount = other.m_RecordCount;
292 TLVRecordType resRec(
nullptr);
293 if (!TLVRecordType::canAssign(tlvDataBasePtr, tlvDataLen))
296 resRec.assign(tlvDataBasePtr);
298 if (resRec.getRecordBasePtr() + resRec.getTotalSize() > tlvDataBasePtr + tlvDataLen)
299 resRec.assign(
nullptr);
302 if (!resRec.isNull() && (tlvDataLen == 0 || resRec.getTotalSize() == 0))
303 resRec.assign(
nullptr);
317 TLVRecordType
getNextTLVRecord(TLVRecordType& record,
const uint8_t* tlvDataBasePtr,
size_t tlvDataLen)
const
319 TLVRecordType resRec(
nullptr);
324 if (!TLVRecordType::canAssign(record.getRecordBasePtr() + record.getTotalSize(),
325 tlvDataBasePtr - record.getRecordBasePtr() + tlvDataLen -
326 record.getTotalSize()))
329 resRec.assign(record.getRecordBasePtr() + record.getTotalSize());
331 if (resRec.getTotalSize() == 0)
332 resRec.assign(
nullptr);
335 if ((resRec.getRecordBasePtr() - tlvDataBasePtr) < 0)
336 resRec.assign(
nullptr);
339 if (!resRec.isNull() && resRec.getRecordBasePtr() + resRec.getTotalSize() > tlvDataBasePtr + tlvDataLen)
340 resRec.assign(
nullptr);
353 TLVRecordType
getTLVRecord(uint32_t recordType, uint8_t* tlvDataBasePtr,
size_t tlvDataLen)
const
356 while (!curRec.isNull())
358 if (curRec.getType() == recordType)
366 curRec.assign(
nullptr);
381 if (m_RecordCount !=
static_cast<size_t>(-1))
382 return m_RecordCount;
386 while (!curRec.isNull())
392 return m_RecordCount;
404 if (m_RecordCount !=
static_cast<size_t>(-1))
405 m_RecordCount += changedBy;
423 TLVRecordBuilder(uint32_t recType,
const uint8_t* recValue, uint8_t recValueLen);
433 TLVRecordBuilder(uint32_t recType,
const std::string& recValue,
bool valueIsHexString =
false);
441 void init(uint32_t recType,
const uint8_t* recValue,
size_t recValueLen);
444 size_t m_RecValueLen;
Definition: IpAddress.h:32
Definition: TLVData.h:419
TLVRecord(uint8_t *recordRawData)
Definition: TLVData.h:45
TLVRecord(const TLVRecord &other)
Definition: TLVData.h:55
virtual size_t getTotalSize() const =0
virtual ~TLVRecord()=default
TRecType getType() const
Definition: TLVData.h:131
bool setValue(T newValue, int valueOffset=0)
Definition: TLVData.h:214
bool operator!=(const TLVRecord &rhs) const
Definition: TLVData.h:123
uint8_t * getRecordBasePtr() const
Definition: TLVData.h:169
uint8_t * getValue() const
Definition: TLVData.h:142
bool operator==(const TLVRecord &rhs) const
Definition: TLVData.h:104
static bool canAssign(const uint8_t *recordRawData, size_t tlvDataLen)
Definition: TLVData.h:80
virtual size_t getDataSize() const =0
bool isNotNull() const
Definition: TLVData.h:161
bool isNull() const
Definition: TLVData.h:153
T getValueAs(size_t offset=0) const
Definition: TLVData.h:195
TLVRecord & operator=(const TLVRecord &other)
Definition: TLVData.h:92
void purgeRecordData()
Definition: TLVData.h:177
void assign(uint8_t *recordRawData)
Definition: TLVData.h:69
Definition: TLVData.h:246
void changeTLVRecordCount(int changedBy)
Definition: TLVData.h:402
TLVRecordReader & operator=(const TLVRecordReader &other)
Definition: TLVData.h:276
virtual ~TLVRecordReader()=default
TLVRecordType getTLVRecord(uint32_t recordType, uint8_t *tlvDataBasePtr, size_t tlvDataLen) const
Definition: TLVData.h:353
TLVRecordReader(const TLVRecordReader &other)
Definition: TLVData.h:262
TLVRecordType getNextTLVRecord(TLVRecordType &record, const uint8_t *tlvDataBasePtr, size_t tlvDataLen) const
Definition: TLVData.h:317
TLVRecordReader()
Definition: TLVData.h:254
TLVRecordType getFirstTLVRecord(uint8_t *tlvDataBasePtr, size_t tlvDataLen) const
Definition: TLVData.h:290
size_t getTLVRecordCount(uint8_t *tlvDataBasePtr, size_t tlvDataLen) const
Definition: TLVData.h:379
The main namespace for the PcapPlusPlus lib.
uint8_t recordValue[]
Definition: TLVData.h:34
TRecType recordType
Definition: TLVData.h:30
TRecLen recordLen
Definition: TLVData.h:32