OLD | NEW |
(Empty) | |
| 1 #ifndef MOJO_GENERATED_BINDINGS_SAMPLE_SERVICE_INTERNAL_H_ |
| 2 #define MOJO_GENERATED_BINDINGS_SAMPLE_SERVICE_INTERNAL_H_ |
| 3 |
| 4 #include <string.h> |
| 5 |
| 6 #include "mojo/public/bindings/bindings_internal.h" |
| 7 #include "mojo/public/bindings/generated/sample_service.h" |
| 8 |
| 9 namespace sample { |
| 10 namespace internal { |
| 11 |
| 12 const uint32_t kService_Frobinate_Name = 1; |
| 13 |
| 14 class Service_Frobinate_Params { |
| 15 public: |
| 16 Service_Frobinate_Params() { |
| 17 header_.num_bytes = sizeof(*this); |
| 18 header_.num_fields = 2; |
| 19 } |
| 20 |
| 21 void set_foo(Foo* foo) { d_.foo.ptr = foo; } |
| 22 void set_baz(bool baz) { d_.baz = baz; } |
| 23 |
| 24 const Foo* foo() const { return d_.foo.ptr; } |
| 25 bool baz() const { return d_.baz; } |
| 26 |
| 27 private: |
| 28 friend class mojo::internal::Traits<Service_Frobinate_Params>; |
| 29 |
| 30 mojo::StructHeader header_; |
| 31 struct { |
| 32 mojo::StructPointer<Foo> foo; |
| 33 uint32_t baz : 1; |
| 34 } d_; |
| 35 |
| 36 ~Service_Frobinate_Params(); // NOT IMPLEMENTED |
| 37 }; |
| 38 |
| 39 } // namespace internal |
| 40 } // namespace sample |
| 41 |
| 42 namespace mojo { |
| 43 namespace internal { |
| 44 |
| 45 template <> |
| 46 class Traits<sample::Bar> { |
| 47 public: |
| 48 static sample::Bar* Clone(const sample::Bar* bar, mojo::MessageBuffer* buf) { |
| 49 sample::Bar* clone = buf->Alloc<sample::Bar>(); |
| 50 memcpy(clone, bar, sizeof(*bar)); |
| 51 return clone; |
| 52 } |
| 53 |
| 54 static void EncodePointersAndHandles(sample::Bar* bar, |
| 55 std::vector<mojo::Handle>* handles) { |
| 56 } |
| 57 |
| 58 static bool DecodePointersAndHandles(sample::Bar* bar, |
| 59 const mojo::Message& message) { |
| 60 return true; |
| 61 } |
| 62 }; |
| 63 |
| 64 template <> |
| 65 class Traits<sample::Foo> { |
| 66 public: |
| 67 static sample::Foo* Clone(const sample::Foo* foo, mojo::MessageBuffer* buf) { |
| 68 sample::Foo* clone = buf->Alloc<sample::Foo>(); |
| 69 memcpy(clone, foo, sizeof(*foo)); |
| 70 |
| 71 clone->set_bar(mojo::internal::Clone(foo->bar(), buf)); |
| 72 clone->set_data(mojo::internal::Clone(foo->data(), buf)); |
| 73 clone->set_extra_bars(mojo::internal::Clone(foo->extra_bars(), buf)); |
| 74 |
| 75 return clone; |
| 76 } |
| 77 |
| 78 static void EncodePointersAndHandles(sample::Foo* foo, |
| 79 std::vector<mojo::Handle>* handles) { |
| 80 Encode(&foo->d_.bar, handles); |
| 81 Encode(&foo->d_.data, handles); |
| 82 Encode(&foo->d_.extra_bars, handles); |
| 83 } |
| 84 |
| 85 static bool DecodePointersAndHandles(sample::Foo* foo, |
| 86 const mojo::Message& message) { |
| 87 if (!Decode(&foo->d_.bar, message)) |
| 88 return false; |
| 89 if (!Decode(&foo->d_.data, message)) |
| 90 return false; |
| 91 if (foo->header_.num_fields >= 8) { |
| 92 if (!Decode(&foo->d_.extra_bars, message)) |
| 93 return false; |
| 94 } |
| 95 |
| 96 // TODO: validate |
| 97 return true; |
| 98 } |
| 99 }; |
| 100 |
| 101 template <> |
| 102 class Traits<sample::internal::Service_Frobinate_Params> { |
| 103 public: |
| 104 static void EncodePointersAndHandles( |
| 105 sample::internal::Service_Frobinate_Params* params, |
| 106 std::vector<mojo::Handle>* handles) { |
| 107 Encode(¶ms->d_.foo, handles); |
| 108 } |
| 109 |
| 110 static bool DecodePointersAndHandles( |
| 111 sample::internal::Service_Frobinate_Params* params, |
| 112 const mojo::Message& message) { |
| 113 if (!Decode(¶ms->d_.foo, message)) |
| 114 return false; |
| 115 |
| 116 // TODO: validate |
| 117 return true; |
| 118 } |
| 119 }; |
| 120 |
| 121 } // namespace internal |
| 122 } // namespace mojo |
| 123 |
| 124 #endif // MOJO_GENERATED_BINDINGS_SAMPLE_SERVICE_INTERNAL_H_ |
OLD | NEW |