| 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 #include "net/tools/domain_security_preload_generator/bit_writer.h" | 
|  | 6 | 
|  | 7 #include "base/logging.h" | 
|  | 8 | 
|  | 9 namespace net { | 
|  | 10 | 
|  | 11 namespace transport_security_state { | 
|  | 12 | 
|  | 13 BitWriter::BitWriter() {} | 
|  | 14 | 
|  | 15 BitWriter::~BitWriter() {} | 
|  | 16 | 
|  | 17 void BitWriter::WriteBits(uint32_t bits, uint8_t number_of_bits) { | 
|  | 18   DCHECK(number_of_bits <= 32); | 
|  | 19   for (uint8_t i = 1; i <= number_of_bits; i++) { | 
|  | 20     uint8_t bit = 1 & (bits >> (number_of_bits - i)); | 
|  | 21     WriteBit(bit); | 
|  | 22   } | 
|  | 23 } | 
|  | 24 | 
|  | 25 void BitWriter::WriteBit(uint8_t bit) { | 
|  | 26   current_byte_ |= bit << (7 - used_); | 
|  | 27   used_++; | 
|  | 28   position_++; | 
|  | 29 | 
|  | 30   if (used_ == 8) { | 
|  | 31     Flush(); | 
|  | 32   } | 
|  | 33 } | 
|  | 34 | 
|  | 35 void BitWriter::Flush() { | 
|  | 36   bytes_.push_back(current_byte_); | 
|  | 37 | 
|  | 38   used_ = 0; | 
|  | 39   current_byte_ = 0; | 
|  | 40 } | 
|  | 41 | 
|  | 42 uint8_t BitWriter::BitLength(uint32_t input) const { | 
|  | 43   uint8_t number_of_bits = 0; | 
|  | 44   while (input != 0) { | 
|  | 45     number_of_bits++; | 
|  | 46     input >>= 1; | 
|  | 47   } | 
|  | 48   return number_of_bits; | 
|  | 49 } | 
|  | 50 | 
|  | 51 }  // namespace transport_security_state | 
|  | 52 | 
|  | 53 }  // namespace net | 
| OLD | NEW | 
|---|