A Discrete-Event Network Simulator
API
bit-serializer.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 BITSERIALIZER_H_
21 #define BITSERIALIZER_H_
22 
23 #include <cstdint>
24 #include <vector>
25 
26 namespace ns3
27 {
28 
60 {
61  public:
62  BitSerializer();
63 
68  void InsertPaddingAtEnd(bool padAtEnd);
69 
75  void PushBits(uint64_t value, uint8_t significantBits);
76 
86  std::vector<uint8_t> GetBytes();
87 
99  uint8_t GetBytes(uint8_t* buffer, uint32_t size);
100 
101  private:
105  void PadAtStart();
106 
110  void PadAtEnd();
111 
112  std::vector<bool> m_blob;
113  bool m_padAtEnd;
114 };
115 
116 } // namespace ns3
117 
118 #endif /* BITSERIALIZER_H_ */
Bit serializer.
bool m_padAtEnd
True if the padding must be added at the end of the blob.
void PushBits(uint64_t value, uint8_t significantBits)
Pushes a number of bits in the blob.
void PadAtStart()
Add the padding at the start of the blob.
std::vector< uint8_t > GetBytes()
Get the bytes representation of the blob.
std::vector< bool > m_blob
Blob of serialized bits.
void InsertPaddingAtEnd(bool padAtEnd)
Toggles the padding insertion policy.
void PadAtEnd()
Add the padding at the end of the blob.
Every class exported by the ns3 library is enclosed in the ns3 namespace.