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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/cpp/bindings/lib/pickle_buffer.cc
diff --git a/mojo/public/cpp/bindings/lib/pickle_buffer.cc b/mojo/public/cpp/bindings/lib/pickle_buffer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b3daa4bbaf12d269e2bb1c8d244ceac42ff2009b
--- /dev/null
+++ b/mojo/public/cpp/bindings/lib/pickle_buffer.cc
@@ -0,0 +1,48 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/public/cpp/bindings/lib/pickle_buffer.h"
+
+#include <stdlib.h>
+
+#include "base/logging.h"
+#include "mojo/public/cpp/bindings/lib/bindings_serialization.h"
+
+namespace mojo {
+namespace internal {
+
+PickleBuffer::PickleBuffer() : base::Pickle(sizeof(PaddedHeader)) {
+ headerT<PaddedHeader>()->padding = 0;
+}
+
+PickleBuffer::~PickleBuffer() {
+}
+
+void PickleBuffer::AllocData(uint32_t num_bytes) {
+ AllocUninitializedData(num_bytes);
+ memset(data(), 0, num_bytes);
+}
+
+void PickleBuffer::AllocUninitializedData(uint32_t num_bytes) {
+ // Data should only ever be explicitly allocated through AllocData or
+ // AllocUninitializedData if the buffer has no existing data in it yet.
+ DCHECK(payload_size() == 0);
+ Resize(num_bytes);
+}
+
+void* PickleBuffer::Allocate(size_t num_bytes) {
+ // The last allocation may terminate in between 8-byte boundaries. Pad the
+ // front of this allocation if that's the case.
+ size_t padding_bytes = (8 - (payload_size() % 8)) % 8;
+ size_t previous_capacity = capacity_after_header();
+ char* p = reinterpret_cast<char*>(ClaimBytes(padding_bytes + num_bytes));
+ DCHECK_EQ(capacity_after_header(), previous_capacity)
+ << "Message buffers must be fully allocated before serialization.";
+ return p + padding_bytes;
+}
+
+PickleBuffer* PickleBuffer::AsPickleBuffer() { return this; }
+
+} // namespace internal
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698