| 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 #include "net/quic/quic_data_writer.h" | 5 #include "net/quic/quic_data_writer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 | 13 |
| 14 using base::StringPiece; | 14 using base::StringPiece; |
| 15 using std::numeric_limits; | 15 using std::numeric_limits; |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 | 18 |
| 19 QuicDataWriter::QuicDataWriter(size_t size) | 19 QuicDataWriter::QuicDataWriter(size_t size, char* buffer) |
| 20 : buffer_(new char[size]), | 20 : buffer_(buffer), capacity_(size), length_(0) { |
| 21 capacity_(size), | |
| 22 length_(0) { | |
| 23 } | 21 } |
| 24 | 22 |
| 25 QuicDataWriter::~QuicDataWriter() { | 23 QuicDataWriter::~QuicDataWriter() { |
| 26 delete[] buffer_; | |
| 27 } | 24 } |
| 28 | 25 |
| 29 char* QuicDataWriter::take() { | 26 char* QuicDataWriter::data() { |
| 30 char* rv = buffer_; | 27 return buffer_; |
| 31 buffer_ = nullptr; | |
| 32 capacity_ = 0; | |
| 33 length_ = 0; | |
| 34 return rv; | |
| 35 } | 28 } |
| 36 | 29 |
| 37 bool QuicDataWriter::WriteUInt8(uint8 value) { | 30 bool QuicDataWriter::WriteUInt8(uint8 value) { |
| 38 return WriteBytes(&value, sizeof(value)); | 31 return WriteBytes(&value, sizeof(value)); |
| 39 } | 32 } |
| 40 | 33 |
| 41 bool QuicDataWriter::WriteUInt16(uint16 value) { | 34 bool QuicDataWriter::WriteUInt16(uint16 value) { |
| 42 return WriteBytes(&value, sizeof(value)); | 35 return WriteBytes(&value, sizeof(value)); |
| 43 } | 36 } |
| 44 | 37 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 DCHECK_LT(offset, capacity_); | 186 DCHECK_LT(offset, capacity_); |
| 194 size_t latched_length = length_; | 187 size_t latched_length = length_; |
| 195 length_ = offset; | 188 length_ = offset; |
| 196 bool success = WriteUInt48(value); | 189 bool success = WriteUInt48(value); |
| 197 DCHECK_LE(length_, latched_length); | 190 DCHECK_LE(length_, latched_length); |
| 198 length_ = latched_length; | 191 length_ = latched_length; |
| 199 return success; | 192 return success; |
| 200 } | 193 } |
| 201 | 194 |
| 202 } // namespace net | 195 } // namespace net |
| OLD | NEW |