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_SPDY_SPDY_FRAME_BUILDER_H_ | 5 #ifndef NET_SPDY_SPDY_FRAME_BUILDER_H_ |
6 #define NET_SPDY_SPDY_FRAME_BUILDER_H_ | 6 #define NET_SPDY_SPDY_FRAME_BUILDER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 // Methods for adding to the payload. These values are appended to the end | 81 // Methods for adding to the payload. These values are appended to the end |
82 // of the SpdyFrameBuilder payload. Note - binary integers are converted from | 82 // of the SpdyFrameBuilder payload. Note - binary integers are converted from |
83 // host to network form. | 83 // host to network form. |
84 bool WriteUInt8(uint8 value) { | 84 bool WriteUInt8(uint8 value) { |
85 return WriteBytes(&value, sizeof(value)); | 85 return WriteBytes(&value, sizeof(value)); |
86 } | 86 } |
87 bool WriteUInt16(uint16 value) { | 87 bool WriteUInt16(uint16 value) { |
88 value = htons(value); | 88 value = htons(value); |
89 return WriteBytes(&value, sizeof(value)); | 89 return WriteBytes(&value, sizeof(value)); |
90 } | 90 } |
| 91 bool WriteUInt24(uint32 value) { |
| 92 DCHECK_EQ(value >> 24, 0u); |
| 93 return |
| 94 WriteUInt8(static_cast<uint8>(value >> 16)) && |
| 95 WriteUInt8(static_cast<uint8>(value >> 8)) && |
| 96 WriteUInt8(static_cast<uint8>(value >> 0)); |
| 97 } |
91 bool WriteUInt32(uint32 value) { | 98 bool WriteUInt32(uint32 value) { |
92 value = htonl(value); | 99 value = htonl(value); |
93 return WriteBytes(&value, sizeof(value)); | 100 return WriteBytes(&value, sizeof(value)); |
94 } | 101 } |
95 // TODO(hkhalil) Rename to WriteStringPiece16(). | 102 // TODO(hkhalil) Rename to WriteStringPiece16(). |
96 bool WriteString(const std::string& value); | 103 bool WriteString(const std::string& value); |
97 bool WriteStringPiece32(const base::StringPiece& value); | 104 bool WriteStringPiece32(const base::StringPiece& value); |
98 bool WriteBytes(const void* data, uint32 data_len); | 105 bool WriteBytes(const void* data, uint32 data_len); |
99 | 106 |
100 // Update (in-place) the length field in the frame being built to reflect the | 107 // Update (in-place) the length field in the frame being built to reflect the |
(...skipping 16 matching lines...) Expand all Loading... |
117 bool CanWrite(size_t length) const; | 124 bool CanWrite(size_t length) const; |
118 | 125 |
119 scoped_ptr<char[]> buffer_; | 126 scoped_ptr<char[]> buffer_; |
120 size_t capacity_; // Allocation size of payload, set by constructor. | 127 size_t capacity_; // Allocation size of payload, set by constructor. |
121 size_t length_; // Current length of the buffer. | 128 size_t length_; // Current length of the buffer. |
122 }; | 129 }; |
123 | 130 |
124 } // namespace net | 131 } // namespace net |
125 | 132 |
126 #endif // NET_SPDY_SPDY_FRAME_BUILDER_H_ | 133 #endif // NET_SPDY_SPDY_FRAME_BUILDER_H_ |
OLD | NEW |