| 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_QUIC_QUIC_DATA_WRITER_H_ | 5 #ifndef NET_QUIC_QUIC_DATA_WRITER_H_ |
| 6 #define NET_QUIC_QUIC_DATA_WRITER_H_ | 6 #define NET_QUIC_QUIC_DATA_WRITER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 bool WriteUInt128(uint128 value); | 46 bool WriteUInt128(uint128 value); |
| 47 bool WriteStringPiece16(base::StringPiece val); | 47 bool WriteStringPiece16(base::StringPiece val); |
| 48 bool WriteBytes(const void* data, size_t data_len); | 48 bool WriteBytes(const void* data, size_t data_len); |
| 49 | 49 |
| 50 // Methods for editing the payload at a specific offset, where the | 50 // Methods for editing the payload at a specific offset, where the |
| 51 // offset must be within the writer's capacity. | 51 // offset must be within the writer's capacity. |
| 52 // Return true if there is enough space at that offset, false otherwise. | 52 // Return true if there is enough space at that offset, false otherwise. |
| 53 bool WriteUInt8ToOffset(uint8 value, size_t offset); | 53 bool WriteUInt8ToOffset(uint8 value, size_t offset); |
| 54 bool WriteUInt48ToOffset(uint64 value, size_t offset); | 54 bool WriteUInt48ToOffset(uint64 value, size_t offset); |
| 55 | 55 |
| 56 static void WriteUint8ToBuffer(uint8 value, char* buffer); | |
| 57 static void WriteUint16ToBuffer(uint16 value, char* buffer); | |
| 58 static void WriteUint32ToBuffer(uint32 value, char* buffer); | |
| 59 static void WriteUint48ToBuffer(uint64 value, char* buffer); | |
| 60 static void WriteUint64ToBuffer(uint64 value, char* buffer); | |
| 61 static void WriteUint128ToBuffer(uint128 value, char* buffer); | |
| 62 | |
| 63 size_t capacity() const { | 56 size_t capacity() const { |
| 64 return capacity_; | 57 return capacity_; |
| 65 } | 58 } |
| 66 | 59 |
| 67 protected: | 60 protected: |
| 68 const char* end_of_payload() const { return buffer_ + length_; } | 61 const char* end_of_payload() const { return buffer_ + length_; } |
| 69 | 62 |
| 70 private: | 63 private: |
| 71 // Returns the location that the data should be written at, or NULL if there | 64 // Returns the location that the data should be written at, or NULL if there |
| 72 // is not enough room. Call EndWrite with the returned offset and the given | 65 // is not enough room. Call EndWrite with the returned offset and the given |
| 73 // length to pad out for the next write. | 66 // length to pad out for the next write. |
| 74 char* BeginWrite(size_t length); | 67 char* BeginWrite(size_t length); |
| 75 | 68 |
| 76 char* buffer_; | 69 char* buffer_; |
| 77 size_t capacity_; // Allocation size of payload (or -1 if buffer is const). | 70 size_t capacity_; // Allocation size of payload (or -1 if buffer is const). |
| 78 size_t length_; // Current length of the buffer. | 71 size_t length_; // Current length of the buffer. |
| 79 }; | 72 }; |
| 80 | 73 |
| 81 } // namespace net | 74 } // namespace net |
| 82 | 75 |
| 83 #endif // NET_QUIC_QUIC_DATA_WRITER_H_ | 76 #endif // NET_QUIC_QUIC_DATA_WRITER_H_ |
| OLD | NEW |