Bit serializer. More...
#include "bit-serializer.h"
Public Member Functions | |
BitSerializer () | |
std::vector< uint8_t > | GetBytes () |
Get the bytes representation of the blob. More... | |
uint8_t | GetBytes (uint8_t *buffer, uint32_t size) |
Get the bytes representation of the blob. More... | |
void | InsertPaddingAtEnd (bool padAtEnd) |
Toggles the padding insertion policy. More... | |
void | PushBits (uint64_t value, uint8_t significantBits) |
Pushes a number of bits in the blob. More... | |
Private Member Functions | |
void | PadAtEnd () |
Add the padding at the end of the blob. More... | |
void | PadAtStart () |
Add the padding at the start of the blob. More... | |
Private Attributes | |
std::vector< bool > | m_blob |
Blob of serialized bits. More... | |
bool | m_padAtEnd |
True if the padding must be added at the end of the blob. More... | |
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 59 of file bit-serializer.h.
ns3::BitSerializer::BitSerializer | ( | ) |
Definition at line 33 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 87 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 111 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 40 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 57 of file bit-serializer.cc.
References m_blob.
Referenced by GetBytes().
|
private |
Add the padding at the start of the blob.
Definition at line 47 of file bit-serializer.cc.
References m_blob, and NS_LOG_FUNCTION.
Referenced by 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 65 of file bit-serializer.cc.
References m_blob, and NS_LOG_FUNCTION.
Referenced by BitSerializerTest::DoRun().
|
private |
Blob of serialized bits.
Definition at line 112 of file bit-serializer.h.
Referenced by GetBytes(), PadAtEnd(), PadAtStart(), and PushBits().
|
private |
True if the padding must be added at the end of the blob.
Definition at line 113 of file bit-serializer.h.
Referenced by BitSerializer(), GetBytes(), and InsertPaddingAtEnd().