| 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_SPDY_SPDY_FRAME_READER_H_ | 5 #ifndef NET_SPDY_SPDY_FRAME_READER_H_ |
| 6 #define NET_SPDY_SPDY_FRAME_READER_H_ | 6 #define NET_SPDY_SPDY_FRAME_READER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/string_piece.h" | 9 #include "base/string_piece.h" |
| 10 #include "net/base/net_export.h" | 10 #include "net/base/net_export.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 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. |
| 28 class NET_EXPORT_PRIVATE SpdyFrameReader { | 28 class NET_EXPORT_PRIVATE SpdyFrameReader { |
| 29 public: | 29 public: |
| 30 // Caller must provide an underlying buffer to work on. | 30 // Caller must provide an underlying buffer to work on. |
| 31 SpdyFrameReader(const char* data, const size_t len); | 31 SpdyFrameReader(const char* data, const size_t len); |
| 32 | 32 |
| 33 // Empty destructor. | 33 // Empty destructor. |
| 34 ~SpdyFrameReader() {} | 34 ~SpdyFrameReader() {} |
| 35 | 35 |
| 36 // Reads an 8-bit unsigned integer into the given output parameter. |
| 37 // Forwards the internal iterater on success. |
| 38 // Returns true on success, false otherwise. |
| 39 bool ReadUInt8(uint8* result); |
| 40 |
| 36 // Reads a 16-bit unsigned integer into the given output parameter. | 41 // Reads a 16-bit unsigned integer into the given output parameter. |
| 37 // Forwards the internal iterater on success. | 42 // Forwards the internal iterater on success. |
| 38 // Returns true on success, false otherwise. | 43 // Returns true on success, false otherwise. |
| 39 bool ReadUInt16(uint16* result); | 44 bool ReadUInt16(uint16* result); |
| 40 | 45 |
| 41 // Reads a 32-bit unsigned integer into the given output parameter. | 46 // Reads a 32-bit unsigned integer into the given output parameter. |
| 42 // Forwards the internal iterater on success. | 47 // Forwards the internal iterater on success. |
| 43 // Returns true on success, false otherwise. | 48 // Returns true on success, false otherwise. |
| 44 bool ReadUInt32(uint32* result); | 49 bool ReadUInt32(uint32* result); |
| 45 | 50 |
| 51 // Reads a 31-bit unsigned integer into the given output parameter. This is |
| 52 // equivelant to ReadUInt32() above except that the highest-order bit is |
| 53 // discarded. |
| 54 // Forwards the internal iterater (by 4B) on success. |
| 55 // Returns true on success, false otherwise. |
| 56 bool ReadUInt31(uint32* result); |
| 57 |
| 46 // Reads a string prefixed with 16-bit length into the given output parameter. | 58 // Reads a string prefixed with 16-bit length into the given output parameter. |
| 47 // | 59 // |
| 48 // NOTE: Does not copy but rather references strings in the underlying buffer. | 60 // NOTE: Does not copy but rather references strings in the underlying buffer. |
| 49 // This should be kept in mind when handling memory management! | 61 // This should be kept in mind when handling memory management! |
| 50 // | 62 // |
| 51 // Forwards the internal iterater on success. | 63 // Forwards the internal iterater on success. |
| 52 // Returns true on success, false otherwise. | 64 // Returns true on success, false otherwise. |
| 53 bool ReadStringPiece16(base::StringPiece* result); | 65 bool ReadStringPiece16(base::StringPiece* result); |
| 54 | 66 |
| 55 // Reads a string prefixed with 32-bit length into the given output parameter. | 67 // Reads a string prefixed with 32-bit length into the given output parameter. |
| 56 // | 68 // |
| 57 // NOTE: Does not copy but rather references strings in the underlying buffer. | 69 // NOTE: Does not copy but rather references strings in the underlying buffer. |
| 58 // This should be kept in mind when handling memory management! | 70 // This should be kept in mind when handling memory management! |
| 59 // | 71 // |
| 60 // Forwards the internal iterater on success. | 72 // Forwards the internal iterater on success. |
| 61 // Returns true on success, false otherwise. | 73 // Returns true on success, false otherwise. |
| 62 bool ReadStringPiece32(base::StringPiece* result); | 74 bool ReadStringPiece32(base::StringPiece* result); |
| 63 | 75 |
| 64 // Reads a given number of bytes into the given buffer. The buffer | 76 // Reads a given number of bytes into the given buffer. The buffer |
| 65 // must be of adequate size. | 77 // must be of adequate size. |
| 66 // Forwards the internal iterater on success. | 78 // Forwards the internal iterater on success. |
| 67 // Returns true on success, false otherwise. | 79 // Returns true on success, false otherwise. |
| 68 bool ReadBytes(void* result, size_t size); | 80 bool ReadBytes(void* result, size_t size); |
| 69 | 81 |
| 82 // Seeks a given number of bytes into the buffer from the current offset. |
| 83 // Equivelant to an empty read. |
| 84 // Forwards the internal iterator. |
| 85 // Returns true on success, false otherwise. |
| 86 bool Seek(size_t size); |
| 87 |
| 70 // Returns true if the entirety of the underlying buffer has been read via | 88 // Returns true if the entirety of the underlying buffer has been read via |
| 71 // Read*() calls. | 89 // Read*() calls. |
| 72 bool IsDoneReading() const; | 90 bool IsDoneReading() const; |
| 73 | 91 |
| 74 // Returns the number of bytes that have been consumed by the reader so far. | 92 // Returns the number of bytes that have been consumed by the reader so far. |
| 75 size_t GetBytesConsumed() const { return ofs_; } | 93 size_t GetBytesConsumed() const { return ofs_; } |
| 76 | 94 |
| 77 private: | 95 private: |
| 78 // Returns true if the underlying buffer has enough room to read the given | 96 // Returns true if the underlying buffer has enough room to read the given |
| 79 // amount of bytes. | 97 // amount of bytes. |
| 80 bool CanRead(size_t bytes) const; | 98 bool CanRead(size_t bytes) const; |
| 81 | 99 |
| 82 // To be called when a read fails for any reason. | 100 // To be called when a read fails for any reason. |
| 83 void OnFailure(); | 101 void OnFailure(); |
| 84 | 102 |
| 85 // The data buffer that we're reading from. | 103 // The data buffer that we're reading from. |
| 86 const char* data_; | 104 const char* data_; |
| 87 | 105 |
| 88 // The length of the data buffer that we're reading from. | 106 // The length of the data buffer that we're reading from. |
| 89 const size_t len_; | 107 const size_t len_; |
| 90 | 108 |
| 91 // The location of the next read from our data buffer. | 109 // The location of the next read from our data buffer. |
| 92 size_t ofs_; | 110 size_t ofs_; |
| 93 }; | 111 }; |
| 94 | 112 |
| 95 } // namespace net | 113 } // namespace net |
| 96 | 114 |
| 97 #endif // NET_SPDY_SPDY_FRAME_READER_H_ | 115 #endif // NET_SPDY_SPDY_FRAME_READER_H_ |
| OLD | NEW |