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

Side by Side Diff: mojo/public/cpp/bindings/lib/pickle_buffer.cc

Issue 1524613002: [mojo] Use base::Pickle for Message storage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/public/cpp/bindings/lib/pickle_buffer.h"
6
7 #include <stdlib.h>
8
9 #include "base/logging.h"
10 #include "mojo/public/cpp/bindings/lib/bindings_serialization.h"
yzshen1 2015/12/15 19:07:02 This is not used. Maybe you want to use internal::
11
12 namespace mojo {
13 namespace internal {
14
15 PickleBuffer::PickleBuffer() : base::Pickle(sizeof(PaddedHeader)) {
16 headerT<PaddedHeader>()->padding = 0;
17 }
18
19 PickleBuffer::~PickleBuffer() {
20 }
21
22 void PickleBuffer::AllocData(uint32_t num_bytes) {
23 AllocUninitializedData(num_bytes);
24 memset(data(), 0, num_bytes);
25 }
26
27 void PickleBuffer::AllocUninitializedData(uint32_t num_bytes) {
28 // Data should only ever be explicitly allocated through AllocData or
29 // AllocUninitializedData if the buffer has no existing data in it yet.
30 DCHECK(payload_size() == 0);
31 Resize(num_bytes);
32 }
33
34 void* PickleBuffer::Allocate(size_t num_bytes) {
35 // The last allocation may terminate in between 8-byte boundaries. Pad the
36 // front of this allocation if that's the case.
37 size_t padding_bytes = (8 - (payload_size() % 8)) % 8;
38 size_t previous_capacity = capacity_after_header();
39 char* p = reinterpret_cast<char*>(ClaimBytes(padding_bytes + num_bytes));
40 DCHECK_EQ(capacity_after_header(), previous_capacity)
41 << "Message buffers must be fully allocated before serialization.";
42 return p + padding_bytes;
43 }
44
45 PickleBuffer* PickleBuffer::AsPickleBuffer() { return this; }
46
47 } // namespace internal
48 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698