| 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_input_stream.h" | 5 #include "net/spdy/hpack_input_stream.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 | 11 |
| 12 namespace net { | 12 namespace net { |
| 13 | 13 |
| 14 using base::StringPiece; | 14 using base::StringPiece; |
| 15 using std::string; | 15 using std::string; |
| 16 | 16 |
| 17 HpackInputStream::HpackInputStream(uint32 max_string_literal_size, | 17 HpackInputStream::HpackInputStream(uint32 max_string_literal_size, |
| 18 StringPiece buffer) | 18 StringPiece buffer) |
| 19 : max_string_literal_size_(max_string_literal_size), | 19 : max_string_literal_size_(max_string_literal_size), |
| 20 buffer_(buffer), | 20 buffer_(buffer), |
| 21 bit_offset_(0) {} | 21 bit_offset_(0) { |
| 22 } |
| 22 | 23 |
| 23 HpackInputStream::~HpackInputStream() {} | 24 HpackInputStream::~HpackInputStream() { |
| 25 } |
| 24 | 26 |
| 25 bool HpackInputStream::HasMoreData() const { | 27 bool HpackInputStream::HasMoreData() const { |
| 26 return !buffer_.empty(); | 28 return !buffer_.empty(); |
| 27 } | 29 } |
| 28 | 30 |
| 29 bool HpackInputStream::MatchPrefixAndConsume(HpackPrefix prefix) { | 31 bool HpackInputStream::MatchPrefixAndConsume(HpackPrefix prefix) { |
| 30 DCHECK_GT(prefix.bit_size, 0u); | 32 DCHECK_GT(prefix.bit_size, 0u); |
| 31 DCHECK_LE(prefix.bit_size, 8u); | 33 DCHECK_LE(prefix.bit_size, 8u); |
| 32 | 34 |
| 33 uint8 next_octet = 0; | 35 uint8 next_octet = 0; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 113 |
| 112 bool HpackInputStream::DecodeNextHuffmanString(const HpackHuffmanTable& table, | 114 bool HpackInputStream::DecodeNextHuffmanString(const HpackHuffmanTable& table, |
| 113 string* str) { | 115 string* str) { |
| 114 uint32 encoded_size = 0; | 116 uint32 encoded_size = 0; |
| 115 if (!DecodeNextUint32(&encoded_size)) | 117 if (!DecodeNextUint32(&encoded_size)) |
| 116 return false; | 118 return false; |
| 117 | 119 |
| 118 if (encoded_size > buffer_.size()) | 120 if (encoded_size > buffer_.size()) |
| 119 return false; | 121 return false; |
| 120 | 122 |
| 121 HpackInputStream bounded_reader( | 123 HpackInputStream bounded_reader(max_string_literal_size_, |
| 122 max_string_literal_size_, | 124 StringPiece(buffer_.data(), encoded_size)); |
| 123 StringPiece(buffer_.data(), encoded_size)); | |
| 124 buffer_.remove_prefix(encoded_size); | 125 buffer_.remove_prefix(encoded_size); |
| 125 | 126 |
| 126 // HpackHuffmanTable will not decode beyond |max_string_literal_size_|. | 127 // HpackHuffmanTable will not decode beyond |max_string_literal_size_|. |
| 127 return table.DecodeString(&bounded_reader, max_string_literal_size_, str); | 128 return table.DecodeString(&bounded_reader, max_string_literal_size_, str); |
| 128 } | 129 } |
| 129 | 130 |
| 130 bool HpackInputStream::PeekBits(size_t* peeked_count, uint32* out) { | 131 bool HpackInputStream::PeekBits(size_t* peeked_count, uint32* out) { |
| 131 size_t byte_offset = (bit_offset_ + *peeked_count) / 8; | 132 size_t byte_offset = (bit_offset_ + *peeked_count) / 8; |
| 132 size_t bit_offset = (bit_offset_ + *peeked_count) % 8; | 133 size_t bit_offset = (bit_offset_ + *peeked_count) % 8; |
| 133 | 134 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 162 buffer_.remove_prefix(byte_count); | 163 buffer_.remove_prefix(byte_count); |
| 163 } | 164 } |
| 164 | 165 |
| 165 void HpackInputStream::ConsumeByteRemainder() { | 166 void HpackInputStream::ConsumeByteRemainder() { |
| 166 if (bit_offset_ != 0) { | 167 if (bit_offset_ != 0) { |
| 167 ConsumeBits(8 - bit_offset_); | 168 ConsumeBits(8 - bit_offset_); |
| 168 } | 169 } |
| 169 } | 170 } |
| 170 | 171 |
| 171 } // namespace net | 172 } // namespace net |
| OLD | NEW |