Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: net/quic/quic_data_writer.h

Issue 1535363003: Switch to standard integer types in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stddef Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_data_reader.cc ('k') | net/quic/quic_data_writer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h>
9 #include <stdint.h>
10
8 #include <cstddef> 11 #include <cstddef>
9 #include <string> 12 #include <string>
10 13
11 #include "base/basictypes.h"
12 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h"
13 #include "base/strings/string_piece.h" 16 #include "base/strings/string_piece.h"
14 #include "net/base/int128.h" 17 #include "net/base/int128.h"
15 #include "net/base/net_export.h" 18 #include "net/base/net_export.h"
16 #include "net/quic/quic_protocol.h" 19 #include "net/quic/quic_protocol.h"
17 20
18 namespace net { 21 namespace net {
19 22
20 // This class provides facilities for packing QUIC data. 23 // This class provides facilities for packing QUIC data.
21 // 24 //
22 // The QuicDataWriter supports appending primitive values (int, string, etc) 25 // The QuicDataWriter supports appending primitive values (int, string, etc)
23 // to a frame instance. The internal memory buffer is exposed as the "data" 26 // to a frame instance. The internal memory buffer is exposed as the "data"
24 // of the QuicDataWriter. 27 // of the QuicDataWriter.
25 class NET_EXPORT_PRIVATE QuicDataWriter { 28 class NET_EXPORT_PRIVATE QuicDataWriter {
26 public: 29 public:
27 // Creates a QuicDataWriter where |buffer| is not owned. 30 // Creates a QuicDataWriter where |buffer| is not owned.
28 QuicDataWriter(size_t size, char* buffer); 31 QuicDataWriter(size_t size, char* buffer);
29 32
30 ~QuicDataWriter(); 33 ~QuicDataWriter();
31 34
32 // Returns the size of the QuicDataWriter's data. 35 // Returns the size of the QuicDataWriter's data.
33 size_t length() const { return length_; } 36 size_t length() const { return length_; }
34 37
35 // Retrieves the buffer from the QuicDataWriter without changing ownership. 38 // Retrieves the buffer from the QuicDataWriter without changing ownership.
36 char* data(); 39 char* data();
37 40
38 // Methods for adding to the payload. These values are appended to the end 41 // Methods for adding to the payload. These values are appended to the end
39 // of the QuicDataWriter payload. Note - binary integers are written in 42 // of the QuicDataWriter payload. Note - binary integers are written in
40 // host byte order (little endian) not network byte order (big endian). 43 // host byte order (little endian) not network byte order (big endian).
41 bool WriteUInt8(uint8 value); 44 bool WriteUInt8(uint8_t value);
42 bool WriteUInt16(uint16 value); 45 bool WriteUInt16(uint16_t value);
43 bool WriteUInt32(uint32 value); 46 bool WriteUInt32(uint32_t value);
44 bool WriteUInt48(uint64 value); 47 bool WriteUInt48(uint64_t value);
45 bool WriteUInt64(uint64 value); 48 bool WriteUInt64(uint64_t value);
46 // Write unsigned floating point corresponding to the value. Large values are 49 // Write unsigned floating point corresponding to the value. Large values are
47 // clamped to the maximum representable (kUFloat16MaxValue). Values that can 50 // clamped to the maximum representable (kUFloat16MaxValue). Values that can
48 // not be represented directly are rounded down. 51 // not be represented directly are rounded down.
49 bool WriteUFloat16(uint64 value); 52 bool WriteUFloat16(uint64_t value);
50 bool WriteStringPiece16(base::StringPiece val); 53 bool WriteStringPiece16(base::StringPiece val);
51 bool WriteBytes(const void* data, size_t data_len); 54 bool WriteBytes(const void* data, size_t data_len);
52 bool WriteRepeatedByte(uint8 byte, size_t count); 55 bool WriteRepeatedByte(uint8_t byte, size_t count);
53 // Fills the remaining buffer with null characters. 56 // Fills the remaining buffer with null characters.
54 void WritePadding(); 57 void WritePadding();
55 58
56 size_t capacity() const { return capacity_; } 59 size_t capacity() const { return capacity_; }
57 60
58 private: 61 private:
59 // 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
60 // 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
61 // given length to pad out for the next write. 64 // given length to pad out for the next write.
62 char* BeginWrite(size_t length); 65 char* BeginWrite(size_t length);
63 66
64 char* buffer_; 67 char* buffer_;
65 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).
66 size_t length_; // Current length of the buffer. 69 size_t length_; // Current length of the buffer.
67 70
68 DISALLOW_COPY_AND_ASSIGN(QuicDataWriter); 71 DISALLOW_COPY_AND_ASSIGN(QuicDataWriter);
69 }; 72 };
70 73
71 } // namespace net 74 } // namespace net
72 75
73 #endif // NET_QUIC_QUIC_DATA_WRITER_H_ 76 #endif // NET_QUIC_QUIC_DATA_WRITER_H_
OLDNEW
« no previous file with comments | « net/quic/quic_data_reader.cc ('k') | net/quic/quic_data_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698