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 // Fills the remaining buffer with null characters. | 49 // Fills the remaining buffer with null characters. |
50 void WritePadding(); | 50 void WritePadding(); |
51 | 51 |
52 // Methods for editing the payload at a specific offset, where the | 52 // Methods for editing the payload at a specific offset, where the |
53 // offset must be within the writer's capacity. | 53 // offset must be within the writer's capacity. |
54 // Return true if there is enough space at that offset, false otherwise. | 54 // Return true if there is enough space at that offset, false otherwise. |
55 bool WriteUInt8ToOffset(uint8 value, size_t offset); | 55 bool WriteUInt8ToOffset(uint8 value, size_t offset); |
| 56 bool WriteUInt32ToOffset(uint32 value, size_t offset); |
56 bool WriteUInt48ToOffset(uint64 value, size_t offset); | 57 bool WriteUInt48ToOffset(uint64 value, size_t offset); |
57 | 58 |
58 size_t capacity() const { | 59 size_t capacity() const { |
59 return capacity_; | 60 return capacity_; |
60 } | 61 } |
61 | 62 |
62 protected: | 63 protected: |
63 const char* end_of_payload() const { return buffer_ + length_; } | 64 const char* end_of_payload() const { return buffer_ + length_; } |
64 | 65 |
65 private: | 66 private: |
66 // Returns the location that the data should be written at, or NULL if there | 67 // Returns the location that the data should be written at, or NULL if there |
67 // is not enough room. Call EndWrite with the returned offset and the given | 68 // is not enough room. Call EndWrite with the returned offset and the given |
68 // length to pad out for the next write. | 69 // length to pad out for the next write. |
69 char* BeginWrite(size_t length); | 70 char* BeginWrite(size_t length); |
70 | 71 |
71 char* buffer_; | 72 char* buffer_; |
72 size_t capacity_; // Allocation size of payload (or -1 if buffer is const). | 73 size_t capacity_; // Allocation size of payload (or -1 if buffer is const). |
73 size_t length_; // Current length of the buffer. | 74 size_t length_; // Current length of the buffer. |
74 }; | 75 }; |
75 | 76 |
76 } // namespace net | 77 } // namespace net |
77 | 78 |
78 #endif // NET_QUIC_QUIC_DATA_WRITER_H_ | 79 #endif // NET_QUIC_QUIC_DATA_WRITER_H_ |
OLD | NEW |