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_CORE_QUIC_DATA_WRITER_H_ | 5 #ifndef NET_QUIC_CORE_QUIC_DATA_WRITER_H_ |
6 #define NET_QUIC_CORE_QUIC_DATA_WRITER_H_ | 6 #define NET_QUIC_CORE_QUIC_DATA_WRITER_H_ |
7 | 7 |
8 #include <cstddef> | 8 #include <cstddef> |
9 #include <cstdint> | 9 #include <cstdint> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/strings/string_piece.h" | |
14 #include "net/base/int128.h" | 13 #include "net/base/int128.h" |
15 #include "net/quic/core/quic_packets.h" | 14 #include "net/quic/core/quic_packets.h" |
16 #include "net/quic/platform/api/quic_export.h" | 15 #include "net/quic/platform/api/quic_export.h" |
| 16 #include "net/quic/platform/api/quic_string_piece.h" |
17 | 17 |
18 namespace net { | 18 namespace net { |
19 | 19 |
20 // This class provides facilities for packing QUIC data. | 20 // This class provides facilities for packing QUIC data. |
21 // | 21 // |
22 // The QuicDataWriter supports appending primitive values (int, string, etc) | 22 // The QuicDataWriter supports appending primitive values (int, string, etc) |
23 // to a frame instance. The internal memory buffer is exposed as the "data" | 23 // to a frame instance. The internal memory buffer is exposed as the "data" |
24 // of the QuicDataWriter. | 24 // of the QuicDataWriter. |
25 class QUIC_EXPORT_PRIVATE QuicDataWriter { | 25 class QUIC_EXPORT_PRIVATE QuicDataWriter { |
26 public: | 26 public: |
(...skipping 13 matching lines...) Expand all Loading... |
40 // host byte order (little endian) not network byte order (big endian). | 40 // host byte order (little endian) not network byte order (big endian). |
41 bool WriteUInt8(uint8_t value); | 41 bool WriteUInt8(uint8_t value); |
42 bool WriteUInt16(uint16_t value); | 42 bool WriteUInt16(uint16_t value); |
43 bool WriteUInt32(uint32_t value); | 43 bool WriteUInt32(uint32_t value); |
44 bool WriteUInt48(uint64_t value); | 44 bool WriteUInt48(uint64_t value); |
45 bool WriteUInt64(uint64_t value); | 45 bool WriteUInt64(uint64_t value); |
46 // Write unsigned floating point corresponding to the value. Large values are | 46 // Write unsigned floating point corresponding to the value. Large values are |
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_t value); | 49 bool WriteUFloat16(uint64_t value); |
50 bool WriteStringPiece16(base::StringPiece val); | 50 bool WriteStringPiece16(QuicStringPiece val); |
51 bool WriteBytes(const void* data, size_t data_len); | 51 bool WriteBytes(const void* data, size_t data_len); |
52 bool WriteRepeatedByte(uint8_t byte, size_t count); | 52 bool WriteRepeatedByte(uint8_t byte, size_t count); |
53 // Fills the remaining buffer with null characters. | 53 // Fills the remaining buffer with null characters. |
54 void WritePadding(); | 54 void WritePadding(); |
55 | 55 |
56 size_t capacity() const { return capacity_; } | 56 size_t capacity() const { return capacity_; } |
57 | 57 |
58 private: | 58 private: |
59 // Returns the location that the data should be written at, or nullptr if | 59 // Returns the location that the data should be written at, or nullptr if |
60 // there is not enough room. Call EndWrite with the returned offset and the | 60 // there is not enough room. Call EndWrite with the returned offset and the |
61 // given length to pad out for the next write. | 61 // given length to pad out for the next write. |
62 char* BeginWrite(size_t length); | 62 char* BeginWrite(size_t length); |
63 | 63 |
64 char* buffer_; | 64 char* buffer_; |
65 size_t capacity_; // Allocation size of payload (or -1 if buffer is const). | 65 size_t capacity_; // Allocation size of payload (or -1 if buffer is const). |
66 size_t length_; // Current length of the buffer. | 66 size_t length_; // Current length of the buffer. |
67 | 67 |
68 DISALLOW_COPY_AND_ASSIGN(QuicDataWriter); | 68 DISALLOW_COPY_AND_ASSIGN(QuicDataWriter); |
69 }; | 69 }; |
70 | 70 |
71 } // namespace net | 71 } // namespace net |
72 | 72 |
73 #endif // NET_QUIC_CORE_QUIC_DATA_WRITER_H_ | 73 #endif // NET_QUIC_CORE_QUIC_DATA_WRITER_H_ |
OLD | NEW |