A Discrete-Event Network Simulator
API
bit-serializer.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2020 Universita' di Firenze, Italy
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
19  */
20 
21 #ifndef BITSERIALIZER_H_
22 #define BITSERIALIZER_H_
23 
24 #include <vector>
25 
26 namespace ns3 {
27 
59 {
60 public:
61  BitSerializer ();
62 
67  void InsertPaddingAtEnd (bool padAtEnd);
68 
74  void PushBits (uint64_t value, uint8_t significantBits);
75 
85  std::vector<uint8_t> GetBytes ();
86 
98  uint8_t GetBytes (uint8_t *buffer, uint32_t size);
99 
100 private:
104  void PadAtStart ();
105 
109  void PadAtEnd ();
110 
111  std::vector<bool> m_blob;
112  bool m_padAtEnd;
113 };
114 
115 } // namespace ns3
116 
117 #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.