Bit serializer. More...
#include "bit-serializer.h"
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. | |
Bit serializer.
See also
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:
Definition at line 48 of file bit-serializer.h.
ns3::BitSerializer::BitSerializer | ( | ) |
Definition at line 22 of file bit-serializer.cc.
References m_padAtEnd, and NS_LOG_FUNCTION.
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.
Definition at line 76 of file bit-serializer.cc.
References m_blob, m_padAtEnd, NS_LOG_FUNCTION, PadAtEnd(), and PadAtStart().
Referenced by BitSerializerTest::DoRun().
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.
[out] | buffer | The buffer where to store the return data. |
[in] | size | The size of 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().
void ns3::BitSerializer::InsertPaddingAtEnd | ( | bool | padAtEnd | ) |
Toggles the padding insertion policy.
padAtEnd | true 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().
|
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().
|
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().
void ns3::BitSerializer::PushBits | ( | uint64_t | value, |
uint8_t | significantBits ) |
Pushes a number of bits in the blob.
value | the bits to be inserted. |
significantBits | Number of bits to insert. |
Definition at line 54 of file bit-serializer.cc.
References m_blob, and NS_LOG_FUNCTION.
Referenced by BitSerializerTest::DoRun().
|
private |
Blob of serialized bits.
Definition at line 101 of file bit-serializer.h.
Referenced by GetBytes(), GetBytes(), PadAtEnd(), PadAtStart(), and PushBits().
|
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().