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

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

Issue 2112093002: Mojo C++ bindings: Merge EncodePointers/DecodePointers into Serialize/Deserialize, respectively. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@61_array_fix
Patch Set: . Created 4 years, 5 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
OLDNEW
(Empty)
1 // Copyright 2013 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/serialization_util.h"
6
7 namespace mojo {
8 namespace internal {
9
10 namespace {
11
12 const size_t kAlignment = 8;
13
14 template <typename T>
15 T AlignImpl(T t) {
16 return t + (kAlignment - (t % kAlignment)) % kAlignment;
17 }
18
19 } // namespace
20
21 size_t Align(size_t size) {
22 return AlignImpl(size);
23 }
24
25 char* AlignPointer(char* ptr) {
26 return reinterpret_cast<char*>(AlignImpl(reinterpret_cast<uintptr_t>(ptr)));
27 }
28
29 bool IsAligned(const void* ptr) {
30 return !(reinterpret_cast<uintptr_t>(ptr) % kAlignment);
31 }
32
33 void EncodePointer(const void* ptr, uint64_t* offset) {
34 if (!ptr) {
35 *offset = 0;
36 return;
37 }
38
39 const char* p_obj = reinterpret_cast<const char*>(ptr);
40 const char* p_slot = reinterpret_cast<const char*>(offset);
41 DCHECK(p_obj > p_slot);
42
43 *offset = static_cast<uint64_t>(p_obj - p_slot);
44 }
45
46 const void* DecodePointerRaw(const uint64_t* offset) {
47 if (!*offset)
48 return nullptr;
49 return reinterpret_cast<const char*>(offset) + *offset;
50 }
51
52 } // namespace internal
53 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/serialization_util.h ('k') | mojo/public/cpp/bindings/lib/validation_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698