OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #include "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/numerics/safe_math.h" | 6 #include "base/numerics/safe_math.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "components/safe_browsing_db/v4_rice.h" | 8 #include "components/safe_browsing_db/v4_rice.h" |
9 | 9 |
10 using ::google::protobuf::RepeatedField; | 10 using ::google::protobuf::RepeatedField; |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 } | 256 } |
257 | 257 |
258 void V4RiceDecoder::GetBitsFromCurrentWord(unsigned int num_requested_bits, | 258 void V4RiceDecoder::GetBitsFromCurrentWord(unsigned int num_requested_bits, |
259 uint32_t* x) { | 259 uint32_t* x) { |
260 uint32_t mask = 0xFFFFFFFF >> (kMaxBitIndex - num_requested_bits); | 260 uint32_t mask = 0xFFFFFFFF >> (kMaxBitIndex - num_requested_bits); |
261 *x = current_word_ & mask; | 261 *x = current_word_ & mask; |
262 current_word_ = current_word_ >> num_requested_bits; | 262 current_word_ = current_word_ >> num_requested_bits; |
263 current_word_bit_index_ += num_requested_bits; | 263 current_word_bit_index_ += num_requested_bits; |
264 }; | 264 }; |
265 | 265 |
266 std::string V4RiceDecoder::DebugString() const { | 266 std::string V4RiceDecoder::DebugString() const { |
Nathan Parker
2016/08/08 21:17:19
Are there constants describing what 4 and 8 are?
vakh (use Gerrit instead)
2016/08/08 22:46:47
Now using constants and added a comment describing
| |
267 unsigned bits_read = (data_byte_index_ - 4) * 8 + current_word_bit_index_; | |
267 return base::StringPrintf( | 268 return base::StringPrintf( |
268 "current_word_: %x; data_byte_index_; %x, " | 269 "bits_read: %x; current_word_: %x; data_byte_index_; %x, " |
269 "current_word_bit_index_: %x; rice_parameter_: %x", | 270 "current_word_bit_index_: %x; rice_parameter_: %x", |
270 current_word_, data_byte_index_, current_word_bit_index_, | 271 bits_read, current_word_, data_byte_index_, current_word_bit_index_, |
271 rice_parameter_); | 272 rice_parameter_); |
272 } | 273 } |
273 | 274 |
274 std::ostream& operator<<(std::ostream& os, const V4RiceDecoder& rice_decoder) { | 275 std::ostream& operator<<(std::ostream& os, const V4RiceDecoder& rice_decoder) { |
275 os << rice_decoder.DebugString(); | 276 os << rice_decoder.DebugString(); |
276 return os; | 277 return os; |
277 } | 278 } |
278 | 279 |
279 } // namespace safe_browsing | 280 } // namespace safe_browsing |
OLD | NEW |