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

Side by Side Diff: base/pickle.cc

Issue 297011: Add Pickle::Read/WriteUint64. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « base/pickle.h ('k') | no next file » | 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) 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 <algorithm> // for max()
9 #include <limits> 10 #include <limits>
10 #include <string>
11 11
12 //------------------------------------------------------------------------------ 12 //------------------------------------------------------------------------------
13 13
14 // static 14 // static
15 const int Pickle::kPayloadUnit = 64; 15 const int Pickle::kPayloadUnit = 64;
16 16
17 // We mark a read only pickle with a special capacity_. 17 // We mark a read only pickle with a special capacity_.
18 static const size_t kCapacityReadOnly = std::numeric_limits<size_t>::max(); 18 static const size_t kCapacityReadOnly = std::numeric_limits<size_t>::max();
19 19
20 // Payload is uint32 aligned. 20 // Payload is uint32 aligned.
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 if (!IteratorHasRoomFor(*iter, sizeof(*result))) 175 if (!IteratorHasRoomFor(*iter, sizeof(*result)))
176 return false; 176 return false;
177 177
178 memcpy(result, *iter, sizeof(*result)); 178 memcpy(result, *iter, sizeof(*result));
179 179
180 UpdateIter(iter, sizeof(*result)); 180 UpdateIter(iter, sizeof(*result));
181 return true; 181 return true;
182 } 182 }
183 183
184 bool Pickle::ReadUInt64(void** iter, uint64* result) const {
185 DCHECK(iter);
186 if (!*iter)
187 *iter = const_cast<char*>(payload());
188
189 if (!IteratorHasRoomFor(*iter, sizeof(*result)))
190 return false;
191
192 memcpy(result, *iter, sizeof(*result));
193
194 UpdateIter(iter, sizeof(*result));
195 return true;
196 }
197
184 bool Pickle::ReadIntPtr(void** iter, intptr_t* result) const { 198 bool Pickle::ReadIntPtr(void** iter, intptr_t* result) const {
185 DCHECK(iter); 199 DCHECK(iter);
186 if (!*iter) 200 if (!*iter)
187 *iter = const_cast<char*>(payload()); 201 *iter = const_cast<char*>(payload());
188 202
189 if (!IteratorHasRoomFor(*iter, sizeof(*result))) 203 if (!IteratorHasRoomFor(*iter, sizeof(*result)))
190 return false; 204 return false;
191 205
192 memcpy(result, *iter, sizeof(*result)); 206 memcpy(result, *iter, sizeof(*result));
193 207
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 variable_buffer_offset_ = 362 variable_buffer_offset_ =
349 data_ptr - reinterpret_cast<char*>(header_) - sizeof(int); 363 data_ptr - reinterpret_cast<char*>(header_) - sizeof(int);
350 364
351 // EndWrite doesn't necessarily have to be called after the write operation, 365 // EndWrite doesn't necessarily have to be called after the write operation,
352 // so we call it here to pad out what the caller will eventually write. 366 // so we call it here to pad out what the caller will eventually write.
353 EndWrite(data_ptr, length); 367 EndWrite(data_ptr, length);
354 return data_ptr; 368 return data_ptr;
355 } 369 }
356 370
357 void Pickle::TrimWriteData(int new_length) { 371 void Pickle::TrimWriteData(int new_length) {
358 DCHECK(variable_buffer_offset_ != 0); 372 DCHECK_NE(variable_buffer_offset_, 0);
359 373
360 // Fetch the the variable buffer size 374 // Fetch the the variable buffer size
361 int* cur_length = reinterpret_cast<int*>( 375 int* cur_length = reinterpret_cast<int*>(
362 reinterpret_cast<char*>(header_) + variable_buffer_offset_); 376 reinterpret_cast<char*>(header_) + variable_buffer_offset_);
363 377
364 if (new_length < 0 || new_length > *cur_length) { 378 if (new_length < 0 || new_length > *cur_length) {
365 NOTREACHED() << "Invalid length in TrimWriteData."; 379 NOTREACHED() << "Invalid length in TrimWriteData.";
366 return; 380 return;
367 } 381 }
368 382
(...skipping 23 matching lines...) Expand all
392 DCHECK(header_size <= static_cast<size_t>(kPayloadUnit)); 406 DCHECK(header_size <= static_cast<size_t>(kPayloadUnit));
393 407
394 const Header* hdr = reinterpret_cast<const Header*>(start); 408 const Header* hdr = reinterpret_cast<const Header*>(start);
395 const char* payload_base = start + header_size; 409 const char* payload_base = start + header_size;
396 const char* payload_end = payload_base + hdr->payload_size; 410 const char* payload_end = payload_base + hdr->payload_size;
397 if (payload_end < payload_base) 411 if (payload_end < payload_base)
398 return NULL; 412 return NULL;
399 413
400 return (payload_end > end) ? NULL : payload_end; 414 return (payload_end > end) ? NULL : payload_end;
401 } 415 }
OLDNEW
« no previous file with comments | « base/pickle.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698