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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
18 */
19
20#ifndef BITDESERIALIZER_H_
21#define BITDESERIALIZER_H_
22
23#include <cstdint>
24#include <deque>
25#include <vector>
26
27namespace ns3
28{
29
30/**
31 * \ingroup packet
32 *
33 * \brief Bit deserializer. See also \sa ns3::BitSerializer
34 *
35 * This class helps converting a variable number, variable sized
36 * number of bit-boundary fields stored as byte array representation
37 * and extract the original bit-fields.
38 *
39 * Note that once the Deserialization starts, it's not anymore
40 * possible to add more data to the byte blob to deserialize.
41 */
42
44{
45 public:
47
48 /**
49 * Pushes some bytes into the blob to be deserialized.
50 * \param bytes The bytes to add.
51 */
52 void PushBytes(std::vector<uint8_t> bytes);
53
54 /**
55 * Pushes some bytes into the blob to be deserialized.
56 * \param bytes The bytes to add.
57 * \param size The length of the array.
58 */
59 void PushBytes(uint8_t* bytes, uint32_t size);
60
61 /**
62 * Pushes one byte into the blob to be deserialized.
63 * \param byte The byte to add.
64 */
65 void PushByte(uint8_t byte);
66
67 /**
68 * Pops a given number of bits from the blob front. In other terms,
69 * 'size' bits are shifted from the contents of the byte blob
70 * onto the return value.
71 *
72 * The maximum number of bits to be deserialized in one single call is 64.
73 *
74 * \param size The number of bits to pop.
75 * \return The popped bits value
76 */
77 uint64_t GetBits(uint8_t size);
78
79 private:
80 /**
81 * Prepare the byte array to the deserialization.
82 */
84
85 std::deque<bool> m_blob; //!< Blob of bits ready to be deserialized.
86 std::vector<uint8_t> m_bytesBlob; //!< Blob of bytes to be deserialized.
87 bool m_deserializing; //!< True if the deserialization did start already.
88};
89
90} // namespace ns3
91
92#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.