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 #ifndef NET_QUIC_CORE_QUIC_DATA_READER_H_ | 5 #ifndef NET_QUIC_CORE_QUIC_DATA_READER_H_ |
6 #define NET_QUIC_CORE_QUIC_DATA_READER_H_ | 6 #define NET_QUIC_CORE_QUIC_DATA_READER_H_ |
7 | 7 |
8 #include <cstddef> | 8 #include <cstddef> |
9 #include <cstdint> | 9 #include <cstdint> |
10 | 10 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // Returns true on success, false otherwise. | 111 // Returns true on success, false otherwise. |
112 bool ReadBytes(void* result, size_t size); | 112 bool ReadBytes(void* result, size_t size); |
113 | 113 |
114 // Returns true if the entirety of the underlying buffer has been read via | 114 // Returns true if the entirety of the underlying buffer has been read via |
115 // Read*() calls. | 115 // Read*() calls. |
116 bool IsDoneReading() const; | 116 bool IsDoneReading() const; |
117 | 117 |
118 // Returns the number of bytes remaining to be read. | 118 // Returns the number of bytes remaining to be read. |
119 size_t BytesRemaining() const; | 119 size_t BytesRemaining() const; |
120 | 120 |
| 121 // Returns the next byte that to be read. Must not be called when there are no |
| 122 // bytes to be read. |
| 123 // |
| 124 // DOES NOT forward the internal iterator. |
| 125 uint8_t PeekByte() const; |
| 126 |
121 private: | 127 private: |
122 // Returns true if the underlying buffer has enough room to read the given | 128 // Returns true if the underlying buffer has enough room to read the given |
123 // amount of bytes. | 129 // amount of bytes. |
124 bool CanRead(size_t bytes) const; | 130 bool CanRead(size_t bytes) const; |
125 | 131 |
126 // To be called when a read fails for any reason. | 132 // To be called when a read fails for any reason. |
127 void OnFailure(); | 133 void OnFailure(); |
128 | 134 |
129 // The data buffer that we're reading from. | 135 // The data buffer that we're reading from. |
130 const char* data_; | 136 const char* data_; |
131 | 137 |
132 // The length of the data buffer that we're reading from. | 138 // The length of the data buffer that we're reading from. |
133 const size_t len_; | 139 const size_t len_; |
134 | 140 |
135 // The location of the next read from our data buffer. | 141 // The location of the next read from our data buffer. |
136 size_t pos_; | 142 size_t pos_; |
137 | 143 |
138 // Perspective of this data reader. Please note, although client and server | 144 // Perspective of this data reader. Please note, although client and server |
139 // may have different in-memory representation of the same field, the on wire | 145 // may have different in-memory representation of the same field, the on wire |
140 // representation must be consistent. | 146 // representation must be consistent. |
141 Perspective perspective_; | 147 Perspective perspective_; |
142 | 148 |
143 DISALLOW_COPY_AND_ASSIGN(QuicDataReader); | 149 DISALLOW_COPY_AND_ASSIGN(QuicDataReader); |
144 }; | 150 }; |
145 | 151 |
146 } // namespace net | 152 } // namespace net |
147 | 153 |
148 #endif // NET_QUIC_CORE_QUIC_DATA_READER_H_ | 154 #endif // NET_QUIC_CORE_QUIC_DATA_READER_H_ |
OLD | NEW |