OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/http2/decoder/decode_buffer.h" |
| 6 |
| 7 namespace net { |
| 8 |
| 9 bool DecodeBuffer::SlowDecodeUnsignedInt(uint32_t field_size, |
| 10 uint32_t field_offset, |
| 11 uint32_t* decode_offset, |
| 12 uint32_t* value) { |
| 13 DCHECK_LT(0u, field_size); |
| 14 DCHECK_LE(field_size, 4u); |
| 15 DCHECK(decode_offset != nullptr); |
| 16 DCHECK_LE(field_offset, *decode_offset); |
| 17 const uint32_t next_field_offset = field_offset + field_size; |
| 18 if (*decode_offset == field_offset) { |
| 19 // Starting to decode field. It is possible we will reach this point |
| 20 // twice, once when we've just exhausted the input, and once when |
| 21 // resuming decoding with a new input buffer. |
| 22 // Clear the field; we do NOT assume that the caller has done so |
| 23 // previously. |
| 24 *value = 0; |
| 25 } else if (*decode_offset >= next_field_offset) { |
| 26 // We already decoded this field. |
| 27 return true; |
| 28 } |
| 29 do { |
| 30 if (Empty()) { |
| 31 return false; // Not done decoding. |
| 32 } |
| 33 *value = *value << 8 | DecodeUInt8(); |
| 34 (*decode_offset)++; |
| 35 } while (*decode_offset < next_field_offset); |
| 36 return true; |
| 37 } |
| 38 |
| 39 bool DecodeBuffer::SlowDecodeUInt8(uint32_t field_offset, |
| 40 uint32_t* decode_offset, |
| 41 uint8_t* value) { |
| 42 uint32_t tmp = *value; |
| 43 const bool done = SlowDecodeUnsignedInt(1 /* field_size */, field_offset, |
| 44 decode_offset, &tmp); |
| 45 *value = tmp & 0xff; |
| 46 DCHECK_EQ(tmp, *value); |
| 47 return done; |
| 48 } |
| 49 |
| 50 bool DecodeBuffer::SlowDecodeUInt16(uint32_t field_offset, |
| 51 uint32_t* decode_offset, |
| 52 uint16_t* value) { |
| 53 uint32_t tmp = *value; |
| 54 const bool done = SlowDecodeUnsignedInt(2 /* field_size */, field_offset, |
| 55 decode_offset, &tmp); |
| 56 *value = tmp & 0xffff; |
| 57 DCHECK_EQ(tmp, *value); |
| 58 return done; |
| 59 } |
| 60 |
| 61 bool DecodeBuffer::SlowDecodeUInt24(uint32_t field_offset, |
| 62 uint32_t* decode_offset, |
| 63 uint32_t* value) { |
| 64 uint32_t tmp = *value; |
| 65 const bool done = SlowDecodeUnsignedInt(3 /* field_size */, field_offset, |
| 66 decode_offset, &tmp); |
| 67 *value = tmp & 0xffffff; |
| 68 DCHECK_EQ(tmp, *value); |
| 69 return done; |
| 70 } |
| 71 |
| 72 bool DecodeBuffer::SlowDecodeUInt31(uint32_t field_offset, |
| 73 uint32_t* decode_offset, |
| 74 uint32_t* value) { |
| 75 uint32_t tmp = *value; |
| 76 const bool done = SlowDecodeUnsignedInt(4 /* field_size */, field_offset, |
| 77 decode_offset, &tmp); |
| 78 *value = tmp & 0x7fffffff; |
| 79 DCHECK_EQ(tmp & 0x7fffffff, *value); |
| 80 return done; |
| 81 } |
| 82 |
| 83 bool DecodeBuffer::SlowDecodeUInt32(uint32_t field_offset, |
| 84 uint32_t* decode_offset, |
| 85 uint32_t* value) { |
| 86 return SlowDecodeUnsignedInt(4 /* field_size */, field_offset, decode_offset, |
| 87 value); |
| 88 } |
| 89 |
| 90 } // namespace net |
OLD | NEW |