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

Unified Diff: examples/serialization/main.cc

Issue 1412733002: C++ bindings: separate out serialization source set, have "mojom" targets optionally use serializat… (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: address comments from previous patch Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « examples/serialization/BUILD.gn ('k') | examples/serialization/serialization.mojom » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: examples/serialization/main.cc
diff --git a/examples/serialization/main.cc b/examples/serialization/main.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9b0a96d69f698e48159ed952964ac766d65a0a66
--- /dev/null
+++ b/examples/serialization/main.cc
@@ -0,0 +1,29 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This example demonstrates how you can serialize and deserialize a generated
+// mojom into and out of a buffer.
+
+#include "examples/serialization/serialization.mojom.h"
+#include "mojo/public/cpp/bindings/array.h"
+#include "mojo/public/cpp/environment/logging.h"
+
+int main() {
+ examples::MyStruct in;
+ examples::MyStruct out;
+
+ in.a = 1;
+ in.b = 2.0f;
+ in.c = "hello world!";
+
+ char buf[1000];
+ MOJO_CHECK(in.Serialize(buf, sizeof(buf)));
+
+ out.Deserialize(buf);
+ MOJO_CHECK(out.a == 1);
+ MOJO_CHECK(out.b == 2.0f);
+ MOJO_CHECK(out.c == "hello world!");
+
+ return 0;
+}
« no previous file with comments | « examples/serialization/BUILD.gn ('k') | examples/serialization/serialization.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698