Coverage Report

Created: 2025-12-14 07:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/PcapPlusPlus/Packet++/src/TLVData.cpp
Line
Count
Source
1
#include "TLVData.h"
2
#include "GeneralUtils.h"
3
#include "EndianPortable.h"
4
5
namespace pcpp
6
{
7
8
  TLVRecordBuilder::TLVRecordBuilder()
9
83.3k
  {
10
83.3k
    m_RecType = 0;
11
83.3k
    m_RecValueLen = 0;
12
83.3k
    m_RecValue = nullptr;
13
83.3k
  }
14
15
  TLVRecordBuilder::TLVRecordBuilder(uint32_t recType, const uint8_t* recValue, uint8_t recValueLen)
16
0
  {
17
0
    init(recType, recValue, recValueLen);
18
0
  }
19
20
  TLVRecordBuilder::TLVRecordBuilder(uint32_t recType, uint8_t recValue)
21
0
  {
22
0
    init(recType, &recValue, sizeof(uint8_t));
23
0
  }
24
25
  TLVRecordBuilder::TLVRecordBuilder(uint32_t recType, uint16_t recValue)
26
0
  {
27
0
    recValue = htobe16(recValue);
28
0
    init(recType, reinterpret_cast<uint8_t*>(&recValue), sizeof(uint16_t));
29
0
  }
30
31
  TLVRecordBuilder::TLVRecordBuilder(uint32_t recType, uint32_t recValue)
32
0
  {
33
0
    recValue = htobe32(recValue);
34
0
    init(recType, reinterpret_cast<uint8_t*>(&recValue), sizeof(uint32_t));
35
0
  }
36
37
  TLVRecordBuilder::TLVRecordBuilder(uint32_t recType, const IPv4Address& recValue)
38
0
  {
39
0
    uint32_t recIntValue = recValue.toInt();
40
0
    init(recType, reinterpret_cast<uint8_t*>(&recIntValue), sizeof(uint32_t));
41
0
  }
42
43
  TLVRecordBuilder::TLVRecordBuilder(uint32_t recType, const std::string& recValue, bool valueIsHexString)
44
0
  {
45
0
    m_RecType = 0;
46
0
    m_RecValueLen = 0;
47
0
    m_RecValue = nullptr;
48
49
0
    if (valueIsHexString)
50
0
    {
51
0
      uint8_t recValueByteArr[512];
52
0
      size_t byteArraySize = hexStringToByteArray(recValue, recValueByteArr, 512);
53
0
      if (byteArraySize > 0)
54
0
      {
55
0
        init(recType, recValueByteArr, byteArraySize);
56
0
      }
57
0
    }
58
0
    else
59
0
    {
60
0
      const uint8_t* recValueByteArr = reinterpret_cast<const uint8_t*>(recValue.c_str());
61
0
      init(recType, recValueByteArr, recValue.length());
62
0
    }
63
0
  }
64
65
  void TLVRecordBuilder::copyData(const TLVRecordBuilder& other)
66
0
  {
67
0
    m_RecType = other.m_RecType;
68
0
    m_RecValueLen = other.m_RecValueLen;
69
0
    m_RecValue = nullptr;
70
0
    if (other.m_RecValue != nullptr)
71
0
    {
72
0
      m_RecValue = new uint8_t[m_RecValueLen];
73
0
      memcpy(m_RecValue, other.m_RecValue, m_RecValueLen);
74
0
    }
75
0
  }
76
77
  TLVRecordBuilder::TLVRecordBuilder(const TLVRecordBuilder& other)
78
0
  {
79
0
    copyData(other);
80
0
  }
81
82
  TLVRecordBuilder& TLVRecordBuilder::operator=(const TLVRecordBuilder& other)
83
0
  {
84
0
    if (m_RecValue != nullptr)
85
0
    {
86
0
      delete[] m_RecValue;
87
0
      m_RecValue = nullptr;
88
0
    }
89
90
0
    copyData(other);
91
92
0
    return *this;
93
0
  }
94
95
  TLVRecordBuilder::~TLVRecordBuilder()
96
83.3k
  {
97
83.3k
    if (m_RecValue != nullptr)
98
83.3k
      delete[] m_RecValue;
99
83.3k
  }
100
101
  void TLVRecordBuilder::init(uint32_t recType, const uint8_t* recValue, size_t recValueLen)
102
83.3k
  {
103
83.3k
    m_RecType = recType;
104
83.3k
    m_RecValueLen = recValueLen;
105
83.3k
    m_RecValue = new uint8_t[recValueLen];
106
83.3k
    if (recValue != nullptr)
107
0
      memcpy(m_RecValue, recValue, recValueLen);
108
83.3k
    else
109
83.3k
      memset(m_RecValue, 0, recValueLen);
110
83.3k
  }
111
112
}  // namespace pcpp