A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ns3::BitSerializer Class Reference

Bit serializer. More...

#include "bit-serializer.h"

+ Collaboration diagram for ns3::BitSerializer:

Public Member Functions

 BitSerializer ()
 
std::vector< uint8_t > GetBytes ()
 Get the bytes representation of the blob.
 
uint8_t GetBytes (uint8_t *buffer, uint32_t size)
 Get the bytes representation of the blob.
 
void InsertPaddingAtEnd (bool padAtEnd)
 Toggles the padding insertion policy.
 
void PushBits (uint64_t value, uint8_t significantBits)
 Pushes a number of bits in the blob.
 

Private Member Functions

void PadAtEnd ()
 Add the padding at the end of the blob.
 
void PadAtStart ()
 Add the padding at the start of the blob.
 

Private Attributes

std::vector< bool > m_blob
 Blob of serialized bits.
 
bool m_padAtEnd
 True if the padding must be added at the end of the blob.
 

Detailed Description

Bit serializer.

See also

See also
ns3::BitDeserializer

This class helps converting a variable number, variable sized number of bit-boundary fields to its final byte array representation.

The typical use-case is:

  aaa: A field
  bbb: B field
  ccc: C field
  ddd: D field
  000: padding

  |aaaa abbb bbcc cdd0|

Padding can be automatically added at the end or at the start of the byte blob to reach a multiple of 8 bits. By default the padding is added at the end of the byte blob.

This class should be used in two cases:

  • When the number of fields is large.
  • When the number of fields is variable. In the other cases it's more convenient to use a simple bitmask.

Definition at line 48 of file bit-serializer.h.

Constructor & Destructor Documentation

◆ BitSerializer()

ns3::BitSerializer::BitSerializer ( )

Definition at line 22 of file bit-serializer.cc.

References m_padAtEnd, and NS_LOG_FUNCTION.

Member Function Documentation

◆ GetBytes() [1/2]

std::vector< uint8_t > ns3::BitSerializer::GetBytes ( )

Get the bytes representation of the blob.

Note that this operation automatically add the needed padding at the end (or start) of the blob.

Warning
{This operation clears the stored data.}
Returns
The byte representation of the blob.

Definition at line 76 of file bit-serializer.cc.

References m_blob, m_padAtEnd, NS_LOG_FUNCTION, PadAtEnd(), and PadAtStart().

Referenced by BitSerializerTest::DoRun().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetBytes() [2/2]

uint8_t ns3::BitSerializer::GetBytes ( uint8_t * buffer,
uint32_t size )

Get the bytes representation of the blob.

Note that this operation automatically add the needed padding at the end (or start) of the blob.

Warning
{This operation clears the stored data.}
Parameters
[out]bufferThe buffer where to store the return data.
[in]sizeThe size of the buffer.
Returns
The number of bytes actually used in the buffer.

Definition at line 100 of file bit-serializer.cc.

References m_blob, m_padAtEnd, NS_ABORT_MSG_IF, NS_LOG_FUNCTION, PadAtEnd(), and PadAtStart().

+ Here is the call graph for this function:

◆ InsertPaddingAtEnd()

void ns3::BitSerializer::InsertPaddingAtEnd ( bool padAtEnd)

Toggles the padding insertion policy.

Parameters
padAtEndtrue if the padding have to be inserted at the end of the bit blob.

Definition at line 29 of file bit-serializer.cc.

References m_padAtEnd, and NS_LOG_FUNCTION.

Referenced by BitSerializerTest::DoRun().

+ Here is the caller graph for this function:

◆ PadAtEnd()

void ns3::BitSerializer::PadAtEnd ( )
private

Add the padding at the end of the blob.

Definition at line 46 of file bit-serializer.cc.

References m_blob.

Referenced by GetBytes(), and GetBytes().

+ Here is the caller graph for this function:

◆ PadAtStart()

void ns3::BitSerializer::PadAtStart ( )
private

Add the padding at the start of the blob.

Definition at line 36 of file bit-serializer.cc.

References m_blob, and NS_LOG_FUNCTION.

Referenced by GetBytes(), and GetBytes().

+ Here is the caller graph for this function:

◆ PushBits()

void ns3::BitSerializer::PushBits ( uint64_t value,
uint8_t significantBits )

Pushes a number of bits in the blob.

Parameters
valuethe bits to be inserted.
significantBitsNumber of bits to insert.

Definition at line 54 of file bit-serializer.cc.

References m_blob, and NS_LOG_FUNCTION.

Referenced by BitSerializerTest::DoRun().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_blob

std::vector<bool> ns3::BitSerializer::m_blob
private

Blob of serialized bits.

Definition at line 101 of file bit-serializer.h.

Referenced by GetBytes(), GetBytes(), PadAtEnd(), PadAtStart(), and PushBits().

◆ m_padAtEnd

bool ns3::BitSerializer::m_padAtEnd
private

True if the padding must be added at the end of the blob.

Definition at line 102 of file bit-serializer.h.

Referenced by BitSerializer(), GetBytes(), GetBytes(), and InsertPaddingAtEnd().


The documentation for this class was generated from the following files: