| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "mojo/public/bindings/lib/bindings_serialization.h" | 5 #include "mojo/public/bindings/lib/bindings_serialization.h" |
| 6 | 6 |
| 7 #include <assert.h> | 7 #include <assert.h> |
| 8 | 8 |
| 9 #include "mojo/public/bindings/lib/bindings_internal.h" |
| 10 |
| 9 namespace mojo { | 11 namespace mojo { |
| 10 namespace internal { | 12 namespace internal { |
| 11 | 13 |
| 12 size_t Align(size_t size) { | 14 size_t Align(size_t size) { |
| 13 const size_t kAlignment = 8; | 15 const size_t kAlignment = 8; |
| 14 return size + (kAlignment - (size % kAlignment)) % kAlignment; | 16 return size + (kAlignment - (size % kAlignment)) % kAlignment; |
| 15 } | 17 } |
| 16 | 18 |
| 17 void EncodePointer(const void* ptr, uint64_t* offset) { | 19 void EncodePointer(const void* ptr, uint64_t* offset) { |
| 18 if (!ptr) { | 20 if (!ptr) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 *handle = Handle(); | 62 *handle = Handle(); |
| 61 return true; | 63 return true; |
| 62 } | 64 } |
| 63 if (handle->value() >= handles->size()) | 65 if (handle->value() >= handles->size()) |
| 64 return false; | 66 return false; |
| 65 // Just leave holes in the vector so we don't screw up other indices. | 67 // Just leave holes in the vector so we don't screw up other indices. |
| 66 *handle = FetchAndReset(&handles->at(handle->value())); | 68 *handle = FetchAndReset(&handles->at(handle->value())); |
| 67 return true; | 69 return true; |
| 68 } | 70 } |
| 69 | 71 |
| 70 // static | |
| 71 void ArrayHelper<Handle>::EncodePointersAndHandles( | |
| 72 const ArrayHeader* header, | |
| 73 ElementType* elements, | |
| 74 std::vector<Handle>* handles) { | |
| 75 for (uint32_t i = 0; i < header->num_elements; ++i) | |
| 76 EncodeHandle(&elements[i], handles); | |
| 77 } | |
| 78 | |
| 79 // static | |
| 80 bool ArrayHelper<Handle>::DecodePointersAndHandles( | |
| 81 const ArrayHeader* header, | |
| 82 ElementType* elements, | |
| 83 Message* message) { | |
| 84 for (uint32_t i = 0; i < header->num_elements; ++i) { | |
| 85 if (!DecodeHandle(&elements[i], &message->handles)) | |
| 86 return false; | |
| 87 } | |
| 88 return true; | |
| 89 } | |
| 90 | |
| 91 } // namespace internal | 72 } // namespace internal |
| 92 } // namespace mojo | 73 } // namespace mojo |
| OLD | NEW |