| OLD | NEW |
| (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/bindings/sample/generated/sample_foo_serialization.h" | |
| 6 | |
| 7 #include <string.h> | |
| 8 | |
| 9 #include "mojo/public/bindings/sample/generated/sample_bar_serialization.h" | |
| 10 #include "mojo/public/bindings/sample/generated/sample_foo.h" | |
| 11 | |
| 12 namespace mojo { | |
| 13 namespace internal { | |
| 14 | |
| 15 // static | |
| 16 size_t ObjectTraits<sample::Foo>::ComputeSizeOf( | |
| 17 const sample::Foo* foo) { | |
| 18 return sizeof(*foo) + | |
| 19 mojo::internal::ComputeSizeOf(foo->bar()) + | |
| 20 mojo::internal::ComputeSizeOf(foo->data()) + | |
| 21 mojo::internal::ComputeSizeOf(foo->extra_bars()) + | |
| 22 mojo::internal::ComputeSizeOf(foo->name()) + | |
| 23 mojo::internal::ComputeSizeOf(foo->files()); | |
| 24 } | |
| 25 | |
| 26 // static | |
| 27 sample::Foo* ObjectTraits<sample::Foo>::Clone( | |
| 28 const sample::Foo* foo, Buffer* buf) { | |
| 29 sample::Foo* clone = sample::Foo::New(buf); | |
| 30 memcpy(clone, foo, sizeof(*foo)); | |
| 31 | |
| 32 clone->set_bar(mojo::internal::Clone(foo->bar(), buf)); | |
| 33 clone->set_data(mojo::internal::Clone(foo->data(), buf)); | |
| 34 clone->set_extra_bars(mojo::internal::Clone(foo->extra_bars(), buf)); | |
| 35 clone->set_name(mojo::internal::Clone(foo->name(), buf)); | |
| 36 clone->set_files(mojo::internal::Clone(foo->files(), buf)); | |
| 37 | |
| 38 return clone; | |
| 39 } | |
| 40 | |
| 41 // static | |
| 42 void ObjectTraits<sample::Foo>::EncodePointersAndHandles( | |
| 43 sample::Foo* foo, std::vector<mojo::Handle>* handles) { | |
| 44 Encode(&foo->bar_, handles); | |
| 45 Encode(&foo->data_, handles); | |
| 46 Encode(&foo->extra_bars_, handles); | |
| 47 Encode(&foo->name_, handles); | |
| 48 Encode(&foo->files_, handles); | |
| 49 } | |
| 50 | |
| 51 // static | |
| 52 bool ObjectTraits<sample::Foo>::DecodePointersAndHandles( | |
| 53 sample::Foo* foo, const mojo::Message& message) { | |
| 54 if (!Decode(&foo->bar_, message)) | |
| 55 return false; | |
| 56 if (!Decode(&foo->data_, message)) | |
| 57 return false; | |
| 58 if (foo->_header_.num_fields >= 8) { | |
| 59 if (!Decode(&foo->extra_bars_, message)) | |
| 60 return false; | |
| 61 } | |
| 62 if (foo->_header_.num_fields >= 9) { | |
| 63 if (!Decode(&foo->name_, message)) | |
| 64 return false; | |
| 65 } | |
| 66 if (foo->_header_.num_fields >= 10) { | |
| 67 if (!Decode(&foo->files_, message)) | |
| 68 return false; | |
| 69 } | |
| 70 | |
| 71 // TODO: validate | |
| 72 return true; | |
| 73 } | |
| 74 | |
| 75 } // namespace internal | |
| 76 } // namespace mojo | |
| OLD | NEW |