 Chromium Code Reviews
 Chromium Code Reviews Issue 2551153003:
  Add static domain security state generator tool.  (Closed)
    
  
    Issue 2551153003:
  Add static domain security state generator tool.  (Closed) 
  | OLD | NEW | 
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_BIT_WRITER_H_ | |
| 6 #define NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_BIT_WRITER_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <vector> | |
| 11 | |
| 12 namespace net { | |
| 13 | |
| 14 // BitWriter acts as a buffer to which bits can be written. The bits are stored | |
| 15 // as bytes in a vector. BitWriter will buffer bytes. When the buffer contains | |
| 16 // 8 bits they will be appended to the vector automaticly. | |
| 
agl
2016/12/06 18:51:34
typo.
 
martijnc
2016/12/07 22:37:53
Fixed.
 | |
| 17 class BitWriter { | |
| 18 public: | |
| 19 BitWriter(); | |
| 20 ~BitWriter(); | |
| 21 | |
| 22 // Append |bit| to the end of the buffer. | |
| 23 void WriteBit(uint8_t bit); | |
| 24 | |
| 25 // Append the last |number_of_bits| of |bits| to the end of the buffer. | |
| 
agl
2016/12/06 18:51:34
does "last" mean "least-significant"?
 
martijnc
2016/12/07 22:37:53
Yes, clarified in the comment.
 | |
| 26 void WriteBits(uint32_t bits, uint8_t number_of_bits); | |
| 27 | |
| 28 // Appends the buffered bits in |current_byte_| to the |bytes_| vector. When | |
| 29 // there are less than 8 bits in the buffer, the empty bits will be filled | |
| 30 // with zero's. | |
| 31 void Close(); | |
| 
agl
2016/12/06 18:51:34
I think Close would be better named Flush, since i
 
martijnc
2016/12/07 22:37:53
Renamed.
 | |
| 32 uint32_t position() const { return position_; } | |
| 33 | |
| 34 // Returns a reference to the |bytes_| buffer of this writer. Make sure to | |
| 35 // call Close() so that the buffered bits are written to |bytes_| as well. | |
| 36 const std::vector<uint8_t>& bytes() const { return bytes_; } | |
| 37 | |
| 38 private: | |
| 39 // Returns the minimum number of bits needed to represent |input|. | |
| 40 uint8_t BitLength(uint32_t input) const; | |
| 41 | |
| 42 // Buffers bits until it can fill a byte. | |
| 43 uint8_t current_byte_; | |
| 44 | |
| 45 // The number of bits currently in |current_byte_|. | |
| 46 uint8_t used_; | |
| 
agl
2016/12/06 18:51:34
I think we're allowed to say " = 0" in class decla
 
martijnc
2016/12/07 22:37:53
Done.
 | |
| 47 | |
| 48 // Number of bits in written to this BitWriter. | |
| 49 int32_t position_; | |
| 
agl
2016/12/06 18:51:34
uint32_t (or size_t) to match the return type of |
 
martijnc
2016/12/07 22:37:53
Done.
 | |
| 50 | |
| 51 std::vector<uint8_t> bytes_; | |
| 52 }; | |
| 53 | |
| 54 } // namespace net | |
| 55 | |
| 56 #endif // NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_BIT_WRITER_H_ | |
| OLD | NEW |