OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <limits> | 5 #include <limits> |
6 | 6 |
7 #include "base/sys_byteorder.h" | 7 #include "base/sys_byteorder.h" |
8 #include "net/spdy/core/spdy_frame_reader.h" | 8 #include "net/spdy/core/spdy_frame_reader.h" |
9 #include "net/spdy/core/spdy_protocol.h" | 9 #include "net/spdy/core/spdy_protocol.h" |
10 | 10 |
11 namespace net { | 11 namespace net { |
12 | 12 |
13 SpdyFrameReader::SpdyFrameReader(const char* data, const size_t len) | 13 SpdyFrameReader::SpdyFrameReader(const char* data, const size_t len) |
14 : data_(data), | 14 : data_(data), len_(len), ofs_(0) {} |
15 len_(len), | |
16 ofs_(0) { | |
17 } | |
18 | 15 |
19 bool SpdyFrameReader::ReadUInt8(uint8_t* result) { | 16 bool SpdyFrameReader::ReadUInt8(uint8_t* result) { |
20 // Make sure that we have the whole uint8_t. | 17 // Make sure that we have the whole uint8_t. |
21 if (!CanRead(1)) { | 18 if (!CanRead(1)) { |
22 OnFailure(); | 19 OnFailure(); |
23 return false; | 20 return false; |
24 } | 21 } |
25 | 22 |
26 // Read into result. | 23 // Read into result. |
27 *result = *reinterpret_cast<const uint8_t*>(data_ + ofs_); | 24 *result = *reinterpret_cast<const uint8_t*>(data_ + ofs_); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 88 |
92 // Zero out highest-order bit. | 89 // Zero out highest-order bit. |
93 if (success) { | 90 if (success) { |
94 *result &= 0x7fffffff; | 91 *result &= 0x7fffffff; |
95 } | 92 } |
96 | 93 |
97 return success; | 94 return success; |
98 } | 95 } |
99 | 96 |
100 bool SpdyFrameReader::ReadUInt24(uint32_t* result) { | 97 bool SpdyFrameReader::ReadUInt24(uint32_t* result) { |
101 // Make sure that we have the whole uint24. | 98 // Make sure that we have the whole uint24_t. |
102 if (!CanRead(3)) { | 99 if (!CanRead(3)) { |
103 OnFailure(); | 100 OnFailure(); |
104 return false; | 101 return false; |
105 } | 102 } |
106 | 103 |
107 // Read into result. | 104 // Read into result. |
108 *result = 0; | 105 *result = 0; |
109 memcpy(reinterpret_cast<char*>(result) + 1, data_ + ofs_, 3); | 106 memcpy(reinterpret_cast<char*>(result) + 1, data_ + ofs_, 3); |
110 *result = base::NetToHost32(*result); | 107 *result = base::NetToHost32(*result); |
111 | 108 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 return bytes <= (len_ - ofs_); | 194 return bytes <= (len_ - ofs_); |
198 } | 195 } |
199 | 196 |
200 void SpdyFrameReader::OnFailure() { | 197 void SpdyFrameReader::OnFailure() { |
201 // Set our iterator to the end of the buffer so that further reads fail | 198 // Set our iterator to the end of the buffer so that further reads fail |
202 // immediately. | 199 // immediately. |
203 ofs_ = len_; | 200 ofs_ = len_; |
204 } | 201 } |
205 | 202 |
206 } // namespace net | 203 } // namespace net |
OLD | NEW |