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

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

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months 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 | Annotate | Revision Log
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 #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)
20 : buffer_(new char[size]), 20 : buffer_(new char[size]), capacity_(size), length_(0) {
21 capacity_(size),
22 length_(0) {
23 } 21 }
24 22
25 QuicDataWriter::~QuicDataWriter() { 23 QuicDataWriter::~QuicDataWriter() {
26 delete[] buffer_; 24 delete[] buffer_;
27 } 25 }
28 26
29 char* QuicDataWriter::take() { 27 char* QuicDataWriter::take() {
30 char* rv = buffer_; 28 char* rv = buffer_;
31 buffer_ = NULL; 29 buffer_ = NULL;
32 capacity_ = 0; 30 capacity_ = 0;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 if (val.length() > numeric_limits<uint16>::max()) { 97 if (val.length() > numeric_limits<uint16>::max()) {
100 return false; 98 return false;
101 } 99 }
102 if (!WriteUInt16(val.size())) { 100 if (!WriteUInt16(val.size())) {
103 return false; 101 return false;
104 } 102 }
105 return WriteBytes(val.data(), val.size()); 103 return WriteBytes(val.data(), val.size());
106 } 104 }
107 105
108 bool QuicDataWriter::WriteIOVector(const IOVector& data) { 106 bool QuicDataWriter::WriteIOVector(const IOVector& data) {
109 char *dest = BeginWrite(data.TotalBufferSize()); 107 char* dest = BeginWrite(data.TotalBufferSize());
110 if (!dest) { 108 if (!dest) {
111 return false; 109 return false;
112 } 110 }
113 for (size_t i = 0; i < data.Size(); ++i) { 111 for (size_t i = 0; i < data.Size(); ++i) {
114 WriteBytes(data.iovec()[i].iov_base, data.iovec()[i].iov_len); 112 WriteBytes(data.iovec()[i].iov_base, data.iovec()[i].iov_len);
115 } 113 }
116 114
117 return true; 115 return true;
118 } 116 }
119 117
120 char* QuicDataWriter::BeginWrite(size_t length) { 118 char* QuicDataWriter::BeginWrite(size_t length) {
121 if (length_ > capacity_) { 119 if (length_ > capacity_) {
122 return NULL; 120 return NULL;
123 } 121 }
124 122
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 DCHECK_LT(offset, capacity_); 191 DCHECK_LT(offset, capacity_);
194 size_t latched_length = length_; 192 size_t latched_length = length_;
195 length_ = offset; 193 length_ = offset;
196 bool success = WriteUInt48(value); 194 bool success = WriteUInt48(value);
197 DCHECK_LE(length_, latched_length); 195 DCHECK_LE(length_, latched_length);
198 length_ = latched_length; 196 length_ = latched_length;
199 return success; 197 return success;
200 } 198 }
201 199
202 } // namespace net 200 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698