Chromium Code Reviews| Index: base/pickle.h |
| =================================================================== |
| --- base/pickle.h (revision 271871) |
| +++ base/pickle.h (working copy) |
| @@ -20,13 +20,14 @@ |
| // while the PickleIterator object is in use. |
| class BASE_EXPORT PickleIterator { |
| public: |
| - PickleIterator() : read_ptr_(NULL), read_end_ptr_(NULL) {} |
| + PickleIterator() : payload_ptr_(NULL), read_index_(0), end_index_(0) {} |
| explicit PickleIterator(const Pickle& pickle); |
| // Methods for reading the payload of the Pickle. To read from the start of |
| // the Pickle, create a PickleIterator from a Pickle. If successful, these |
| // methods return true. Otherwise, false is returned to indicate that the |
| - // result could not be extracted. |
| + // result could not be extracted. It is not possible to read from iterator |
| + // after that. |
| bool ReadBool(bool* result) WARN_UNUSED_RESULT; |
| bool ReadInt(int* result) WARN_UNUSED_RESULT; |
| bool ReadLong(long* result) WARN_UNUSED_RESULT; |
| @@ -63,6 +64,10 @@ |
| template <typename Type> |
| inline bool ReadBuiltinType(Type* result); |
| + // Advance read_index_ but do not allow it to exceed end_index_. |
| + // Keeps read_index_ aligned. |
| + inline void Advance(size_t size); |
| + |
| // Get read pointer for Type and advance read pointer. |
| template<typename Type> |
| inline const char* GetReadPointerAndAdvance(); |
| @@ -77,8 +82,9 @@ |
| size_t size_element); |
| // Pointers to the Pickle data. |
| - const char* read_ptr_; |
| - const char* read_end_ptr_; |
| + const char* payload_ptr_; |
|
jar (doing other things)
2014/05/29 01:51:16
nit: Now that we're not advancing this ptr, perha
halyavin
2014/05/29 07:34:55
Done.
|
| + size_t read_index_; |
| + size_t end_index_; |
| FRIEND_TEST_ALL_PREFIXES(PickleTest, GetReadPointerAndAdvance); |
| }; |
| @@ -277,7 +283,9 @@ |
| } |
| // The payload is the pickle data immediately following the header. |
| - size_t payload_size() const { return header_->payload_size; } |
| + size_t payload_size() const { |
| + return header_ ? header_->payload_size : 0; |
| + } |
| const char* payload() const { |
| return reinterpret_cast<const char*>(header_) + header_size_; |