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 #include <limits> | 10 #include <limits> |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 } | 201 } |
202 | 202 |
203 bool PickleIterator::ReadBytes(const char** data, int length) { | 203 bool PickleIterator::ReadBytes(const char** data, int length) { |
204 const char* read_from = GetReadPointerAndAdvance(length); | 204 const char* read_from = GetReadPointerAndAdvance(length); |
205 if (!read_from) | 205 if (!read_from) |
206 return false; | 206 return false; |
207 *data = read_from; | 207 *data = read_from; |
208 return true; | 208 return true; |
209 } | 209 } |
210 | 210 |
| 211 PickleSizer::PickleSizer() {} |
| 212 |
| 213 PickleSizer::~PickleSizer() {} |
| 214 |
| 215 void PickleSizer::AddString(const StringPiece& value) { |
| 216 AddInt(); |
| 217 AddBytes(static_cast<int>(value.size())); |
| 218 } |
| 219 |
| 220 void PickleSizer::AddString16(const StringPiece16& value) { |
| 221 AddInt(); |
| 222 AddBytes(static_cast<int>(value.size() * sizeof(char16))); |
| 223 } |
| 224 |
| 225 void PickleSizer::AddData(int length) { |
| 226 CHECK_GE(length, 0); |
| 227 AddInt(); |
| 228 AddBytes(length); |
| 229 } |
| 230 |
| 231 void PickleSizer::AddBytes(int length) { |
| 232 payload_size_ += bits::Align(length, sizeof(uint32_t)); |
| 233 } |
| 234 |
| 235 template <size_t length> void PickleSizer::AddBytesStatic() { |
| 236 DCHECK_LE(length, static_cast<size_t>(std::numeric_limits<int>::max())); |
| 237 AddBytes(length); |
| 238 } |
| 239 |
| 240 template void PickleSizer::AddBytesStatic<2>(); |
| 241 template void PickleSizer::AddBytesStatic<4>(); |
| 242 template void PickleSizer::AddBytesStatic<8>(); |
| 243 |
211 Pickle::Attachment::Attachment() {} | 244 Pickle::Attachment::Attachment() {} |
212 | 245 |
213 Pickle::Attachment::~Attachment() {} | 246 Pickle::Attachment::~Attachment() {} |
214 | 247 |
215 // Payload is uint32_t aligned. | 248 // Payload is uint32_t aligned. |
216 | 249 |
217 Pickle::Pickle() | 250 Pickle::Pickle() |
218 : header_(NULL), | 251 : header_(NULL), |
219 header_size_(sizeof(Header)), | 252 header_size_(sizeof(Header)), |
220 capacity_after_header_(0), | 253 capacity_after_header_(0), |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 | 469 |
437 inline void Pickle::WriteBytesCommon(const void* data, size_t length) { | 470 inline void Pickle::WriteBytesCommon(const void* data, size_t length) { |
438 DCHECK_NE(kCapacityReadOnly, capacity_after_header_) | 471 DCHECK_NE(kCapacityReadOnly, capacity_after_header_) |
439 << "oops: pickle is readonly"; | 472 << "oops: pickle is readonly"; |
440 MSAN_CHECK_MEM_IS_INITIALIZED(data, length); | 473 MSAN_CHECK_MEM_IS_INITIALIZED(data, length); |
441 void* write = ClaimUninitializedBytesInternal(length); | 474 void* write = ClaimUninitializedBytesInternal(length); |
442 memcpy(write, data, length); | 475 memcpy(write, data, length); |
443 } | 476 } |
444 | 477 |
445 } // namespace base | 478 } // namespace base |
OLD | NEW |