A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
bit-deserializer.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Universita' di Firenze, Italy
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
7 */
8
9#ifndef BITDESERIALIZER_H_
10#define BITDESERIALIZER_H_
11
12#include <cstdint>
13#include <deque>
14#include <vector>
15
16namespace ns3
17{
18
19/**
20 * \ingroup packet
21 *
22 * \brief Bit deserializer. See also \sa ns3::BitSerializer
23 *
24 * This class helps converting a variable number, variable sized
25 * number of bit-boundary fields stored as byte array representation
26 * and extract the original bit-fields.
27 *
28 * Note that once the Deserialization starts, it's not anymore
29 * possible to add more data to the byte blob to deserialize.
30 */
31
33{
34 public:
36
37 /**
38 * Pushes some bytes into the blob to be deserialized.
39 * \param bytes The bytes to add.
40 */
41 void PushBytes(std::vector<uint8_t> bytes);
42
43 /**
44 * Pushes some bytes into the blob to be deserialized.
45 * \param bytes The bytes to add.
46 * \param size The length of the array.
47 */
48 void PushBytes(uint8_t* bytes, uint32_t size);
49
50 /**
51 * Pushes one byte into the blob to be deserialized.
52 * \param byte The byte to add.
53 */
54 void PushByte(uint8_t byte);
55
56 /**
57 * Pops a given number of bits from the blob front. In other terms,
58 * 'size' bits are shifted from the contents of the byte blob
59 * onto the return value.
60 *
61 * The maximum number of bits to be deserialized in one single call is 64.
62 *
63 * \param size The number of bits to pop.
64 * \return The popped bits value
65 */
66 uint64_t GetBits(uint8_t size);
67
68 private:
69 /**
70 * Prepare the byte array to the deserialization.
71 */
73
74 std::deque<bool> m_blob; //!< Blob of bits ready to be deserialized.
75 std::vector<uint8_t> m_bytesBlob; //!< Blob of bytes to be deserialized.
76 bool m_deserializing; //!< True if the deserialization did start already.
77};
78
79} // namespace ns3
80
81#endif /* BITDESERIALIZER_H_ */
Bit deserializer.
void PushBytes(std::vector< uint8_t > bytes)
Pushes some bytes into the blob to be deserialized.
std::vector< uint8_t > m_bytesBlob
Blob of bytes to be deserialized.
void PrepareDeserialization()
Prepare the byte array to the deserialization.
void PushByte(uint8_t byte)
Pushes one byte into the blob to be deserialized.
bool m_deserializing
True if the deserialization did start already.
std::deque< bool > m_blob
Blob of bits ready to be deserialized.
uint64_t GetBits(uint8_t size)
Pops a given number of bits from the blob front.
Every class exported by the ns3 library is enclosed in the ns3 namespace.