A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
tag-buffer.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2008 INRIA
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7
*/
8
#include "
tag-buffer.h
"
9
10
#include "ns3/assert.h"
11
#include "ns3/log.h"
12
13
#include <cstring>
14
15
namespace
ns3
16
{
17
18
NS_LOG_COMPONENT_DEFINE
(
"TagBuffer"
);
19
20
#ifndef TAG_BUFFER_USE_INLINE
21
22
void
23
TagBuffer::WriteU8
(uint8_t v)
24
{
25
NS_LOG_FUNCTION
(
this
<<
static_cast<
uint32_t
>
(v));
26
NS_ASSERT
(
m_current
+ 1 <=
m_end
);
27
*
m_current
= v;
28
m_current
++;
29
}
30
31
void
32
TagBuffer::WriteU16
(uint16_t
data
)
33
{
34
NS_LOG_FUNCTION
(
this
<<
data
);
35
WriteU8
((
data
>> 0) & 0xff);
36
WriteU8
((
data
>> 8) & 0xff);
37
}
38
39
void
40
TagBuffer::WriteU32
(
uint32_t
data
)
41
{
42
NS_LOG_FUNCTION
(
this
<<
data
);
43
WriteU8
((
data
>> 0) & 0xff);
44
WriteU8
((
data
>> 8) & 0xff);
45
WriteU8
((
data
>> 16) & 0xff);
46
WriteU8
((
data
>> 24) & 0xff);
47
}
48
49
uint8_t
50
TagBuffer::ReadU8
()
51
{
52
NS_LOG_FUNCTION
(
this
);
53
NS_ASSERT
(
m_current
+ 1 <=
m_end
);
54
uint8_t v;
55
v = *
m_current
;
56
m_current
++;
57
return
v;
58
}
59
60
uint16_t
61
TagBuffer::ReadU16
()
62
{
63
NS_LOG_FUNCTION
(
this
);
64
uint8_t byte0 =
ReadU8
();
65
uint8_t byte1 =
ReadU8
();
66
uint16_t
data
= byte1;
67
data
<<= 8;
68
data
|= byte0;
69
return
data
;
70
}
71
72
uint32_t
73
TagBuffer::ReadU32
()
74
{
75
NS_LOG_FUNCTION
(
this
);
76
uint8_t byte0 =
ReadU8
();
77
uint8_t byte1 =
ReadU8
();
78
uint8_t byte2 =
ReadU8
();
79
uint8_t byte3 =
ReadU8
();
80
uint32_t
data
= byte3;
81
data
<<= 8;
82
data
|= byte2;
83
data
<<= 8;
84
data
|= byte1;
85
data
<<= 8;
86
data
|= byte0;
87
return
data
;
88
}
89
90
#endif
/* TAG_BUFFER_USE_INLINE */
91
92
void
93
TagBuffer::WriteU64
(uint64_t
data
)
94
{
95
NS_LOG_FUNCTION
(
this
<<
data
);
96
WriteU8
((
data
>> 0) & 0xff);
97
WriteU8
((
data
>> 8) & 0xff);
98
WriteU8
((
data
>> 16) & 0xff);
99
WriteU8
((
data
>> 24) & 0xff);
100
WriteU8
((
data
>> 32) & 0xff);
101
WriteU8
((
data
>> 40) & 0xff);
102
WriteU8
((
data
>> 48) & 0xff);
103
WriteU8
((
data
>> 56) & 0xff);
104
}
105
106
void
107
TagBuffer::WriteDouble
(
double
v)
108
{
109
NS_LOG_FUNCTION
(
this
<< v);
110
auto
buf = (uint8_t*)&v;
111
for
(
uint32_t
i = 0; i <
sizeof
(
double
); ++i, ++buf)
112
{
113
WriteU8
(*buf);
114
}
115
}
116
117
void
118
TagBuffer::Write
(
const
uint8_t* buffer,
uint32_t
size)
119
{
120
NS_LOG_FUNCTION
(
this
<< &buffer << size);
121
for
(
uint32_t
i = 0; i < size; ++i, ++buffer)
122
{
123
WriteU8
(*buffer);
124
}
125
}
126
127
uint64_t
128
TagBuffer::ReadU64
()
129
{
130
NS_LOG_FUNCTION
(
this
);
131
uint8_t byte0 =
ReadU8
();
132
uint8_t byte1 =
ReadU8
();
133
uint8_t byte2 =
ReadU8
();
134
uint8_t byte3 =
ReadU8
();
135
uint8_t byte4 =
ReadU8
();
136
uint8_t byte5 =
ReadU8
();
137
uint8_t byte6 =
ReadU8
();
138
uint8_t byte7 =
ReadU8
();
139
uint64_t
data
= byte7;
140
data
<<= 8;
141
data
|= byte6;
142
data
<<= 8;
143
data
|= byte5;
144
data
<<= 8;
145
data
|= byte4;
146
data
<<= 8;
147
data
|= byte3;
148
data
<<= 8;
149
data
|= byte2;
150
data
<<= 8;
151
data
|= byte1;
152
data
<<= 8;
153
data
|= byte0;
154
155
return
data
;
156
}
157
158
double
159
TagBuffer::ReadDouble
()
160
{
161
NS_LOG_FUNCTION
(
this
);
162
double
v;
163
auto
buf = (uint8_t*)&v;
164
for
(
uint32_t
i = 0; i <
sizeof
(
double
); ++i, ++buf)
165
{
166
*buf =
ReadU8
();
167
}
168
return
v;
169
}
170
171
void
172
TagBuffer::Read
(uint8_t* buffer,
uint32_t
size)
173
{
174
NS_LOG_FUNCTION
(
this
<< &buffer << size);
175
std::memcpy(buffer,
m_current
, size);
176
m_current
+= size;
177
NS_ASSERT
(
m_current
<=
m_end
);
178
}
179
180
TagBuffer::TagBuffer
(uint8_t* start, uint8_t* end)
181
: m_current(start),
182
m_end(end)
183
{
184
NS_LOG_FUNCTION
(
this
<< &start << &end);
185
}
186
187
void
188
TagBuffer::TrimAtEnd
(
uint32_t
trim)
189
{
190
NS_LOG_FUNCTION
(
this
<< trim);
191
NS_ASSERT
(
m_current
<= (
m_end
- trim));
192
m_end
-= trim;
193
}
194
195
void
196
TagBuffer::CopyFrom
(
TagBuffer
o)
197
{
198
NS_LOG_FUNCTION
(
this
<< &o);
199
NS_ASSERT
(o.
m_end
>= o.
m_current
);
200
NS_ASSERT
(
m_end
>=
m_current
);
201
uintptr_t size = o.
m_end
- o.
m_current
;
202
NS_ASSERT
(size <= (uintptr_t)(
m_end
-
m_current
));
203
std::memcpy(
m_current
, o.
m_current
, size);
204
m_current
+= size;
205
}
206
207
}
// namespace ns3
double
ns3::TagBuffer
read and write tag data
Definition
tag-buffer.h:41
ns3::TagBuffer::TagBuffer
TagBuffer(uint8_t *start, uint8_t *end)
Constructor.
Definition
tag-buffer.cc:180
ns3::TagBuffer::ReadU32
TAG_BUFFER_INLINE uint32_t ReadU32()
Definition
tag-buffer.h:206
ns3::TagBuffer::WriteU64
void WriteU64(uint64_t v)
Definition
tag-buffer.cc:93
ns3::TagBuffer::TrimAtEnd
void TrimAtEnd(uint32_t trim)
Trim some space from the end.
Definition
tag-buffer.cc:188
ns3::TagBuffer::Read
void Read(uint8_t *buffer, uint32_t size)
Definition
tag-buffer.cc:172
ns3::TagBuffer::WriteDouble
void WriteDouble(double v)
Definition
tag-buffer.cc:107
ns3::TagBuffer::WriteU8
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
Definition
tag-buffer.h:161
ns3::TagBuffer::ReadU8
TAG_BUFFER_INLINE uint8_t ReadU8()
Definition
tag-buffer.h:185
ns3::TagBuffer::ReadU16
TAG_BUFFER_INLINE uint16_t ReadU16()
Definition
tag-buffer.h:195
ns3::TagBuffer::WriteU32
TAG_BUFFER_INLINE void WriteU32(uint32_t v)
Definition
tag-buffer.h:176
ns3::TagBuffer::ReadU64
uint64_t ReadU64()
Definition
tag-buffer.cc:128
ns3::TagBuffer::m_current
uint8_t * m_current
current TagBuffer position
Definition
tag-buffer.h:147
ns3::TagBuffer::m_end
uint8_t * m_end
end TagBuffer position
Definition
tag-buffer.h:148
ns3::TagBuffer::ReadDouble
double ReadDouble()
Definition
tag-buffer.cc:159
ns3::TagBuffer::Write
void Write(const uint8_t *buffer, uint32_t size)
Definition
tag-buffer.cc:118
ns3::TagBuffer::WriteU16
TAG_BUFFER_INLINE void WriteU16(uint16_t v)
Definition
tag-buffer.h:169
ns3::TagBuffer::CopyFrom
void CopyFrom(TagBuffer o)
Copy the nternal structure of another TagBuffer.
Definition
tag-buffer.cc:196
uint32_t
NS_ASSERT
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition
assert.h:55
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition
log-macros-enabled.h:229
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
data
uint8_t data[writeSize]
Definition
socket-bound-tcp-static-routing.cc:41
tag-buffer.h
src
network
model
tag-buffer.cc
Generated on Fri Nov 8 2024 13:59:05 for ns-3 by
1.11.0