Chromium Code Reviews| Index: net/quic/quic_data_reader.h |
| diff --git a/net/spdy/spdy_frame_reader.h b/net/quic/quic_data_reader.h |
| similarity index 59% |
| copy from net/spdy/spdy_frame_reader.h |
| copy to net/quic/quic_data_reader.h |
| index 6db7a08f659e75638deebefa38df2507e818fd03..76ec69637b776669d3e6cf4337463dbecbb4fa5e 100644 |
| --- a/net/spdy/spdy_frame_reader.h |
| +++ b/net/quic/quic_data_reader.h |
| @@ -2,36 +2,36 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#ifndef NET_SPDY_SPDY_FRAME_READER_H_ |
| -#define NET_SPDY_SPDY_FRAME_READER_H_ |
| +#ifndef NET_QUIC_QUIC_DATA_READER_H_ |
| +#define NET_QUIC_QUIC_DATA_READER_H_ |
| #include "base/basictypes.h" |
| +#include "net/quic/uint128.h" |
|
jar (doing other things)
2012/10/14 23:04:38
nit: alphabetize
Ryan Hamilton
2012/10/15 21:22:08
Done.
|
| #include "base/string_piece.h" |
| -#include "net/base/net_export.h" |
| namespace net { |
| -// Used for reading SPDY frames. Though there isn't really anything terribly |
| -// SPDY-specific here, it's a helper class that's useful when doing SPDY |
| +// Used for reading QUIC data. Though there isn't really anything terribly |
| +// QUIC-specific here, it's a helper class that's useful when doing QUIC |
| // framing. |
| // |
| -// To use, simply construct a SpdyFramerReader using the underlying buffer that |
| +// To use, simply construct a QuicDataReader using the underlying buffer that |
| // you'd like to read fields from, then call one of the Read*() methods to |
| // actually do some reading. |
| // |
| // This class keeps an internal iterator to keep track of what's already been |
| // read and each successive Read*() call automatically increments said iterator |
| -// on success. On failure, internal state of the SpdyFrameReader should not be |
| +// on success. On failure, internal state of the QuicDataReader should not be |
| // trusted and it is up to the caller to throw away the failed instance and |
| // handle the error as appropriate. None of the Read*() methods should ever be |
| // called after failure, as they will also fail immediately. |
| -class NET_EXPORT_PRIVATE SpdyFrameReader { |
| +class QuicDataReader { |
| public: |
| // Caller must provide an underlying buffer to work on. |
| - SpdyFrameReader(const char* data, const size_t len); |
| + QuicDataReader(const char* data, const size_t len); |
| // Empty destructor. |
| - ~SpdyFrameReader() {} |
| + ~QuicDataReader() {} |
| // Reads a 16-bit unsigned integer into the given output parameter. |
| // Forwards the internal iterater on success. |
| @@ -43,6 +43,20 @@ class NET_EXPORT_PRIVATE SpdyFrameReader { |
| // Returns true on success, false otherwise. |
| bool ReadUInt32(uint32* result); |
| + // Reads a 48-bit unsigned integer into the given output parameter. |
| + // Forwards the internal iterater on success. |
|
jar (doing other things)
2012/10/14 23:04:38
nit: spelling: iterater--> iterator
This was inhe
Ryan Hamilton
2012/10/15 21:22:08
Done.
|
| + // Returns true on success, false otherwise. |
| + bool ReadUInt48(uint64* result); |
| + |
| + // Reads a 64-bit unsigned integer into the given output parameter. |
| + // Forwards the internal iterater on success. |
| + // Returns true on success, false otherwise. |
| + bool ReadUInt64(uint64* result); |
| + |
| + // Reads a 128-bit unsigned integer nito the given output parameter. |
|
jar (doing other things)
2012/10/14 23:04:38
nit: nito-->into
Ryan Hamilton
2012/10/15 21:22:08
Done.
|
| + // Forwards the internal iterater on success. |
| + // Returns true on success, false otherwise. |
| + bool ReadUInt128(uint128* result); |
| // Reads a string prefixed with 16-bit length into the given output parameter. |
| // |
| // NOTE: Does not copy but rather references strings in the underlying buffer. |
| @@ -52,14 +66,27 @@ class NET_EXPORT_PRIVATE SpdyFrameReader { |
| // Returns true on success, false otherwise. |
| bool ReadStringPiece16(base::StringPiece* result); |
| - // Reads a string prefixed with 32-bit length into the given output parameter. |
| + // Reads a given number of bytes into the given buffer. The buffer |
| + // must be of adequate size. |
| + // Forwards the internal iterater on success. |
| + // Returns true on success, false otherwise. |
| + bool ReadStringPiece(base::StringPiece* result, size_t len); |
| + |
| + // Returns the remaining payload as a StringPiece. |
| // |
| // NOTE: Does not copy but rather references strings in the underlying buffer. |
| // This should be kept in mind when handling memory management! |
| // |
| - // Forwards the internal iterater on success. |
| - // Returns true on success, false otherwise. |
| - bool ReadStringPiece32(base::StringPiece* result); |
| + // Forwards the internal iterater. |
| + base::StringPiece ReadRemainingPayload(); |
| + |
| + // Returns the remaining payload as a StringPiece. |
| + // |
| + // NOTE: Does not copy but rather references strings in the underlying buffer. |
| + // This should be kept in mind when handling memory management! |
| + // |
| + // DOES NOT forward the internal iterater. |
| + base::StringPiece PeekRemainingPayload(); |
| // Reads a given number of bytes into the given buffer. The buffer |
| // must be of adequate size. |
| @@ -71,6 +98,9 @@ class NET_EXPORT_PRIVATE SpdyFrameReader { |
| // Read*() calls. |
| bool IsDoneReading() const; |
| + // Returns the number of bytes remaining to be read. |
| + size_t BytesRemaining() const; |
| + |
| private: |
| // Returns true if the underlying buffer has enough room to read the given |
| // amount of bytes. |
| @@ -86,9 +116,9 @@ class NET_EXPORT_PRIVATE SpdyFrameReader { |
| const size_t len_; |
| // The location of the next read from our data buffer. |
| - size_t ofs_; |
| + size_t pos_; |
| }; |
| } // namespace net |
| -#endif // NET_SPDY_SPDY_FRAME_READER_H_ |
| +#endif // NET_QUIC_QUIC_DATA_READER_H_ |