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

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

Issue 2740453006: Add QuicStringPiece which is actually StringPiece. (Closed)
Patch Set: fix compile error and rebase Created 3 years, 9 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
« no previous file with comments | « net/quic/core/quic_data_writer.h ('k') | net/quic/core/quic_framer.h » ('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 #include "net/quic/core/quic_data_writer.h" 5 #include "net/quic/core/quic_data_writer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 using base::StringPiece;
11
12 namespace net { 10 namespace net {
13 11
14 QuicDataWriter::QuicDataWriter(size_t size, char* buffer) 12 QuicDataWriter::QuicDataWriter(size_t size, char* buffer)
15 : buffer_(buffer), capacity_(size), length_(0) {} 13 : buffer_(buffer), capacity_(size), length_(0) {}
16 14
17 QuicDataWriter::~QuicDataWriter() {} 15 QuicDataWriter::~QuicDataWriter() {}
18 16
19 char* QuicDataWriter::data() { 17 char* QuicDataWriter::data() {
20 return buffer_; 18 return buffer_;
21 } 19 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 72
75 // Hidden bit (position 11) is set. We should remove it and increment the 73 // Hidden bit (position 11) is set. We should remove it and increment the
76 // exponent. Equivalently, we just add it to the exponent. 74 // exponent. Equivalently, we just add it to the exponent.
77 // This hides the bit. 75 // This hides the bit.
78 result = static_cast<uint16_t>(value + (exponent << kUFloat16MantissaBits)); 76 result = static_cast<uint16_t>(value + (exponent << kUFloat16MantissaBits));
79 } 77 }
80 78
81 return WriteBytes(&result, sizeof(result)); 79 return WriteBytes(&result, sizeof(result));
82 } 80 }
83 81
84 bool QuicDataWriter::WriteStringPiece16(StringPiece val) { 82 bool QuicDataWriter::WriteStringPiece16(QuicStringPiece val) {
85 if (val.size() > std::numeric_limits<uint16_t>::max()) { 83 if (val.size() > std::numeric_limits<uint16_t>::max()) {
86 return false; 84 return false;
87 } 85 }
88 if (!WriteUInt16(static_cast<uint16_t>(val.size()))) { 86 if (!WriteUInt16(static_cast<uint16_t>(val.size()))) {
89 return false; 87 return false;
90 } 88 }
91 return WriteBytes(val.data(), val.size()); 89 return WriteBytes(val.data(), val.size());
92 } 90 }
93 91
94 char* QuicDataWriter::BeginWrite(size_t length) { 92 char* QuicDataWriter::BeginWrite(size_t length) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 void QuicDataWriter::WritePadding() { 132 void QuicDataWriter::WritePadding() {
135 DCHECK_LE(length_, capacity_); 133 DCHECK_LE(length_, capacity_);
136 if (length_ > capacity_) { 134 if (length_ > capacity_) {
137 return; 135 return;
138 } 136 }
139 memset(buffer_ + length_, 0x00, capacity_ - length_); 137 memset(buffer_ + length_, 0x00, capacity_ - length_);
140 length_ = capacity_; 138 length_ = capacity_;
141 } 139 }
142 140
143 } // namespace net 141 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_data_writer.h ('k') | net/quic/core/quic_framer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698