OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <limits> | 9 #include <limits> |
10 #include <string> | 10 #include <string> |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 if (!IteratorHasRoomFor(*iter, len * sizeof(wchar_t))) | 211 if (!IteratorHasRoomFor(*iter, len * sizeof(wchar_t))) |
212 return false; | 212 return false; |
213 | 213 |
214 wchar_t* chars = reinterpret_cast<wchar_t*>(*iter); | 214 wchar_t* chars = reinterpret_cast<wchar_t*>(*iter); |
215 result->assign(chars, len); | 215 result->assign(chars, len); |
216 | 216 |
217 UpdateIter(iter, len * sizeof(wchar_t)); | 217 UpdateIter(iter, len * sizeof(wchar_t)); |
218 return true; | 218 return true; |
219 } | 219 } |
220 | 220 |
| 221 bool Pickle::ReadString16(void** iter, string16* result) const { |
| 222 DCHECK(iter); |
| 223 |
| 224 int len; |
| 225 if (!ReadLength(iter, &len)) |
| 226 return false; |
| 227 if (!IteratorHasRoomFor(*iter, len)) |
| 228 return false; |
| 229 |
| 230 char16* chars = reinterpret_cast<char16*>(*iter); |
| 231 result->assign(chars, len); |
| 232 |
| 233 UpdateIter(iter, len * sizeof(char16)); |
| 234 return true; |
| 235 } |
| 236 |
221 bool Pickle::ReadBytes(void** iter, const char** data, int length) const { | 237 bool Pickle::ReadBytes(void** iter, const char** data, int length) const { |
222 DCHECK(iter); | 238 DCHECK(iter); |
223 DCHECK(data); | 239 DCHECK(data); |
224 | 240 |
225 if (!IteratorHasRoomFor(*iter, length)) | 241 if (!IteratorHasRoomFor(*iter, length)) |
226 return false; | 242 return false; |
227 | 243 |
228 *data = reinterpret_cast<const char*>(*iter); | 244 *data = reinterpret_cast<const char*>(*iter); |
229 | 245 |
230 UpdateIter(iter, length); | 246 UpdateIter(iter, length); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 return false; | 299 return false; |
284 | 300 |
285 return WriteBytes(value.data(), static_cast<int>(value.size())); | 301 return WriteBytes(value.data(), static_cast<int>(value.size())); |
286 } | 302 } |
287 | 303 |
288 bool Pickle::WriteWString(const std::wstring& value) { | 304 bool Pickle::WriteWString(const std::wstring& value) { |
289 if (!WriteInt(static_cast<int>(value.size()))) | 305 if (!WriteInt(static_cast<int>(value.size()))) |
290 return false; | 306 return false; |
291 | 307 |
292 return WriteBytes(value.data(), | 308 return WriteBytes(value.data(), |
293 static_cast<int>(value.size() * sizeof(value.data()[0]))); | 309 static_cast<int>(value.size() * sizeof(wchar_t))); |
| 310 } |
| 311 |
| 312 bool Pickle::WriteString16(const string16& value) { |
| 313 if (!WriteInt(static_cast<int>(value.size()))) |
| 314 return false; |
| 315 |
| 316 return WriteBytes(value.data(), |
| 317 static_cast<int>(value.size()) * sizeof(char16)); |
294 } | 318 } |
295 | 319 |
296 bool Pickle::WriteData(const char* data, int length) { | 320 bool Pickle::WriteData(const char* data, int length) { |
297 return WriteInt(length) && WriteBytes(data, length); | 321 return WriteInt(length) && WriteBytes(data, length); |
298 } | 322 } |
299 | 323 |
300 char* Pickle::BeginWriteData(int length) { | 324 char* Pickle::BeginWriteData(int length) { |
301 DCHECK_EQ(variable_buffer_offset_, 0U) << | 325 DCHECK_EQ(variable_buffer_offset_, 0U) << |
302 "There can only be one variable buffer in a Pickle"; | 326 "There can only be one variable buffer in a Pickle"; |
303 | 327 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 | 379 |
356 const Header* hdr = reinterpret_cast<const Header*>(start); | 380 const Header* hdr = reinterpret_cast<const Header*>(start); |
357 const char* payload_base = start + header_size; | 381 const char* payload_base = start + header_size; |
358 const char* payload_end = payload_base + hdr->payload_size; | 382 const char* payload_end = payload_base + hdr->payload_size; |
359 if (payload_end < payload_base) | 383 if (payload_end < payload_base) |
360 return NULL; | 384 return NULL; |
361 | 385 |
362 return (payload_end > end) ? NULL : payload_end; | 386 return (payload_end > end) ? NULL : payload_end; |
363 } | 387 } |
364 | 388 |
OLD | NEW |