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

Side by Side Diff: examples/serialization/main.cc

Issue 1800753005: C++ bindings: A struct's Deserialize() now does validation before deserializing. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: fix char* - >char bug in unittest. FixedBuffer can accept sizes that aren't 8 byte multiples. Created 4 years, 8 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
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/lib/bindings_internal.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 // This example demonstrates how you can serialize and deserialize a generated 5 // This example demonstrates how you can serialize and deserialize a generated
6 // mojom into and out of a buffer. 6 // mojom into and out of a buffer.
7 7
8 #include "examples/serialization/serialization.mojom.h" 8 #include "examples/serialization/serialization.mojom.h"
9 #include "mojo/public/cpp/bindings/array.h" 9 #include "mojo/public/cpp/bindings/array.h"
10 #include "mojo/public/cpp/environment/logging.h" 10 #include "mojo/public/cpp/environment/logging.h"
11 11
12 int main() { 12 int main() {
13 examples::MyStruct in; 13 examples::MyStruct in;
14 examples::MyStruct out; 14 examples::MyStruct out;
15 15
16 in.a = 1; 16 in.a = 1;
17 in.b = 2.0f; 17 in.b = 2.0f;
18 in.c = "hello world!"; 18 in.c = "hello world!";
19 19
20 char buf[1000]; 20 char buf[1000];
21 MOJO_CHECK(in.Serialize(buf, sizeof(buf))); 21 MOJO_CHECK(in.Serialize(buf, sizeof(buf)));
22 22 MOJO_CHECK(out.Deserialize(buf, sizeof(buf)));
23 out.Deserialize(buf);
24 MOJO_CHECK(out.a == 1); 23 MOJO_CHECK(out.a == 1);
25 MOJO_CHECK(out.b == 2.0f); 24 MOJO_CHECK(out.b == 2.0f);
26 MOJO_CHECK(out.c == "hello world!"); 25 MOJO_CHECK(out.c == "hello world!");
27 26
28 return 0; 27 return 0;
29 } 28 }
OLDNEW
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/lib/bindings_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698