Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(794)

Side by Side Diff: net/quic/core/quic_data_reader.h

Issue 2847753002: Some changes to prepare for endian change for QUIC: 1) Make data reader/write be able to read/write… (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "net/base/int128.h" 12 #include "net/base/int128.h"
13 #include "net/quic/core/quic_types.h" 13 #include "net/quic/core/quic_types.h"
14 #include "net/quic/platform/api/quic_endian.h"
14 #include "net/quic/platform/api/quic_export.h" 15 #include "net/quic/platform/api/quic_export.h"
15 #include "net/quic/platform/api/quic_string_piece.h" 16 #include "net/quic/platform/api/quic_string_piece.h"
16 17
17 namespace net { 18 namespace net {
18 19
19 // Used for reading QUIC data. Though there isn't really anything terribly 20 // Used for reading QUIC data. Though there isn't really anything terribly
20 // QUIC-specific here, it's a helper class that's useful when doing QUIC 21 // QUIC-specific here, it's a helper class that's useful when doing QUIC
21 // framing. 22 // framing.
22 // 23 //
23 // To use, simply construct a QuicDataReader using the underlying buffer that 24 // To use, simply construct a QuicDataReader using the underlying buffer that
24 // you'd like to read fields from, then call one of the Read*() methods to 25 // you'd like to read fields from, then call one of the Read*() methods to
25 // actually do some reading. 26 // actually do some reading.
26 // 27 //
27 // This class keeps an internal iterator to keep track of what's already been 28 // This class keeps an internal iterator to keep track of what's already been
28 // read and each successive Read*() call automatically increments said iterator 29 // read and each successive Read*() call automatically increments said iterator
29 // on success. On failure, internal state of the QuicDataReader should not be 30 // on success. On failure, internal state of the QuicDataReader should not be
30 // trusted and it is up to the caller to throw away the failed instance and 31 // trusted and it is up to the caller to throw away the failed instance and
31 // handle the error as appropriate. None of the Read*() methods should ever be 32 // handle the error as appropriate. None of the Read*() methods should ever be
32 // called after failure, as they will also fail immediately. 33 // called after failure, as they will also fail immediately.
33 class QUIC_EXPORT_PRIVATE QuicDataReader { 34 class QUIC_EXPORT_PRIVATE QuicDataReader {
34 public: 35 public:
35 // Caller must provide an underlying buffer to work on. 36 // Caller must provide an underlying buffer to work on.
36 QuicDataReader(const char* data, const size_t len, Perspective perspective); 37 QuicDataReader(const char* data,
38 const size_t len,
39 Perspective perspective,
40 Endianness endianness);
37 41
38 // Empty destructor. 42 // Empty destructor.
39 ~QuicDataReader() {} 43 ~QuicDataReader() {}
40 44
41 // Reads a 16-bit unsigned integer into the given output parameter. 45 // Reads an 8/16/32/64-bit unsigned integer into the given output
42 // Forwards the internal iterator on success. 46 // parameter. Forwards the internal iterator on success. Returns true on
43 // Returns true on success, false otherwise. 47 // success, false otherwise.
48 bool ReadUInt8(uint8_t* result);
44 bool ReadUInt16(uint16_t* result); 49 bool ReadUInt16(uint16_t* result);
50 bool ReadUInt32(uint32_t* result);
51 bool ReadUInt64(uint64_t* result);
45 52
46 // Reads a 32-bit unsigned integer into the given output parameter. 53 // Reads |num_bytes| bytes in the correct byte order into least significant
47 // Forwards the internal iterator on success. 54 // bytes of |result|.
48 // Returns true on success, false otherwise. 55 bool ReadBytesToUInt64(size_t num_bytes, uint64_t* result);
49 bool ReadUInt32(uint32_t* result);
50
51 // Reads a 64-bit unsigned integer into the given output parameter.
52 // Forwards the internal iterator on success.
53 // Returns true on success, false otherwise.
54 bool ReadUInt64(uint64_t* result);
55 56
56 // Reads a 16-bit unsigned float into the given output parameter. 57 // Reads a 16-bit unsigned float into the given output parameter.
57 // Forwards the internal iterator on success. 58 // Forwards the internal iterator on success.
58 // Returns true on success, false otherwise. 59 // Returns true on success, false otherwise.
59 bool ReadUFloat16(uint64_t* result); 60 bool ReadUFloat16(uint64_t* result);
60 61
61 // Reads a string prefixed with 16-bit length into the given output parameter. 62 // Reads a string prefixed with 16-bit length into the given output parameter.
62 // 63 //
63 // NOTE: Does not copy but rather references strings in the underlying buffer. 64 // NOTE: Does not copy but rather references strings in the underlying buffer.
64 // This should be kept in mind when handling memory management! 65 // This should be kept in mind when handling memory management!
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 const size_t len_; 140 const size_t len_;
140 141
141 // The location of the next read from our data buffer. 142 // The location of the next read from our data buffer.
142 size_t pos_; 143 size_t pos_;
143 144
144 // Perspective of this data reader. Please note, although client and server 145 // Perspective of this data reader. Please note, although client and server
145 // may have different in-memory representation of the same field, the on wire 146 // may have different in-memory representation of the same field, the on wire
146 // representation must be consistent. 147 // representation must be consistent.
147 Perspective perspective_; 148 Perspective perspective_;
148 149
150 // The endianness to read integers and floating numbers.
151 Endianness endianness_;
152
149 DISALLOW_COPY_AND_ASSIGN(QuicDataReader); 153 DISALLOW_COPY_AND_ASSIGN(QuicDataReader);
150 }; 154 };
151 155
152 } // namespace net 156 } // namespace net
153 157
154 #endif // NET_QUIC_CORE_QUIC_DATA_READER_H_ 158 #endif // NET_QUIC_CORE_QUIC_DATA_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698