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 "net/quic/core/quic_data_reader.h" | 5 #include "net/quic/core/quic_data_reader.h" |
6 | 6 |
7 #include "net/base/int128.h" | 7 #include "net/base/int128.h" |
| 8 #include "net/quic/core/quic_flags.h" |
8 #include "net/quic/core/quic_packets.h" | 9 #include "net/quic/core/quic_packets.h" |
| 10 #include "net/quic/platform/api/quic_endian.h" |
9 | 11 |
10 namespace net { | 12 namespace net { |
11 | 13 |
12 QuicDataReader::QuicDataReader(const char* data, const size_t len) | 14 QuicDataReader::QuicDataReader(const char* data, const size_t len) |
13 : data_(data), len_(len), pos_(0) {} | 15 : data_(data), len_(len), pos_(0) {} |
14 | 16 |
15 bool QuicDataReader::ReadUInt16(uint16_t* result) { | 17 bool QuicDataReader::ReadUInt16(uint16_t* result) { |
16 return ReadBytes(result, sizeof(*result)); | 18 return ReadBytes(result, sizeof(*result)); |
17 } | 19 } |
18 | 20 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 79 |
78 // Set result. | 80 // Set result. |
79 *result = QuicStringPiece(data_ + pos_, size); | 81 *result = QuicStringPiece(data_ + pos_, size); |
80 | 82 |
81 // Iterate. | 83 // Iterate. |
82 pos_ += size; | 84 pos_ += size; |
83 | 85 |
84 return true; | 86 return true; |
85 } | 87 } |
86 | 88 |
| 89 bool QuicDataReader::ReadConnectionId(uint64_t* connection_id) { |
| 90 if (!ReadUInt64(connection_id)) { |
| 91 return false; |
| 92 } |
| 93 |
| 94 if (FLAGS_quic_restart_flag_quic_big_endian_connection_id) { |
| 95 *connection_id = QuicEndian::NetToHost64(*connection_id); |
| 96 } |
| 97 |
| 98 return true; |
| 99 } |
| 100 |
87 QuicStringPiece QuicDataReader::ReadRemainingPayload() { | 101 QuicStringPiece QuicDataReader::ReadRemainingPayload() { |
88 QuicStringPiece payload = PeekRemainingPayload(); | 102 QuicStringPiece payload = PeekRemainingPayload(); |
89 pos_ = len_; | 103 pos_ = len_; |
90 return payload; | 104 return payload; |
91 } | 105 } |
92 | 106 |
93 QuicStringPiece QuicDataReader::PeekRemainingPayload() { | 107 QuicStringPiece QuicDataReader::PeekRemainingPayload() { |
94 return QuicStringPiece(data_ + pos_, len_ - pos_); | 108 return QuicStringPiece(data_ + pos_, len_ - pos_); |
95 } | 109 } |
96 | 110 |
(...skipping 25 matching lines...) Expand all Loading... |
122 return bytes <= (len_ - pos_); | 136 return bytes <= (len_ - pos_); |
123 } | 137 } |
124 | 138 |
125 void QuicDataReader::OnFailure() { | 139 void QuicDataReader::OnFailure() { |
126 // Set our iterator to the end of the buffer so that further reads fail | 140 // Set our iterator to the end of the buffer so that further reads fail |
127 // immediately. | 141 // immediately. |
128 pos_ = len_; | 142 pos_ = len_; |
129 } | 143 } |
130 | 144 |
131 } // namespace net | 145 } // namespace net |
OLD | NEW |