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 // Decoder for strings encoded using the HPACK Huffman Code (see | 5 // Decoder for strings encoded using the HPACK Huffman Code (see |
6 // https://httpwg.github.io/specs/rfc7541.html#huffman.code). | 6 // https://httpwg.github.io/specs/rfc7541.html#huffman.code). |
7 // | 7 // |
8 // This implementation is inspired by the One-Shift algorithm described in | 8 // This implementation is inspired by the One-Shift algorithm described in |
9 // "On the Implementation of Minimum Redundancy Prefix Codes", by Alistair | 9 // "On the Implementation of Minimum Redundancy Prefix Codes", by Alistair |
10 // Moffat and Andrew Turpin, 1997. | 10 // Moffat and Andrew Turpin, 1997. |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 DCHECK_LT(canonical, 256u); | 296 DCHECK_LT(canonical, 256u); |
297 return static_cast<char>(kCanonicalToSymbol[canonical]); | 297 return static_cast<char>(kCanonicalToSymbol[canonical]); |
298 } | 298 } |
299 | 299 |
300 // TODO(jamessynge): Maybe further refactorings, including just passing in a | 300 // TODO(jamessynge): Maybe further refactorings, including just passing in a |
301 // SpdyStringPiece instead of an HpackInputStream, thus avoiding the PeekBits | 301 // SpdyStringPiece instead of an HpackInputStream, thus avoiding the PeekBits |
302 // calls, and also allowing us to separate the code into portions dealing with | 302 // calls, and also allowing us to separate the code into portions dealing with |
303 // long strings, and a later portion dealing with the last few bytes of strings. | 303 // long strings, and a later portion dealing with the last few bytes of strings. |
304 // TODO(jamessynge): Determine if that is worth it by adding some counters to | 304 // TODO(jamessynge): Determine if that is worth it by adding some counters to |
305 // measure the distribution of string sizes seen in practice. | 305 // measure the distribution of string sizes seen in practice. |
306 bool HpackHuffmanDecoder::DecodeString(HpackInputStream* in, std::string* out) { | 306 bool HpackHuffmanDecoder::DecodeString(HpackInputStream* in, SpdyString* out) { |
307 out->clear(); | 307 out->clear(); |
308 | 308 |
309 // Load |bits| with the leading bits of the input stream, left justified | 309 // Load |bits| with the leading bits of the input stream, left justified |
310 // (i.e. the bits of the first byte are the high-order bits of |bits|, | 310 // (i.e. the bits of the first byte are the high-order bits of |bits|, |
311 // and the bits of the fourth byte are the low-order bits of |bits|). | 311 // and the bits of the fourth byte are the low-order bits of |bits|). |
312 // |peeked_success| if there are more bits in |*in| (i.e. the encoding | 312 // |peeked_success| if there are more bits in |*in| (i.e. the encoding |
313 // of the string to be decoded is more than 4 bytes). | 313 // of the string to be decoded is more than 4 bytes). |
314 | 314 |
315 auto bits_available_and_bits = in->InitializePeekBits(); | 315 auto bits_available_and_bits = in->InitializePeekBits(); |
316 HuffmanCodeLength bits_available = bits_available_and_bits.first; | 316 HuffmanCodeLength bits_available = bits_available_and_bits.first; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 // Get some more bits for decoding (up to 8). |peeked_success| is true | 391 // Get some more bits for decoding (up to 8). |peeked_success| is true |
392 // if we got any bits. | 392 // if we got any bits. |
393 peeked_success = in->PeekBits(&bits_available, &bits); | 393 peeked_success = in->PeekBits(&bits_available, &bits); |
394 } | 394 } |
395 DLOG_IF(WARNING, (VLOG_IS_ON(2) && bits_available < 32 && !peeked_success)) | 395 DLOG_IF(WARNING, (VLOG_IS_ON(2) && bits_available < 32 && !peeked_success)) |
396 << "no more peeking possible"; | 396 << "no more peeking possible"; |
397 } | 397 } |
398 } | 398 } |
399 | 399 |
400 } // namespace net | 400 } // namespace net |
OLD | NEW |