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

Side by Side Diff: mojo/public/bindings/sample/generated/sample_service_serialization.h

Issue 23913008: C++ bindings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows build error. Created 7 years, 2 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 | Annotate | Revision Log
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 #ifndef MOJO_GENERATED_BINDINGS_SAMPLE_SERVICE_SERIALIZATION_H_
6 #define MOJO_GENERATED_BINDINGS_SAMPLE_SERVICE_SERIALIZATION_H_
7
8 #include <string.h>
9
10 #include "mojo/public/bindings/lib/bindings_serialization.h"
11 #include "mojo/public/bindings/sample/generated/sample_service.h"
12
13 namespace sample {
14 namespace internal {
15
16 const uint32_t kService_Frobinate_Name = 1;
17
18 class Service_Frobinate_Params {
19 public:
20 static Service_Frobinate_Params* New(mojo::Buffer* buf) {
21 return new (buf->Allocate(sizeof(Service_Frobinate_Params)))
22 Service_Frobinate_Params();
23 }
24
25 void set_foo(Foo* foo) { d_.foo.ptr = foo; }
26 void set_baz(bool baz) { d_.baz = baz; }
27 void set_port(mojo::Handle port) { d_.port = port; }
28
29 const Foo* foo() const { return d_.foo.ptr; }
30 bool baz() const { return d_.baz; }
31 mojo::Handle port() const {
32 // NOTE: port is an optional field!
33 return header_.num_fields >= 3 ? d_.port : mojo::kInvalidHandle;
34 }
35
36 private:
37 friend class mojo::internal::ObjectTraits<Service_Frobinate_Params>;
38
39 Service_Frobinate_Params() {
40 header_.num_bytes = sizeof(*this);
41 header_.num_fields = 3;
42 }
43 ~Service_Frobinate_Params(); // NOT IMPLEMENTED
44
45 mojo::internal::StructHeader header_;
46 struct Data {
47 mojo::internal::StructPointer<Foo> foo;
48 uint32_t baz : 1;
49 mojo::Handle port;
50 } d_;
51 };
52
53 } // namespace internal
54 } // namespace sample
55
56 namespace mojo {
57 namespace internal {
58
59 template <>
60 class ObjectTraits<sample::Bar> {
61 public:
62 static size_t ComputeAlignedSizeOf(const sample::Bar* bar) {
63 return Align(sizeof(*bar));
64 }
65
66 static sample::Bar* Clone(const sample::Bar* bar, Buffer* buf) {
67 sample::Bar* clone = sample::Bar::New(buf);
68 memcpy(clone, bar, sizeof(*bar));
69 return clone;
70 }
71
72 static void EncodePointersAndHandles(sample::Bar* bar,
73 std::vector<mojo::Handle>* handles) {
74 }
75
76 static bool DecodePointersAndHandles(sample::Bar* bar,
77 const mojo::Message& message) {
78 return true;
79 }
80 };
81
82 template <>
83 class ObjectTraits<sample::Foo> {
84 public:
85 static size_t ComputeAlignedSizeOf(const sample::Foo* foo) {
86 return Align(sizeof(*foo)) +
87 mojo::internal::ComputeAlignedSizeOf(foo->bar()) +
88 mojo::internal::ComputeAlignedSizeOf(foo->data()) +
89 mojo::internal::ComputeAlignedSizeOf(foo->extra_bars()) +
90 mojo::internal::ComputeAlignedSizeOf(foo->name()) +
91 mojo::internal::ComputeAlignedSizeOf(foo->files());
92 }
93
94 static sample::Foo* Clone(const sample::Foo* foo, Buffer* buf) {
95 sample::Foo* clone = sample::Foo::New(buf);
96 memcpy(clone, foo, sizeof(*foo));
97
98 clone->set_bar(mojo::internal::Clone(foo->bar(), buf));
99 clone->set_data(mojo::internal::Clone(foo->data(), buf));
100 clone->set_extra_bars(mojo::internal::Clone(foo->extra_bars(), buf));
101 clone->set_name(mojo::internal::Clone(foo->name(), buf));
102 clone->set_files(mojo::internal::Clone(foo->files(), buf));
103
104 return clone;
105 }
106
107 static void EncodePointersAndHandles(sample::Foo* foo,
108 std::vector<mojo::Handle>* handles) {
109 Encode(&foo->d_.bar, handles);
110 Encode(&foo->d_.data, handles);
111 Encode(&foo->d_.extra_bars, handles);
112 Encode(&foo->d_.name, handles);
113 Encode(&foo->d_.files, handles);
114 }
115
116 static bool DecodePointersAndHandles(sample::Foo* foo,
117 const mojo::Message& message) {
118 if (!Decode(&foo->d_.bar, message))
119 return false;
120 if (!Decode(&foo->d_.data, message))
121 return false;
122 if (foo->header_.num_fields >= 8) {
123 if (!Decode(&foo->d_.extra_bars, message))
124 return false;
125 }
126 if (foo->header_.num_fields >= 9) {
127 if (!Decode(&foo->d_.name, message))
128 return false;
129 }
130 if (foo->header_.num_fields >= 10) {
131 if (!Decode(&foo->d_.files, message))
132 return false;
133 }
134
135 // TODO: validate
136 return true;
137 }
138 };
139
140 template <>
141 class ObjectTraits<sample::internal::Service_Frobinate_Params> {
142 public:
143 static void EncodePointersAndHandles(
144 sample::internal::Service_Frobinate_Params* params,
145 std::vector<mojo::Handle>* handles) {
146 Encode(&params->d_.foo, handles);
147 EncodeHandle(&params->d_.port, handles);
148 }
149
150 static bool DecodePointersAndHandles(
151 sample::internal::Service_Frobinate_Params* params,
152 const mojo::Message& message) {
153 if (!Decode(&params->d_.foo, message))
154 return false;
155 if (params->header_.num_fields >= 3) {
156 if (!DecodeHandle(&params->d_.port, message.handles))
157 return false;
158 }
159
160 // TODO: validate
161 return true;
162 }
163 };
164
165 } // namespace internal
166 } // namespace mojo
167
168 #endif // MOJO_GENERATED_BINDINGS_SAMPLE_SERVICE_SERIALIZATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698