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

Side by Side Diff: base/pickle.cc

Issue 981853002: Revert of Adding StringPiece read/write support to pickle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 | « base/pickle.h ('k') | base/pickle_unittest.cc » ('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 "base/pickle.h" 5 #include "base/pickle.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include <algorithm> // for max() 9 #include <algorithm> // for max()
10 10
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 if (!ReadInt(&len)) 145 if (!ReadInt(&len))
146 return false; 146 return false;
147 const char* read_from = GetReadPointerAndAdvance(len); 147 const char* read_from = GetReadPointerAndAdvance(len);
148 if (!read_from) 148 if (!read_from)
149 return false; 149 return false;
150 150
151 result->assign(read_from, len); 151 result->assign(read_from, len);
152 return true; 152 return true;
153 } 153 }
154 154
155 bool PickleIterator::ReadStringPiece(base::StringPiece* result) {
156 int len;
157 if (!ReadInt(&len))
158 return false;
159 const char* read_from = GetReadPointerAndAdvance(len);
160 if (!read_from)
161 return false;
162
163 *result = base::StringPiece(read_from, len);
164 return true;
165 }
166
167 bool PickleIterator::ReadWString(std::wstring* result) { 155 bool PickleIterator::ReadWString(std::wstring* result) {
168 int len; 156 int len;
169 if (!ReadInt(&len)) 157 if (!ReadInt(&len))
170 return false; 158 return false;
171 const char* read_from = GetReadPointerAndAdvance(len, sizeof(wchar_t)); 159 const char* read_from = GetReadPointerAndAdvance(len, sizeof(wchar_t));
172 if (!read_from) 160 if (!read_from)
173 return false; 161 return false;
174 162
175 result->assign(reinterpret_cast<const wchar_t*>(read_from), len); 163 result->assign(reinterpret_cast<const wchar_t*>(read_from), len);
176 return true; 164 return true;
177 } 165 }
178 166
179 bool PickleIterator::ReadString16(string16* result) { 167 bool PickleIterator::ReadString16(string16* result) {
180 int len; 168 int len;
181 if (!ReadInt(&len)) 169 if (!ReadInt(&len))
182 return false; 170 return false;
183 const char* read_from = GetReadPointerAndAdvance(len, sizeof(char16)); 171 const char* read_from = GetReadPointerAndAdvance(len, sizeof(char16));
184 if (!read_from) 172 if (!read_from)
185 return false; 173 return false;
186 174
187 result->assign(reinterpret_cast<const char16*>(read_from), len); 175 result->assign(reinterpret_cast<const char16*>(read_from), len);
188 return true; 176 return true;
189 } 177 }
190 178
191 bool PickleIterator::ReadStringPiece16(base::StringPiece16* result) {
192 int len;
193 if (!ReadInt(&len))
194 return false;
195 const char* read_from = GetReadPointerAndAdvance(len, sizeof(char16));
196 if (!read_from)
197 return false;
198
199 *result = base::StringPiece16(reinterpret_cast<const char16*>(read_from),
200 len);
201 return true;
202 }
203
204 bool PickleIterator::ReadData(const char** data, int* length) { 179 bool PickleIterator::ReadData(const char** data, int* length) {
205 *length = 0; 180 *length = 0;
206 *data = 0; 181 *data = 0;
207 182
208 if (!ReadInt(length)) 183 if (!ReadInt(length))
209 return false; 184 return false;
210 185
211 return ReadBytes(data, *length); 186 return ReadBytes(data, *length);
212 } 187 }
213 188
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 header_ = NULL; 264 header_ = NULL;
290 header_size_ = other.header_size_; 265 header_size_ = other.header_size_;
291 } 266 }
292 Resize(other.header_->payload_size); 267 Resize(other.header_->payload_size);
293 memcpy(header_, other.header_, 268 memcpy(header_, other.header_,
294 other.header_size_ + other.header_->payload_size); 269 other.header_size_ + other.header_->payload_size);
295 write_offset_ = other.write_offset_; 270 write_offset_ = other.write_offset_;
296 return *this; 271 return *this;
297 } 272 }
298 273
299 bool Pickle::WriteString(const base::StringPiece& value) { 274 bool Pickle::WriteString(const std::string& value) {
300 if (!WriteInt(static_cast<int>(value.size()))) 275 if (!WriteInt(static_cast<int>(value.size())))
301 return false; 276 return false;
302 277
303 return WriteBytes(value.data(), static_cast<int>(value.size())); 278 return WriteBytes(value.data(), static_cast<int>(value.size()));
304 } 279 }
305 280
306 bool Pickle::WriteWString(const std::wstring& value) { 281 bool Pickle::WriteWString(const std::wstring& value) {
307 if (!WriteInt(static_cast<int>(value.size()))) 282 if (!WriteInt(static_cast<int>(value.size())))
308 return false; 283 return false;
309 284
310 return WriteBytes(value.data(), 285 return WriteBytes(value.data(),
311 static_cast<int>(value.size() * sizeof(wchar_t))); 286 static_cast<int>(value.size() * sizeof(wchar_t)));
312 } 287 }
313 288
314 bool Pickle::WriteString16(const base::StringPiece16& value) { 289 bool Pickle::WriteString16(const string16& value) {
315 if (!WriteInt(static_cast<int>(value.size()))) 290 if (!WriteInt(static_cast<int>(value.size())))
316 return false; 291 return false;
317 292
318 return WriteBytes(value.data(), 293 return WriteBytes(value.data(),
319 static_cast<int>(value.size()) * sizeof(char16)); 294 static_cast<int>(value.size()) * sizeof(char16));
320 } 295 }
321 296
322 bool Pickle::WriteData(const char* data, int length) { 297 bool Pickle::WriteData(const char* data, int length) {
323 return length >= 0 && WriteInt(length) && WriteBytes(data, length); 298 return length >= 0 && WriteInt(length) && WriteBytes(data, length);
324 } 299 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 if (new_size > capacity_after_header_) { 363 if (new_size > capacity_after_header_) {
389 Resize(std::max(capacity_after_header_ * 2, new_size)); 364 Resize(std::max(capacity_after_header_ * 2, new_size));
390 } 365 }
391 366
392 char* write = mutable_payload() + write_offset_; 367 char* write = mutable_payload() + write_offset_;
393 memcpy(write, data, length); 368 memcpy(write, data, length);
394 memset(write + length, 0, data_len - length); 369 memset(write + length, 0, data_len - length);
395 header_->payload_size = static_cast<uint32>(new_size); 370 header_->payload_size = static_cast<uint32>(new_size);
396 write_offset_ = new_size; 371 write_offset_ = new_size;
397 } 372 }
OLDNEW
« no previous file with comments | « base/pickle.h ('k') | base/pickle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698