| 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 "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 Loading... |
| 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 |
| 155 bool PickleIterator::ReadWString(std::wstring* result) { | 167 bool PickleIterator::ReadWString(std::wstring* result) { |
| 156 int len; | 168 int len; |
| 157 if (!ReadInt(&len)) | 169 if (!ReadInt(&len)) |
| 158 return false; | 170 return false; |
| 159 const char* read_from = GetReadPointerAndAdvance(len, sizeof(wchar_t)); | 171 const char* read_from = GetReadPointerAndAdvance(len, sizeof(wchar_t)); |
| 160 if (!read_from) | 172 if (!read_from) |
| 161 return false; | 173 return false; |
| 162 | 174 |
| 163 result->assign(reinterpret_cast<const wchar_t*>(read_from), len); | 175 result->assign(reinterpret_cast<const wchar_t*>(read_from), len); |
| 164 return true; | 176 return true; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 header_ = NULL; | 276 header_ = NULL; |
| 265 header_size_ = other.header_size_; | 277 header_size_ = other.header_size_; |
| 266 } | 278 } |
| 267 Resize(other.header_->payload_size); | 279 Resize(other.header_->payload_size); |
| 268 memcpy(header_, other.header_, | 280 memcpy(header_, other.header_, |
| 269 other.header_size_ + other.header_->payload_size); | 281 other.header_size_ + other.header_->payload_size); |
| 270 write_offset_ = other.write_offset_; | 282 write_offset_ = other.write_offset_; |
| 271 return *this; | 283 return *this; |
| 272 } | 284 } |
| 273 | 285 |
| 274 bool Pickle::WriteString(const std::string& value) { | 286 bool Pickle::WriteString(const base::StringPiece& value) |
| 287 { |
| 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::WriteWString(const std::wstring& 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 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 if (new_size > capacity_after_header_) { | 376 if (new_size > capacity_after_header_) { |
| 364 Resize(std::max(capacity_after_header_ * 2, new_size)); | 377 Resize(std::max(capacity_after_header_ * 2, new_size)); |
| 365 } | 378 } |
| 366 | 379 |
| 367 char* write = mutable_payload() + write_offset_; | 380 char* write = mutable_payload() + write_offset_; |
| 368 memcpy(write, data, length); | 381 memcpy(write, data, length); |
| 369 memset(write + length, 0, data_len - length); | 382 memset(write + length, 0, data_len - length); |
| 370 header_->payload_size = static_cast<uint32>(new_size); | 383 header_->payload_size = static_cast<uint32>(new_size); |
| 371 write_offset_ = new_size; | 384 write_offset_ = new_size; |
| 372 } | 385 } |
| OLD | NEW |