| Index: net/tools/domain_security_preload_generator/bit_writer.h
|
| diff --git a/net/tools/domain_security_preload_generator/bit_writer.h b/net/tools/domain_security_preload_generator/bit_writer.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..55fee37a72fce7d1f57091bac2833f1422fcff7a
|
| --- /dev/null
|
| +++ b/net/tools/domain_security_preload_generator/bit_writer.h
|
| @@ -0,0 +1,56 @@
|
| +// Copyright (c) 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_BIT_WRITER_H_
|
| +#define NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_BIT_WRITER_H_
|
| +
|
| +#include <stdint.h>
|
| +
|
| +#include <vector>
|
| +
|
| +namespace net {
|
| +
|
| +// BitWriter acts as a buffer to which bits can be written. The bits are stored
|
| +// as bytes in a vector. BitWriter will buffer bytes. When the buffer contains
|
| +// 8 bits they will be appended to the vector automaticly.
|
| +class BitWriter {
|
| + public:
|
| + BitWriter();
|
| + ~BitWriter();
|
| +
|
| + // Append |bit| to the end of the buffer.
|
| + void WriteBit(uint8_t bit);
|
| +
|
| + // Append the last |number_of_bits| of |bits| to the end of the buffer.
|
| + void WriteBits(uint32_t bits, uint8_t number_of_bits);
|
| +
|
| + // Appends the buffered bits in |current_byte_| to the |bytes_| vector. When
|
| + // there are less than 8 bits in the buffer, the empty bits will be filled
|
| + // with zero's.
|
| + void Close();
|
| + uint32_t position() const { return position_; }
|
| +
|
| + // Returns a reference to the |bytes_| buffer of this writer. Make sure to
|
| + // call Close() so that the buffered bits are written to |bytes_| as well.
|
| + const std::vector<uint8_t>& bytes() const { return bytes_; }
|
| +
|
| + private:
|
| + // Returns the minimum number of bits needed to represent |input|.
|
| + uint8_t BitLength(uint32_t input) const;
|
| +
|
| + // Buffers bits until it can fill a byte.
|
| + uint8_t current_byte_;
|
| +
|
| + // The number of bits currently in |current_byte_|.
|
| + uint8_t used_;
|
| +
|
| + // Number of bits in written to this BitWriter.
|
| + int32_t position_;
|
| +
|
| + std::vector<uint8_t> bytes_;
|
| +};
|
| +
|
| +} // namespace net
|
| +
|
| +#endif // NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_BIT_WRITER_H_
|
|
|