VOOZH about

URL: https://codereview.chromium.org/11125002/diff/11031/net/quic/quic_data_reader.h

⇱ net/quic/quic_data_reader.h - Issue 11125002: Add QuicFramer and friends. - Code Review


Side by Side Diff

Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Keyboard Shortcuts

File
u :up to issue
j / k :jump to file after / before current file
J / K :jump to next file with a comment after / before current file
Side-by-side diff
i :toggle intra-line diffs
e :expand all comments
c :collapse all comments
s :toggle showing all comments
n / p :next / previous diff chunk or comment
N / P :next / previous comment
<Up> / <Down> :next / previous line
Issue
u :up to list of issues
j / k :jump to patch after / before current patch
o / <Enter> :open current patch in side-by-side view
i :open current patch in unified diff view
Issue List
j / k :jump to issue after / before current issue
o / <Enter> :open current issue
👁 Image
Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Issues Search
    My Issues | Starred     Open | Closed | All

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

👁 Image
Issue 11125002: Add QuicFramer and friends. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: narrowing in Created 8 years, 2 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 | Annotate | Revision Log
« net/quic/crypto/null_encrypter_test.cc ('K') | « net/quic/crypto/quic_encrypter.cc ('k') | net/quic/quic_data_reader.cc » ('j') | net/quic/quic_data_reader.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
#ifndef NET_SPDY_SPDY_FRAME_READER_H_#ifndef NET_QUIC_QUIC_DATA_READER_H_
#define NET_SPDY_SPDY_FRAME_READER_H_#define NET_QUIC_QUIC_DATA_READER_H_
7 7
8 #include "base/basictypes.h" 8 #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.
9 #include "base/string_piece.h" 10 #include "base/string_piece.h"
#include "net/base/net_export.h"
11 11
12 namespace net { 12 namespace net {
13 13
// Used for reading SPDY frames. Though there isn't really anything terribly// Used for reading QUIC data. Though there isn't really anything terribly
// SPDY-specific here, it's a helper class that's useful when doing SPDY// QUIC-specific here, it's a helper class that's useful when doing QUIC
16 // framing. 16 // framing.
17 // 17 //
// To use, simply construct a SpdyFramerReader using the underlying buffer that// To use, simply construct a QuicDataReader using the underlying buffer that
19 // you'd like to read fields from, then call one of the Read*() methods to 19 // you'd like to read fields from, then call one of the Read*() methods to
20 // actually do some reading. 20 // actually do some reading.
21 // 21 //
22 // This class keeps an internal iterator to keep track of what's already been 22 // This class keeps an internal iterator to keep track of what's already been
23 // read and each successive Read*() call automatically increments said iterator 23 // 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
25 // trusted and it is up to the caller to throw away the failed instance and 25 // trusted and it is up to the caller to throw away the failed instance and
26 // handle the error as appropriate. None of the Read*() methods should ever be 26 // handle the error as appropriate. None of the Read*() methods should ever be
27 // called after failure, as they will also fail immediately. 27 // called after failure, as they will also fail immediately.
class NET_EXPORT_PRIVATE SpdyFrameReader {class QuicDataReader {
29 public: 29 public:
30 // Caller must provide an underlying buffer to work on. 30 // 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);
32 32
33 // Empty destructor. 33 // Empty destructor.
~SpdyFrameReader() {} ~QuicDataReader() {}
35 35
36 // Reads a 16-bit unsigned integer into the given output parameter. 36 // Reads a 16-bit unsigned integer into the given output parameter.
37 // Forwards the internal iterater on success. 37 // Forwards the internal iterater on success.
38 // Returns true on success, false otherwise. 38 // Returns true on success, false otherwise.
39 bool ReadUInt16(uint16* result); 39 bool ReadUInt16(uint16* result);
40 40
41 // Reads a 32-bit unsigned integer into the given output parameter. 41 // Reads a 32-bit unsigned integer into the given output parameter.
42 // Forwards the internal iterater on success. 42 // Forwards the internal iterater on success.
43 // Returns true on success, false otherwise. 43 // Returns true on success, false otherwise.
44 bool ReadUInt32(uint32* result); 44 bool ReadUInt32(uint32* result);
45 45
// 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);
46 // Reads a string prefixed with 16-bit length into the given output parameter. 60 // Reads a string prefixed with 16-bit length into the given output parameter.
47 // 61 //
48 // NOTE: Does not copy but rather references strings in the underlying buffer. 62 // NOTE: Does not copy but rather references strings in the underlying buffer.
49 // This should be kept in mind when handling memory management! 63 // This should be kept in mind when handling memory management!
50 // 64 //
51 // Forwards the internal iterater on success. 65 // Forwards the internal iterater on success.
52 // Returns true on success, false otherwise. 66 // Returns true on success, false otherwise.
53 bool ReadStringPiece16(base::StringPiece* result); 67 bool ReadStringPiece16(base::StringPiece* result);
54 68
// 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.
56 // 76 //
57 // NOTE: Does not copy but rather references strings in the underlying buffer. 77 // NOTE: Does not copy but rather references strings in the underlying buffer.
58 // This should be kept in mind when handling memory management! 78 // This should be kept in mind when handling memory management!
59 // 79 //
// Forwards the internal iterater on success. // Forwards the internal iterater.
// Returns true on success, false otherwise. base::StringPiece ReadRemainingPayload();
bool ReadStringPiece32(base::StringPiece* result);
// 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();
63 90
64 // Reads a given number of bytes into the given buffer. The buffer 91 // Reads a given number of bytes into the given buffer. The buffer
65 // must be of adequate size. 92 // must be of adequate size.
66 // Forwards the internal iterater on success. 93 // Forwards the internal iterater on success.
67 // Returns true on success, false otherwise. 94 // Returns true on success, false otherwise.
68 bool ReadBytes(void* result, size_t size); 95 bool ReadBytes(void* result, size_t size);
69 96
70 // Returns true if the entirety of the underlying buffer has been read via 97 // Returns true if the entirety of the underlying buffer has been read via
71 // Read*() calls. 98 // Read*() calls.
72 bool IsDoneReading() const; 99 bool IsDoneReading() const;
73 100
// Returns the number of bytes remaining to be read.
size_t BytesRemaining() const;
74 private: 104 private:
75 // Returns true if the underlying buffer has enough room to read the given 105 // Returns true if the underlying buffer has enough room to read the given
76 // amount of bytes. 106 // amount of bytes.
77 bool CanRead(size_t bytes) const; 107 bool CanRead(size_t bytes) const;
78 108
79 // To be called when a read fails for any reason. 109 // To be called when a read fails for any reason.
80 void OnFailure(); 110 void OnFailure();
81 111
82 // The data buffer that we're reading from. 112 // The data buffer that we're reading from.
83 const char* data_; 113 const char* data_;
84 114
85 // The length of the data buffer that we're reading from. 115 // The length of the data buffer that we're reading from.
86 const size_t len_; 116 const size_t len_;
87 117
88 // The location of the next read from our data buffer. 118 // The location of the next read from our data buffer.
size_t ofs_; size_t pos_;
90 }; 120 };
91 121
92 } // namespace net 122 } // namespace net
93 123
#endif // NET_SPDY_SPDY_FRAME_READER_H_#endif // NET_QUIC_QUIC_DATA_READER_H_
OLDNEW
« net/quic/crypto/null_encrypter_test.cc ('K') | « net/quic/crypto/quic_encrypter.cc ('k') | net/quic/quic_data_reader.cc » ('j') | net/quic/quic_data_reader.cc » ('J')
👁 Powered by Google App Engine
This is Rietveld 408576698