A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
tag-buffer.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2008 INRIA
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
*/
19
#ifndef TAG_BUFFER_H
20
#define TAG_BUFFER_H
21
22
#include <stdint.h>
23
24
#define TAG_BUFFER_USE_INLINE 1
25
26
#ifdef TAG_BUFFER_USE_INLINE
27
#define TAG_BUFFER_INLINE inline
28
#else
29
#define TAG_BUFFER_INLINE
30
#endif
31
32
namespace
ns3
33
{
34
51
class
TagBuffer
52
{
53
public
:
59
TagBuffer
(uint8_t*
start
, uint8_t* end);
60
65
void
TrimAtEnd
(uint32_t trim);
66
71
void
CopyFrom
(
TagBuffer
o);
72
78
TAG_BUFFER_INLINE
void
WriteU8
(uint8_t v);
84
TAG_BUFFER_INLINE
void
WriteU16
(uint16_t v);
90
TAG_BUFFER_INLINE
void
WriteU32
(uint32_t v);
96
void
WriteU64
(uint64_t v);
103
void
WriteDouble
(
double
v);
111
void
Write
(
const
uint8_t* buffer, uint32_t size);
118
TAG_BUFFER_INLINE
uint8_t
ReadU8
();
125
TAG_BUFFER_INLINE
uint16_t
ReadU16
();
132
TAG_BUFFER_INLINE
uint32_t
ReadU32
();
139
uint64_t
ReadU64
();
146
double
ReadDouble
();
155
void
Read
(uint8_t* buffer, uint32_t size);
156
157
private
:
158
uint8_t*
m_current
;
159
uint8_t*
m_end
;
160
};
161
162
}
// namespace ns3
163
164
#ifdef TAG_BUFFER_USE_INLINE
165
166
#include "ns3/assert.h"
167
168
namespace
ns3
169
{
170
171
void
172
TagBuffer::WriteU8
(uint8_t v)
173
{
174
NS_ASSERT
(
m_current
+ 1 <=
m_end
);
175
*
m_current
= v;
176
m_current
++;
177
}
178
179
void
180
TagBuffer::WriteU16
(uint16_t
data
)
181
{
182
WriteU8
((
data
>> 0) & 0xff);
183
WriteU8
((
data
>> 8) & 0xff);
184
}
185
186
void
187
TagBuffer::WriteU32
(uint32_t
data
)
188
{
189
WriteU8
((
data
>> 0) & 0xff);
190
WriteU8
((
data
>> 8) & 0xff);
191
WriteU8
((
data
>> 16) & 0xff);
192
WriteU8
((
data
>> 24) & 0xff);
193
}
194
195
uint8_t
196
TagBuffer::ReadU8
()
197
{
198
NS_ASSERT
(
m_current
+ 1 <=
m_end
);
199
uint8_t v;
200
v = *
m_current
;
201
m_current
++;
202
return
v;
203
}
204
205
uint16_t
206
TagBuffer::ReadU16
()
207
{
208
uint8_t byte0 =
ReadU8
();
209
uint8_t byte1 =
ReadU8
();
210
uint16_t
data
= byte1;
211
data
<<= 8;
212
data
|= byte0;
213
return
data
;
214
}
215
216
uint32_t
217
TagBuffer::ReadU32
()
218
{
219
uint8_t byte0 =
ReadU8
();
220
uint8_t byte1 =
ReadU8
();
221
uint8_t byte2 =
ReadU8
();
222
uint8_t byte3 =
ReadU8
();
223
uint32_t
data
= byte3;
224
data
<<= 8;
225
data
|= byte2;
226
data
<<= 8;
227
data
|= byte1;
228
data
<<= 8;
229
data
|= byte0;
230
return
data
;
231
}
232
233
}
// namespace ns3
234
235
#endif
/* TAG_BUFFER_USE_INLINE */
236
237
#endif
/* TAG_BUFFER_H */
ns3::TagBuffer
read and write tag data
Definition:
tag-buffer.h:52
ns3::TagBuffer::TagBuffer
TagBuffer(uint8_t *start, uint8_t *end)
Constructor.
Definition:
tag-buffer.cc:191
ns3::TagBuffer::ReadU32
TAG_BUFFER_INLINE uint32_t ReadU32()
Definition:
tag-buffer.h:217
ns3::TagBuffer::WriteU64
void WriteU64(uint64_t v)
Definition:
tag-buffer.cc:104
ns3::TagBuffer::TrimAtEnd
void TrimAtEnd(uint32_t trim)
Trim some space from the end.
Definition:
tag-buffer.cc:199
ns3::TagBuffer::Read
void Read(uint8_t *buffer, uint32_t size)
Definition:
tag-buffer.cc:183
ns3::TagBuffer::WriteDouble
void WriteDouble(double v)
Definition:
tag-buffer.cc:118
ns3::TagBuffer::WriteU8
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
Definition:
tag-buffer.h:172
ns3::TagBuffer::ReadU8
TAG_BUFFER_INLINE uint8_t ReadU8()
Definition:
tag-buffer.h:196
ns3::TagBuffer::ReadU16
TAG_BUFFER_INLINE uint16_t ReadU16()
Definition:
tag-buffer.h:206
ns3::TagBuffer::WriteU32
TAG_BUFFER_INLINE void WriteU32(uint32_t v)
Definition:
tag-buffer.h:187
ns3::TagBuffer::ReadU64
uint64_t ReadU64()
Definition:
tag-buffer.cc:139
ns3::TagBuffer::m_current
uint8_t * m_current
current TagBuffer position
Definition:
tag-buffer.h:158
ns3::TagBuffer::m_end
uint8_t * m_end
end TagBuffer position
Definition:
tag-buffer.h:159
ns3::TagBuffer::ReadDouble
double ReadDouble()
Definition:
tag-buffer.cc:170
ns3::TagBuffer::Write
void Write(const uint8_t *buffer, uint32_t size)
Definition:
tag-buffer.cc:129
ns3::TagBuffer::WriteU16
TAG_BUFFER_INLINE void WriteU16(uint16_t v)
Definition:
tag-buffer.h:180
ns3::TagBuffer::CopyFrom
void CopyFrom(TagBuffer o)
Copy the nternal structure of another TagBuffer.
Definition:
tag-buffer.cc:207
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:66
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
two-ray-to-three-gpp-ch-calibration.start
start
Definition:
two-ray-to-three-gpp-ch-calibration.py:520
data
uint8_t data[writeSize]
Definition:
socket-bound-tcp-static-routing.cc:52
TAG_BUFFER_INLINE
#define TAG_BUFFER_INLINE
Definition:
tag-buffer.h:27
src
network
model
tag-buffer.h
Generated on Sun Mar 3 2024 17:11:06 for ns-3 by
1.9.1