| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 buffer_ = NULL; | 42 buffer_ = NULL; |
| 43 capacity_ = 0; | 43 capacity_ = 0; |
| 44 length_ = 0; | 44 length_ = 0; |
| 45 return rv; | 45 return rv; |
| 46 } | 46 } |
| 47 | 47 |
| 48 // Methods for adding to the payload. These values are appended to the end | 48 // Methods for adding to the payload. These values are appended to the end |
| 49 // of the SpdyFrameBuilder payload. Note - binary integers are converted from | 49 // of the SpdyFrameBuilder payload. Note - binary integers are converted from |
| 50 // host to network form. | 50 // host to network form. |
| 51 bool WriteUInt16(uint16 value) { | 51 bool WriteUInt16(uint16 value) { |
| 52 value = htons(value); | 52 value = base::HostToNet16(value); |
| 53 return WriteBytes(&value, sizeof(value)); | 53 return WriteBytes(&value, sizeof(value)); |
| 54 } | 54 } |
| 55 bool WriteUInt32(uint32 value) { | 55 bool WriteUInt32(uint32 value) { |
| 56 value = htonl(value); | 56 value = base::HostToNet32(value); |
| 57 return WriteBytes(&value, sizeof(value)); | 57 return WriteBytes(&value, sizeof(value)); |
| 58 } | 58 } |
| 59 // TODO(hkhalil) Rename to WriteStringPiece16(). | 59 // TODO(hkhalil) Rename to WriteStringPiece16(). |
| 60 bool WriteString(const std::string& value); | 60 bool WriteString(const std::string& value); |
| 61 bool WriteStringPiece32(const base::StringPiece& value); | 61 bool WriteStringPiece32(const base::StringPiece& value); |
| 62 bool WriteBytes(const void* data, uint32 data_len); | 62 bool WriteBytes(const void* data, uint32 data_len); |
| 63 | 63 |
| 64 // Write an integer to a particular offset in the data buffer. | 64 // Write an integer to a particular offset in the data buffer. |
| 65 bool WriteUInt32ToOffset(int offset, uint32 value) { | 65 bool WriteUInt32ToOffset(int offset, uint32 value) { |
| 66 value = htonl(value); | 66 value = base::HostToNet32(value); |
| 67 return WriteBytesToOffset(offset, &value, sizeof(value)); | 67 return WriteBytesToOffset(offset, &value, sizeof(value)); |
| 68 } | 68 } |
| 69 | 69 |
| 70 // Write to a particular offset in the data buffer. | 70 // Write to a particular offset in the data buffer. |
| 71 bool WriteBytesToOffset(int offset, const void* data, uint32 data_len) { | 71 bool WriteBytesToOffset(int offset, const void* data, uint32 data_len) { |
| 72 if (offset + data_len > length_) | 72 if (offset + data_len > length_) |
| 73 return false; | 73 return false; |
| 74 char *ptr = buffer_ + offset; | 74 char *ptr = buffer_ + offset; |
| 75 memcpy(ptr, data, data_len); | 75 memcpy(ptr, data, data_len); |
| 76 return true; | 76 return true; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 private: | 124 private: |
| 125 char* buffer_; | 125 char* buffer_; |
| 126 size_t capacity_; // Allocation size of payload (or -1 if buffer is const). | 126 size_t capacity_; // Allocation size of payload (or -1 if buffer is const). |
| 127 size_t length_; // current length of the buffer | 127 size_t length_; // current length of the buffer |
| 128 size_t variable_buffer_offset_; // IF non-zero, then offset to a buffer. | 128 size_t variable_buffer_offset_; // IF non-zero, then offset to a buffer. |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 } // namespace spdy | 131 } // namespace spdy |
| 132 | 132 |
| 133 #endif // NET_SPDY_SPDY_FRAME_BUILDER_H_ | 133 #endif // NET_SPDY_SPDY_FRAME_BUILDER_H_ |
| OLD | NEW |