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

Side by Side Diff: base/pickle.cc

Issue 1001833005: Update from https://crrev.com/320343 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Supress 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::ReadWString(std::wstring* result) { 155 bool PickleIterator::ReadStringPiece(base::StringPiece* result) {
156 int len; 156 int len;
157 if (!ReadInt(&len)) 157 if (!ReadInt(&len))
158 return false; 158 return false;
159 const char* read_from = GetReadPointerAndAdvance(len, sizeof(wchar_t)); 159 const char* read_from = GetReadPointerAndAdvance(len);
160 if (!read_from) 160 if (!read_from)
161 return false; 161 return false;
162 162
163 result->assign(reinterpret_cast<const wchar_t*>(read_from), len); 163 *result = base::StringPiece(read_from, len);
164 return true; 164 return true;
165 } 165 }
166 166
167 bool PickleIterator::ReadString16(string16* result) { 167 bool PickleIterator::ReadString16(string16* result) {
168 int len; 168 int len;
169 if (!ReadInt(&len)) 169 if (!ReadInt(&len))
170 return false; 170 return false;
171 const char* read_from = GetReadPointerAndAdvance(len, sizeof(char16)); 171 const char* read_from = GetReadPointerAndAdvance(len, sizeof(char16));
172 if (!read_from) 172 if (!read_from)
173 return false; 173 return false;
174 174
175 result->assign(reinterpret_cast<const char16*>(read_from), len); 175 result->assign(reinterpret_cast<const char16*>(read_from), len);
176 return true; 176 return true;
177 } 177 }
178 178
179 bool PickleIterator::ReadStringPiece16(base::StringPiece16* result) {
180 int len;
181 if (!ReadInt(&len))
182 return false;
183 const char* read_from = GetReadPointerAndAdvance(len, sizeof(char16));
184 if (!read_from)
185 return false;
186
187 *result = base::StringPiece16(reinterpret_cast<const char16*>(read_from),
188 len);
189 return true;
190 }
191
179 bool PickleIterator::ReadData(const char** data, int* length) { 192 bool PickleIterator::ReadData(const char** data, int* length) {
180 *length = 0; 193 *length = 0;
181 *data = 0; 194 *data = 0;
182 195
183 if (!ReadInt(length)) 196 if (!ReadInt(length))
184 return false; 197 return false;
185 198
186 return ReadBytes(data, *length); 199 return ReadBytes(data, *length);
187 } 200 }
188 201
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 header_ = NULL; 277 header_ = NULL;
265 header_size_ = other.header_size_; 278 header_size_ = other.header_size_;
266 } 279 }
267 Resize(other.header_->payload_size); 280 Resize(other.header_->payload_size);
268 memcpy(header_, other.header_, 281 memcpy(header_, other.header_,
269 other.header_size_ + other.header_->payload_size); 282 other.header_size_ + other.header_->payload_size);
270 write_offset_ = other.write_offset_; 283 write_offset_ = other.write_offset_;
271 return *this; 284 return *this;
272 } 285 }
273 286
274 bool Pickle::WriteString(const std::string& value) { 287 bool Pickle::WriteString(const base::StringPiece& value) {
275 if (!WriteInt(static_cast<int>(value.size()))) 288 if (!WriteInt(static_cast<int>(value.size())))
276 return false; 289 return false;
277 290
278 return WriteBytes(value.data(), static_cast<int>(value.size())); 291 return WriteBytes(value.data(), static_cast<int>(value.size()));
279 } 292 }
280 293
281 bool Pickle::WriteWString(const std::wstring& value) { 294 bool Pickle::WriteString16(const base::StringPiece16& value) {
282 if (!WriteInt(static_cast<int>(value.size()))) 295 if (!WriteInt(static_cast<int>(value.size())))
283 return false; 296 return false;
284 297
285 return WriteBytes(value.data(),
286 static_cast<int>(value.size() * sizeof(wchar_t)));
287 }
288
289 bool Pickle::WriteString16(const string16& value) {
290 if (!WriteInt(static_cast<int>(value.size())))
291 return false;
292
293 return WriteBytes(value.data(), 298 return WriteBytes(value.data(),
294 static_cast<int>(value.size()) * sizeof(char16)); 299 static_cast<int>(value.size()) * sizeof(char16));
295 } 300 }
296 301
297 bool Pickle::WriteData(const char* data, int length) { 302 bool Pickle::WriteData(const char* data, int length) {
298 return length >= 0 && WriteInt(length) && WriteBytes(data, length); 303 return length >= 0 && WriteInt(length) && WriteBytes(data, length);
299 } 304 }
300 305
301 bool Pickle::WriteBytes(const void* data, int length) { 306 bool Pickle::WriteBytes(const void* data, int length) {
302 WriteBytesCommon(data, length); 307 WriteBytesCommon(data, length);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 if (new_size > capacity_after_header_) { 368 if (new_size > capacity_after_header_) {
364 Resize(std::max(capacity_after_header_ * 2, new_size)); 369 Resize(std::max(capacity_after_header_ * 2, new_size));
365 } 370 }
366 371
367 char* write = mutable_payload() + write_offset_; 372 char* write = mutable_payload() + write_offset_;
368 memcpy(write, data, length); 373 memcpy(write, data, length);
369 memset(write + length, 0, data_len - length); 374 memset(write + length, 0, data_len - length);
370 header_->payload_size = static_cast<uint32>(new_size); 375 header_->payload_size = static_cast<uint32>(new_size);
371 write_offset_ = new_size; 376 write_offset_ = new_size;
372 } 377 }
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