INET Framework for OMNeT++/OMNEST
inet::MemoryInputStream Class Reference

This class provides an efficient in memory bit input stream. More...

#include <MemoryInputStream.h>

Public Member Functions

 MemoryInputStream (const std::vector< uint8_t > &data, b length=b(-1), b position=b(0))
 
 MemoryInputStream (const uint8_t *buffer, b length, b position=b(0))
 
Stream querying functions
bool isReadBeyondEnd () const
 Returns true if a read operation ever read beyond the end of the stream. More...
 
b getLength () const
 Returns the total length of the stream measured in bits. More...
 
b getRemainingLength () const
 Returns the remaining unread length of the stream measured in bits. More...
 
b getPosition () const
 Returns the current read position of the stream measured in bits. More...
 
const std::vector< uint8_t > & getData () const
 
void copyData (std::vector< bool > &result, b offset=b(0), b length=b(-1)) const
 
void copyData (std::vector< uint8_t > &result, B offset=B(0), B length=B(-1)) const
 
Stream updating functions
void seek (b position)
 Updates the read position of the stream. More...
 
Bit streaming functions
bool readBit ()
 Reads a bit at the current position of the stream. More...
 
bool readBitRepeatedly (bool value, size_t count)
 Reads the same bit repeatedly at the current position of the stream. More...
 
b readBits (std::vector< bool > &bits, b length)
 Reads a sequence of bits at the current position of the stream keeping the original bit order. More...
 
Byte streaming functions
uint8_t readByte ()
 Reads a byte at the current position of the stream in MSB to LSB bit order. More...
 
bool readByteRepeatedly (uint8_t value, size_t count)
 Reads the same byte repeatedly at the current position of the stream in MSB to LSB bit order. More...
 
B readBytes (std::vector< uint8_t > &bytes, B length)
 Reads a sequence of bytes at the current position of the stream keeping the original byte order in MSB to LSB bit order. More...
 
B readBytes (uint8_t *buffer, B length)
 Reads a sequence of bytes at the current position of the stream keeping the original byte order in MSB to LSB bit order. More...
 
Basic type streaming functions
uint8_t readUint2 ()
 Reads a 2 bit unsigned integer at the current position of the stream in MSB to LSB bit order. More...
 
uint8_t readUint4 ()
 Reads a 4 bit unsigned integer at the current position of the stream in MSB to LSB bit order. More...
 
uint8_t readUint8 ()
 Reads an 8 bit unsigned integer at the current position of the stream in MSB to LSB bit order. More...
 
uint16_t readUint16Be ()
 Reads a 16 bit unsigned integer at the current position of the stream in big endian byte order and MSB to LSB bit order. More...
 
uint16_t readUint16Le ()
 Reads a 16 bit unsigned integer at the current position of the stream in little endian byte order and MSB to LSB bit order. More...
 
uint32_t readUint24Be ()
 Reads a 24 bit unsigned integer at the current position of the stream in big endian byte order and MSB to LSB bit order. More...
 
uint32_t readUint24Le ()
 Reads a 24 bit unsigned integer at the current position of the stream in little endian byte order and MSB to LSB bit order. More...
 
uint32_t readUint32Be ()
 Reads a 32 bit unsigned integer at the current position of the stream in big endian byte order and MSB to LSB bit order. More...
 
uint32_t readUint32Le ()
 Reads a 32 bit unsigned integer at the current position of the stream in little endian byte order and MSB to LSB bit order. More...
 
uint64_t readUint48Be ()
 Reads a 48 bit unsigned integer at the current position of the stream in big endian byte order and MSB to LSB bit order. More...
 
uint64_t readUint48Le ()
 Reads a 48 bit unsigned integer at the current position of the stream in little endian byte order and MSB to LSB bit order. More...
 
uint64_t readUint64Be ()
 Reads a 64 bit unsigned integer at the current position of the stream in big endian byte order and MSB to LSB bit order. More...
 
uint64_t readUint64Le ()
 Reads a 64 bit unsigned integer at the current position of the stream in little endian byte order and MSB to LSB bit order. More...
 
INET specific type streaming functions
MacAddress readMacAddress ()
 Reads a MAC address at the current position of the stream in big endian byte order and MSB to LSB bit order. More...
 
Ipv4Address readIpv4Address ()
 Reads an Ipv4 address at the current position of the stream in big endian byte order and MSB to LSB bit order. More...
 
Ipv6Address readIpv6Address ()
 Reads an Ipv6 address at the current position of the stream in big endian byte order and MSB to LSB bit order. More...
 
other useful streaming functions
std::string readString ()
 Reads a string from the current position until a zero. More...
 
uint64_t readNBitsToUint64Be (uint8_t n)
 Reads n bits of a 64 bit unsigned integer at the current position of the stream in big endian byte order and MSB to LSB bit order. More...
 

Protected Member Functions

bool isByteAligned ()
 

Protected Attributes

std::vector< uint8_t > data
 This vector contains the bits that are read from this stream. More...
 
b length
 The length of the bit stream measured in bits. More...
 
b position
 The position of the next bit that will be read measured in bits. More...
 
bool isReadBeyondEnd_ = false
 This flag indicates if the stream has been read beyond the end of data. More...
 

Detailed Description

This class provides an efficient in memory bit input stream.

The stream provides a set of read functions that read data at the current position of the stream. Most functions are implemented in the header to allow inlining.

Constructor & Destructor Documentation

◆ MemoryInputStream() [1/2]

inet::MemoryInputStream::MemoryInputStream ( const std::vector< uint8_t > &  data,
b  length = b(-1),
b  position = b(0) 
)
inline
59  :
60  data(data),
61  length(length == b(-1) ? b(data.size() * 8) : length),
63  {
64  assert(b(0) <= this->length);
65  assert(b(0) <= position && position <= this->length);
66  }

◆ MemoryInputStream() [2/2]

inet::MemoryInputStream::MemoryInputStream ( const uint8_t *  buffer,
b  length,
b  position = b(0) 
)
inline
68  :
69  data(buffer, buffer + B(length).get()),
70  length(length),
72  {
73  assert(b(0) <= this->length);
74  assert(b(0) <= position && position <= this->length);
75  }

Member Function Documentation

◆ copyData() [1/2]

void inet::MemoryInputStream::copyData ( std::vector< bool > &  result,
b  offset = b(0),
b  length = b(-1) 
) const
inline
101  {
102  size_t end = b(length == b(-1) ? this->length : offset + length).get();
103  for (size_t i = b(offset).get(); i < end; i++) {
104  size_t byteIndex = i / 8;
105  size_t bitIndex = i % 8;
106  uint8_t byte = data.at(byteIndex);
107  uint8_t mask = 1 << (7 - bitIndex);
108  bool bit = byte & mask;
109  result.push_back(bit);
110  }
111  }

Referenced by inet::FieldsChunkSerializer::deserialize().

◆ copyData() [2/2]

void inet::MemoryInputStream::copyData ( std::vector< uint8_t > &  result,
B  offset = B(0),
B  length = B(-1) 
) const
inline
113  {
114  auto end = length == B(-1) ? B(data.size()) : offset + length;
115  assert(b(0) <= offset && offset <= B(data.size()));
116  assert(b(0) <= end && end <= B(data.size()));
117  assert(offset <= end);
118  result.insert(result.begin(), data.begin() + B(offset).get(), data.begin() + B(end).get());
119  }

◆ getData()

const std::vector<uint8_t>& inet::MemoryInputStream::getData ( ) const
inline

◆ getLength()

b inet::MemoryInputStream::getLength ( ) const
inline

Returns the total length of the stream measured in bits.

87 { return length; }

◆ getPosition()

◆ getRemainingLength()

◆ isByteAligned()

bool inet::MemoryInputStream::isByteAligned ( )
inlineprotected
54  {
55  return b(position).get() % 8 == 0;
56  }

◆ isReadBeyondEnd()

bool inet::MemoryInputStream::isReadBeyondEnd ( ) const
inline

Returns true if a read operation ever read beyond the end of the stream.

82 { return isReadBeyondEnd_; }

Referenced by inet::Chunk::deserialize().

◆ readBit()

◆ readBitRepeatedly()

bool inet::MemoryInputStream::readBitRepeatedly ( bool  value,
size_t  count 
)
inline

Reads the same bit repeatedly at the current position of the stream.

157  {
158  bool success = true;
159  for (size_t i = 0; i < count; i++)
160  success &= (value == readBit());
161  return success;
162  }

Referenced by inet::BitCountChunkSerializer::deserialize(), inet::XMacHeaderSerializer::deserialize(), inet::UnitDiskPhyHeaderSerializer::deserialize(), inet::BMacHeaderSerializer::deserialize(), inet::physicallayer::ApskPhyHeaderSerializer::deserialize(), and inet::bgp::BgpHeaderSerializer::deserialize().

◆ readBits()

b inet::MemoryInputStream::readBits ( std::vector< bool > &  bits,
b  length 
)
inline

Reads a sequence of bits at the current position of the stream keeping the original bit order.

168  {
169  b i;
170  for (i = b(0); i < length; i++) {
171  if (isReadBeyondEnd_)
172  break;
173  bits.push_back(readBit());
174  }
175  return b(i);
176  }

Referenced by inet::BitsChunkSerializer::deserialize().

◆ readByte()

uint8_t inet::MemoryInputStream::readByte ( )
inline

Reads a byte at the current position of the stream in MSB to LSB bit order.

184  {
185  if (position + B(1) > length) {
186  isReadBeyondEnd_ = true;
187  position = length;
188  return 0;
189  }
190  else {
191  uint8_t result;
192  if (isByteAligned())
193  result = data[B(position).get()];
194  else {
195  int l1 = b(position).get() % 8;
196  int l2 = 8 - l1;
197  result = data[B(position - b(l1)).get()] << l1;
198  result |= data[B(position + b(l2)).get()] >> l2;
199  }
200  position += B(1);
201  return result;
202  }
203  }

Referenced by inet::Ieee8021aeTagTpidHeaderSerializer::deserialize(), inet::Ieee8022LlcHeaderSerializer::deserialize(), inet::Ipv6HeaderSerializer::deserialize(), inet::rtp::RtcpPacketSerializer::deserialize(), inet::GenericAppMsgSerializer::deserialize(), inet::VoipStreamPacketSerializer::deserialize(), inet::XMacHeaderSerializer::deserialize(), inet::BMacHeaderSerializer::deserialize(), inet::IcmpHeaderSerializer::deserialize(), inet::Ieee8021dBpduSerializer::deserialize(), inet::IgmpHeaderSerializer::deserialize(), inet::DhcpMessageSerializer::deserialize(), inet::Icmpv6HeaderSerializer::deserialize(), inet::PimPacketSerializer::deserialize(), inet::aodv::AodvControlPacketsSerializer::deserialize(), inet::CsmaCaMacHeaderSerializer::deserialize(), inet::bgp::BgpHeaderSerializer::deserialize(), inet::ArpPacketSerializer::deserialize(), inet::ieee80211::Ieee80211MacHeaderSerializer::deserialize(), inet::ieee80211::Ieee80211MgmtFrameSerializer::deserialize(), inet::Ieee8021aeTagEpdHeaderSerializer::deserialize(), inet::physicallayer::EthernetPhyHeaderSerializer::deserialize(), inet::physicallayer::Ieee80211DsssPhyHeaderSerializer::deserialize(), inet::ospfv2::Ospfv2PacketSerializer::deserialize(), inet::physicallayer::EthernetFragmentPhyHeaderSerializer::deserialize(), inet::ieee80211::Ieee80211MpduSubframeHeaderSerializer::deserialize(), inet::physicallayer::Ieee80211HrDsssPhyHeaderSerializer::deserialize(), inet::deserializeIpv6NdOptions(), inet::ospfv2::Ospfv2PacketSerializer::deserializeLsaHeader(), inet::Ipv4HeaderSerializer::deserializeOption(), inet::tcp::TcpHeaderSerializer::deserializeOption(), inet::ospfv2::Ospfv2PacketSerializer::deserializeRouterLsa(), and inet::ospfv2::Ospfv2PacketSerializer::deserializeSummaryLsa().

◆ readByteRepeatedly()

◆ readBytes() [1/2]

B inet::MemoryInputStream::readBytes ( std::vector< uint8_t > &  bytes,
B  length 
)
inline

Reads a sequence of bytes at the current position of the stream keeping the original byte order in MSB to LSB bit order.

220  {
221  assert(isByteAligned());
222  if (position + length > this->length) {
223  length = this->length - position;
224  isReadBeyondEnd_ = true;
225  }
226  auto end = position + length;
227  assert(b(0) <= position && position <= B(data.size()));
228  assert(b(0) <= end && end <= B(data.size()));
229  assert(position <= end);
230  bytes.insert(bytes.end(), data.begin() + B(position).get(), data.begin() + B(end).get());
231  position += length;
232  return length;
233  }

Referenced by inet::BytesChunkSerializer::deserialize(), inet::DhcpMessageSerializer::deserialize(), inet::sctp::SctpHeaderSerializer::deserialize(), inet::ieee80211::Ieee80211MgmtFrameSerializer::deserialize(), inet::Ipv4HeaderSerializer::deserialize(), and inet::tcp::TcpHeaderSerializer::deserialize().

◆ readBytes() [2/2]

B inet::MemoryInputStream::readBytes ( uint8_t *  buffer,
B  length 
)
inline

Reads a sequence of bytes at the current position of the stream keeping the original byte order in MSB to LSB bit order.

239  {
240  assert(isByteAligned());
241  if (position + length > this->length) {
242  length = this->length - position;
243  isReadBeyondEnd_ = true;
244  }
245  std::copy(data.begin() + B(position).get(), data.begin() + B(position + length).get(), buffer);
246  position += length;
247  return length;
248  }

◆ readIpv4Address()

◆ readIpv6Address()

Ipv6Address inet::MemoryInputStream::readIpv6Address ( )
inline

Reads an Ipv6 address at the current position of the stream in big endian byte order and MSB to LSB bit order.

447  {
448  uint32_t d[4];
449  for (auto& element : d)
450  element = readUint32Be();
451  return Ipv6Address(d[0], d[1], d[2], d[3]);
452  }

Referenced by inet::Ipv6HeaderSerializer::deserialize(), inet::Icmpv6HeaderSerializer::deserialize(), inet::aodv::AodvControlPacketsSerializer::deserialize(), and inet::deserializeIpv6NdOptions().

◆ readMacAddress()

◆ readNBitsToUint64Be()

◆ readString()

std::string inet::MemoryInputStream::readString ( )
inline

Reads a string from the current position until a zero.

460  {
461  std::vector<uint8_t> data;
462  while (uint8_t b = readByte())
463  data.push_back(b);
464  return std::string(data.begin(), data.end());
465  }

◆ readUint16Be()

uint16_t inet::MemoryInputStream::readUint16Be ( )
inline

Reads a 16 bit unsigned integer at the current position of the stream in big endian byte order and MSB to LSB bit order.

289  {
290  uint16_t value = 0;
291  value |= (static_cast<uint16_t>(readByte()) << 8);
292  value |= (static_cast<uint16_t>(readByte()) << 0);
293  return value;
294  }

Referenced by inet::Ieee802EpdHeaderSerializer::deserialize(), inet::EthernetControlFrameSerializer::deserialize(), inet::Ieee8021rTagTpidHeaderSerializer::deserialize(), inet::Ieee8022LlcHeaderSerializer::deserialize(), inet::Ieee8021aeTagTpidHeaderSerializer::deserialize(), inet::Ieee8021qTagTpidHeaderSerializer::deserialize(), inet::Ipv6HeaderSerializer::deserialize(), inet::rtp::RtcpPacketSerializer::deserialize(), inet::rtp::RtpMpegPacketSerializer::deserialize(), inet::rtp::RtpPacketSerializer::deserialize(), inet::UnitDiskPhyHeaderSerializer::deserialize(), inet::physicallayer::ApskPhyHeaderSerializer::deserialize(), inet::IcmpHeaderSerializer::deserialize(), inet::DhcpMessageSerializer::deserialize(), inet::EchoPacketSerializer::deserialize(), inet::Icmpv6HeaderSerializer::deserialize(), inet::IgmpHeaderSerializer::deserialize(), inet::BMacHeaderSerializer::deserialize(), inet::PimPacketSerializer::deserialize(), inet::PppHeaderSerializer::deserialize(), inet::RipPacketSerializer::deserialize(), inet::SequenceNumberHeaderSerializer::deserialize(), inet::UdpHeaderSerializer::deserialize(), inet::VoipStreamPacketSerializer::deserialize(), inet::XMacHeaderSerializer::deserialize(), inet::CrcHeaderSerializer::deserialize(), inet::Ieee8021dBpduSerializer::deserialize(), inet::CsmaCaMacHeaderSerializer::deserialize(), inet::bgp::BgpHeaderSerializer::deserialize(), inet::ospf::OspfPacketSerializer::deserialize(), inet::AckingMacHeaderSerializer::deserialize(), inet::physicallayer::Ieee80211FhssPhyHeaderSerializer::deserialize(), inet::ieee80211::Ieee80211MacHeaderSerializer::deserialize(), inet::ieee80211::Ieee80211MgmtFrameSerializer::deserialize(), inet::ArpPacketSerializer::deserialize(), inet::Ieee8021qTagEpdHeaderSerializer::deserialize(), inet::Ieee8021rTagEpdHeaderSerializer::deserialize(), inet::Ieee8021aeTagEpdHeaderSerializer::deserialize(), inet::PppTrailerSerializer::deserialize(), inet::EthernetTypeOrLengthFieldSerializer::deserialize(), inet::physicallayer::Ieee80211IrPhyHeaderSerializer::deserialize(), inet::ieee80211::Ieee80211MsduSubframeHeaderSerializer::deserialize(), inet::EthernetMacHeaderSerializer::deserialize(), inet::ospfv2::Ospfv2PacketSerializer::deserialize(), inet::physicallayer::Ieee80211DsssPhyHeaderSerializer::deserialize(), inet::physicallayer::Ieee80211HrDsssPhyHeaderSerializer::deserialize(), inet::physicallayer::Ieee80211OfdmPhyHeaderSerializer::deserialize(), inet::physicallayer::Ieee80211ErpOfdmPhyHeaderSerializer::deserialize(), inet::deserializeIpv6NdOptions(), inet::ospfv2::Ospfv2PacketSerializer::deserializeLsaHeader(), inet::Ipv4HeaderSerializer::deserializeOption(), inet::tcp::TcpHeaderSerializer::deserializeOption(), inet::ospfv2::Ospfv2PacketSerializer::deserializeOspfHeader(), inet::ospfv2::Ospfv2PacketSerializer::deserializeRouterLsa(), inet::GptpPacketSerializer::readGptpBase(), inet::GptpPacketSerializer::readGptpFollowUpInformationTlv(), and inet::GptpPacketSerializer::readPortIdentity().

◆ readUint16Le()

uint16_t inet::MemoryInputStream::readUint16Le ( )
inline

Reads a 16 bit unsigned integer at the current position of the stream in little endian byte order and MSB to LSB bit order.

300  {
301  uint16_t value = 0;
302  value |= (static_cast<uint16_t>(readByte()) << 0);
303  value |= (static_cast<uint16_t>(readByte()) << 8);
304  return value;
305  }

Referenced by inet::ieee80211::Ieee80211MacHeaderSerializer::deserialize().

◆ readUint2()

uint8_t inet::MemoryInputStream::readUint2 ( )
inline

Reads a 2 bit unsigned integer at the current position of the stream in MSB to LSB bit order.

257  {
258  uint8_t value = 0;
259  if (readBit()) value |= 0x2;
260  if (readBit()) value |= 0x1;
261  return value;
262  }

Referenced by inet::Ipv6HeaderSerializer::deserialize().

◆ readUint24Be()

uint32_t inet::MemoryInputStream::readUint24Be ( )
inline

Reads a 24 bit unsigned integer at the current position of the stream in big endian byte order and MSB to LSB bit order.

311  {
312  uint32_t value = 0;
313  value |= (static_cast<uint32_t>(readByte()) << 16);
314  value |= (static_cast<uint32_t>(readByte()) << 8);
315  value |= (static_cast<uint32_t>(readByte()) << 0);
316  return value;
317  }

Referenced by inet::ospfv2::Ospfv2PacketSerializer::deserializeAsExternalLsa(), inet::ospfv2::Ospfv2PacketSerializer::deserializeSummaryLsa(), and inet::GptpPacketSerializer::readGptpFollowUpInformationTlv().

◆ readUint24Le()

uint32_t inet::MemoryInputStream::readUint24Le ( )
inline

Reads a 24 bit unsigned integer at the current position of the stream in little endian byte order and MSB to LSB bit order.

323  {
324  uint32_t value = 0;
325  value |= (static_cast<uint32_t>(readByte()) << 0);
326  value |= (static_cast<uint32_t>(readByte()) << 8);
327  value |= (static_cast<uint32_t>(readByte()) << 16);
328  return value;
329  }

◆ readUint32Be()

uint32_t inet::MemoryInputStream::readUint32Be ( )
inline

Reads a 32 bit unsigned integer at the current position of the stream in big endian byte order and MSB to LSB bit order.

335  {
336  uint32_t value = 0;
337  value |= (static_cast<uint32_t>(readByte()) << 24);
338  value |= (static_cast<uint32_t>(readByte()) << 16);
339  value |= (static_cast<uint32_t>(readByte()) << 8);
340  value |= (static_cast<uint32_t>(readByte()) << 0);
341  return value;
342  }

Referenced by inet::Ieee8021aeTagTpidHeaderSerializer::deserialize(), inet::rtp::RtcpPacketSerializer::deserialize(), inet::rtp::RtpPacketSerializer::deserialize(), inet::Ipv6HeaderSerializer::deserialize(), inet::ApplicationPacketSerializer::deserialize(), inet::RipPacketSerializer::deserialize(), inet::IcmpHeaderSerializer::deserialize(), inet::Icmpv6HeaderSerializer::deserialize(), inet::VoipStreamPacketSerializer::deserialize(), inet::DhcpMessageSerializer::deserialize(), inet::FcsHeaderSerializer::deserialize(), inet::GenericAppMsgSerializer::deserialize(), inet::Ieee8021dBpduSerializer::deserialize(), inet::DsdvHelloSerializer::deserialize(), inet::IgmpHeaderSerializer::deserialize(), inet::EtherAppReqSerializer::deserialize(), inet::PimPacketSerializer::deserialize(), inet::aodv::AodvControlPacketsSerializer::deserialize(), inet::bgp::BgpHeaderSerializer::deserialize(), inet::ieee80211::Ieee80211MacHeaderSerializer::deserialize(), inet::Ieee8021aeTagEpdHeaderSerializer::deserialize(), inet::CsmaCaMacTrailerSerializer::deserialize(), inet::EtherAppRespSerializer::deserialize(), inet::ieee80211::Ieee80211MacTrailerSerializer::deserialize(), inet::ospfv2::Ospfv2PacketSerializer::deserialize(), inet::EthernetFcsSerializer::deserialize(), inet::ospfv2::Ospfv2PacketSerializer::deserializeAsExternalLsa(), inet::deserializeIpv6NdOptions(), inet::ospfv2::Ospfv2PacketSerializer::deserializeLsaHeader(), inet::Ipv4HeaderSerializer::deserializeOption(), inet::tcp::TcpHeaderSerializer::deserializeOption(), inet::ospfv2::Ospfv2PacketSerializer::deserializeRouterLsa(), inet::GptpPacketSerializer::readGptpBase(), inet::GptpPacketSerializer::readGptpFollowUpInformationTlv(), inet::GptpPacketSerializer::readScaledNS(), and inet::GptpPacketSerializer::readTimestamp().

◆ readUint32Le()

uint32_t inet::MemoryInputStream::readUint32Le ( )
inline

Reads a 32 bit unsigned integer at the current position of the stream in little endian byte order and MSB to LSB bit order.

348  {
349  uint32_t value = 0;
350  value |= (static_cast<uint32_t>(readByte()) << 0);
351  value |= (static_cast<uint32_t>(readByte()) << 8);
352  value |= (static_cast<uint32_t>(readByte()) << 16);
353  value |= (static_cast<uint32_t>(readByte()) << 24);
354  return value;
355  }

◆ readUint4()

uint8_t inet::MemoryInputStream::readUint4 ( )
inline

◆ readUint48Be()

uint64_t inet::MemoryInputStream::readUint48Be ( )
inline

Reads a 48 bit unsigned integer at the current position of the stream in big endian byte order and MSB to LSB bit order.

361  {
362  uint64_t value = 0;
363  value |= (static_cast<uint64_t>(readByte()) << 40);
364  value |= (static_cast<uint64_t>(readByte()) << 32);
365  value |= (static_cast<uint64_t>(readByte()) << 24);
366  value |= (static_cast<uint64_t>(readByte()) << 16);
367  value |= (static_cast<uint64_t>(readByte()) << 8);
368  value |= (static_cast<uint64_t>(readByte()) << 0);
369  return value;
370  }

Referenced by inet::GptpPacketSerializer::readTimestamp().

◆ readUint48Le()

uint64_t inet::MemoryInputStream::readUint48Le ( )
inline

Reads a 48 bit unsigned integer at the current position of the stream in little endian byte order and MSB to LSB bit order.

376  {
377  uint64_t value = 0;
378  value |= (static_cast<uint64_t>(readByte()) << 0);
379  value |= (static_cast<uint64_t>(readByte()) << 8);
380  value |= (static_cast<uint64_t>(readByte()) << 16);
381  value |= (static_cast<uint64_t>(readByte()) << 24);
382  value |= (static_cast<uint64_t>(readByte()) << 32);
383  value |= (static_cast<uint64_t>(readByte()) << 40);
384  return value;
385  }

◆ readUint64Be()

uint64_t inet::MemoryInputStream::readUint64Be ( )
inline

Reads a 64 bit unsigned integer at the current position of the stream in big endian byte order and MSB to LSB bit order.

391  {
392  uint64_t value = 0;
393  value |= (static_cast<uint64_t>(readByte()) << 56);
394  value |= (static_cast<uint64_t>(readByte()) << 48);
395  value |= (static_cast<uint64_t>(readByte()) << 40);
396  value |= (static_cast<uint64_t>(readByte()) << 32);
397  value |= (static_cast<uint64_t>(readByte()) << 24);
398  value |= (static_cast<uint64_t>(readByte()) << 16);
399  value |= (static_cast<uint64_t>(readByte()) << 8);
400  value |= (static_cast<uint64_t>(readByte()) << 0);
401  return value;
402  }

Referenced by inet::rtp::RtcpPacketSerializer::deserialize(), inet::XMacHeaderSerializer::deserialize(), inet::BMacHeaderSerializer::deserialize(), inet::GenericAppMsgSerializer::deserialize(), inet::DhcpMessageSerializer::deserialize(), inet::AckingMacHeaderSerializer::deserialize(), inet::ieee80211::Ieee80211MgmtFrameSerializer::deserialize(), inet::ieee80211::Ieee80211MacHeaderSerializer::deserialize(), inet::GptpPacketSerializer::readClock8(), inet::GptpPacketSerializer::readPortIdentity(), and inet::GptpPacketSerializer::readScaledNS().

◆ readUint64Le()

uint64_t inet::MemoryInputStream::readUint64Le ( )
inline

Reads a 64 bit unsigned integer at the current position of the stream in little endian byte order and MSB to LSB bit order.

408  {
409  uint64_t value = 0;
410  value |= (static_cast<uint64_t>(readByte()) << 0);
411  value |= (static_cast<uint64_t>(readByte()) << 8);
412  value |= (static_cast<uint64_t>(readByte()) << 16);
413  value |= (static_cast<uint64_t>(readByte()) << 24);
414  value |= (static_cast<uint64_t>(readByte()) << 32);
415  value |= (static_cast<uint64_t>(readByte()) << 40);
416  value |= (static_cast<uint64_t>(readByte()) << 48);
417  value |= (static_cast<uint64_t>(readByte()) << 56);
418  return value;
419  }

◆ readUint8()

◆ seek()

void inet::MemoryInputStream::seek ( b  position)
inline

Member Data Documentation

◆ data

std::vector<uint8_t> inet::MemoryInputStream::data
protected

This vector contains the bits that are read from this stream.

The first bit of the bit stream is stored in the most significant bit of the first byte. For the longest possible bit stream given the same number of bytes, the last bit of the bit stream is stored in the least significant bit of the last byte. In other cases some of the lower bits of the last byte are not used.

◆ isReadBeyondEnd_

bool inet::MemoryInputStream::isReadBeyondEnd_ = false
protected

This flag indicates if the stream has been read beyond the end of data.

◆ length

b inet::MemoryInputStream::length
protected

The length of the bit stream measured in bits.

◆ position

b inet::MemoryInputStream::position
protected

The position of the next bit that will be read measured in bits.


The documentation for this class was generated from the following file:
MAC_ADDRESS_SIZE
#define MAC_ADDRESS_SIZE
Definition: MacAddress.h:16
inet::MemoryInputStream::isByteAligned
bool isByteAligned()
Definition: MemoryInputStream.h:54
inet::count
int count(const std::vector< T > &v, const Tk &a)
Definition: stlutils.h:54
inet::MemoryInputStream::readBit
bool readBit()
Reads a bit at the current position of the stream.
Definition: MemoryInputStream.h:138
inet::MemoryInputStream::readUint32Be
uint32_t readUint32Be()
Reads a 32 bit unsigned integer at the current position of the stream in big endian byte order and MS...
Definition: MemoryInputStream.h:335
inet::MemoryInputStream::data
std::vector< uint8_t > data
This vector contains the bits that are read from this stream.
Definition: MemoryInputStream.h:39
inet::units::units::B
intscale< b, 1, 8 > B
Definition: Units.h:1168
inet::MemoryInputStream::length
b length
The length of the bit stream measured in bits.
Definition: MemoryInputStream.h:43
inet::MemoryInputStream::readByte
uint8_t readByte()
Reads a byte at the current position of the stream in MSB to LSB bit order.
Definition: MemoryInputStream.h:184
inet::units::values::b
value< int64_t, units::b > b
Definition: Units.h:1241
inet::MemoryInputStream::isReadBeyondEnd_
bool isReadBeyondEnd_
This flag indicates if the stream has been read beyond the end of data.
Definition: MemoryInputStream.h:51
inet::MemoryInputStream::position
b position
The position of the next bit that will be read measured in bits.
Definition: MemoryInputStream.h:47
copy
MIT License free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to copy
Definition: LICENSE.txt:8