| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 // clamped to the maximum representable (kUFloat16MaxValue). Values that can | 47 // clamped to the maximum representable (kUFloat16MaxValue). Values that can |
| 48 // not be represented directly are rounded down. | 48 // not be represented directly are rounded down. |
| 49 bool WriteUFloat16(uint64 value); | 49 bool WriteUFloat16(uint64 value); |
| 50 bool WriteStringPiece16(base::StringPiece val); | 50 bool WriteStringPiece16(base::StringPiece val); |
| 51 bool WriteIOVector(const IOVector& data); | 51 bool WriteIOVector(const IOVector& data); |
| 52 bool WriteBytes(const void* data, size_t data_len); | 52 bool WriteBytes(const void* data, size_t data_len); |
| 53 bool WriteRepeatedByte(uint8 byte, size_t count); | 53 bool WriteRepeatedByte(uint8 byte, size_t count); |
| 54 // Fills the remaining buffer with null characters. | 54 // Fills the remaining buffer with null characters. |
| 55 void WritePadding(); | 55 void WritePadding(); |
| 56 | 56 |
| 57 // Methods for editing the payload at a specific offset, where the | |
| 58 // offset must be within the writer's capacity. | |
| 59 // Return true if there is enough space at that offset, false otherwise. | |
| 60 bool WriteUInt8ToOffset(uint8 value, size_t offset); | |
| 61 bool WriteUInt32ToOffset(uint32 value, size_t offset); | |
| 62 bool WriteUInt48ToOffset(uint64 value, size_t offset); | |
| 63 | |
| 64 size_t capacity() const { | 57 size_t capacity() const { |
| 65 return capacity_; | 58 return capacity_; |
| 66 } | 59 } |
| 67 | 60 |
| 68 private: | 61 private: |
| 69 // Returns the location that the data should be written at, or nullptr if | 62 // Returns the location that the data should be written at, or nullptr if |
| 70 // there is not enough room. Call EndWrite with the returned offset and the | 63 // there is not enough room. Call EndWrite with the returned offset and the |
| 71 // given length to pad out for the next write. | 64 // given length to pad out for the next write. |
| 72 char* BeginWrite(size_t length); | 65 char* BeginWrite(size_t length); |
| 73 | 66 |
| 74 char* buffer_; | 67 char* buffer_; |
| 75 size_t capacity_; // Allocation size of payload (or -1 if buffer is const). | 68 size_t capacity_; // Allocation size of payload (or -1 if buffer is const). |
| 76 size_t length_; // Current length of the buffer. | 69 size_t length_; // Current length of the buffer. |
| 77 | 70 |
| 78 DISALLOW_COPY_AND_ASSIGN(QuicDataWriter); | 71 DISALLOW_COPY_AND_ASSIGN(QuicDataWriter); |
| 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 |