OLD | NEW |
---|---|
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_BIT_WRITER_H_ | 5 #ifndef NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_BIT_WRITER_H_ |
6 #define NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_BIT_WRITER_H_ | 6 #define NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_BIT_WRITER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | |
13 | |
12 namespace net { | 14 namespace net { |
13 | 15 |
14 namespace transport_security_state { | 16 namespace transport_security_state { |
15 | 17 |
16 // BitWriter acts as a buffer to which bits can be written. The bits are stored | 18 // BitWriter acts as a buffer to which bits can be written. The bits are stored |
17 // as bytes in a vector. BitWriter will buffer bits until it contains 8 bits at | 19 // as bytes in a vector. BitWriter will buffer bits until it contains 8 bits at |
18 // which point they will be appended to the vector automatically. | 20 // which point they will be appended to the vector automatically. |
19 class BitWriter { | 21 class BitWriter { |
20 public: | 22 public: |
21 BitWriter(); | 23 BitWriter(); |
(...skipping 10 matching lines...) Expand all Loading... | |
32 // there are less than 8 bits in the buffer, the empty bits will be filled | 34 // there are less than 8 bits in the buffer, the empty bits will be filled |
33 // with zero's. | 35 // with zero's. |
34 void Flush(); | 36 void Flush(); |
35 uint32_t position() const { return position_; } | 37 uint32_t position() const { return position_; } |
36 | 38 |
37 // Returns a reference to |bytes_|. Make sure to call Flush() first so that | 39 // Returns a reference to |bytes_|. Make sure to call Flush() first so that |
38 // the buffered bits are written to |bytes_| as well. | 40 // the buffered bits are written to |bytes_| as well. |
39 const std::vector<uint8_t>& bytes() const { return bytes_; } | 41 const std::vector<uint8_t>& bytes() const { return bytes_; } |
40 | 42 |
41 private: | 43 private: |
42 // Returns the minimum number of bits needed to represent |input|. | |
martijnc
2017/02/08 20:58:21
This wasn't used.
| |
43 uint8_t BitLength(uint32_t input) const; | |
44 | |
45 // Buffers bits until they fill a whole byte. | 44 // Buffers bits until they fill a whole byte. |
46 uint8_t current_byte_ = 0; | 45 uint8_t current_byte_ = 0; |
47 | 46 |
48 // The number of bits currently in |current_byte_|. | 47 // The number of bits currently in |current_byte_|. |
49 uint8_t used_ = 0; | 48 uint8_t used_ = 0; |
50 | 49 |
51 // Total number of bits written to this BitWriter. | 50 // Total number of bits written to this BitWriter. |
52 uint32_t position_ = 0; | 51 uint32_t position_ = 0; |
53 | 52 |
54 std::vector<uint8_t> bytes_; | 53 std::vector<uint8_t> bytes_; |
54 | |
55 DISALLOW_COPY_AND_ASSIGN(BitWriter); | |
55 }; | 56 }; |
56 | 57 |
57 } // namespace transport_security_state | 58 } // namespace transport_security_state |
58 | 59 |
59 } // namespace net | 60 } // namespace net |
60 | 61 |
61 #endif // NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_BIT_WRITER_H_ | 62 #endif // NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_BIT_WRITER_H_ |
OLD | NEW |