| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "net/spdy/hpack_huffman_table.h" | 5 #include "net/spdy/hpack_huffman_table.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 length = 8; | 241 length = 8; |
| 242 } | 242 } |
| 243 out->AppendBits(static_cast<uint8>(code), length); | 243 out->AppendBits(static_cast<uint8>(code), length); |
| 244 } | 244 } |
| 245 if (bit_remnant != 0) { | 245 if (bit_remnant != 0) { |
| 246 // Pad current byte as required. | 246 // Pad current byte as required. |
| 247 out->AppendBits(pad_bits_ >> bit_remnant, 8 - bit_remnant); | 247 out->AppendBits(pad_bits_ >> bit_remnant, 8 - bit_remnant); |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 | 250 |
| 251 size_t HpackHuffmanTable::EncodedSize(StringPiece in) const { |
| 252 size_t bit_count = 0; |
| 253 for (size_t i = 0; i != in.size(); i++) { |
| 254 uint16 symbol_id = static_cast<uint8>(in[i]); |
| 255 CHECK_GT(code_by_id_.size(), symbol_id); |
| 256 |
| 257 bit_count += length_by_id_[symbol_id]; |
| 258 } |
| 259 if (bit_count % 8 != 0) { |
| 260 bit_count += 8 - bit_count % 8; |
| 261 } |
| 262 return bit_count / 8; |
| 263 } |
| 264 |
| 251 bool HpackHuffmanTable::DecodeString(HpackInputStream* in, | 265 bool HpackHuffmanTable::DecodeString(HpackInputStream* in, |
| 252 size_t out_capacity, | 266 size_t out_capacity, |
| 253 string* out) const { | 267 string* out) const { |
| 254 // Number of decode iterations required for a 32-bit code. | 268 // Number of decode iterations required for a 32-bit code. |
| 255 const int kDecodeIterations = static_cast<int>( | 269 const int kDecodeIterations = static_cast<int>( |
| 256 std::ceil((32.f - kDecodeTableRootBits) / kDecodeTableBranchBits)); | 270 std::ceil((32.f - kDecodeTableRootBits) / kDecodeTableBranchBits)); |
| 257 | 271 |
| 258 out->clear(); | 272 out->clear(); |
| 259 | 273 |
| 260 // Current input, stored in the high |bits_available| bits of |bits|. | 274 // Current input, stored in the high |bits_available| bits of |bits|. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 bits = bits << entry.length; | 314 bits = bits << entry.length; |
| 301 bits_available -= entry.length; | 315 bits_available -= entry.length; |
| 302 } | 316 } |
| 303 peeked_success = in->PeekBits(&bits_available, &bits); | 317 peeked_success = in->PeekBits(&bits_available, &bits); |
| 304 } | 318 } |
| 305 NOTREACHED(); | 319 NOTREACHED(); |
| 306 return false; | 320 return false; |
| 307 } | 321 } |
| 308 | 322 |
| 309 } // namespace net | 323 } // namespace net |
| OLD | NEW |