Vardhan Mudunuru | 5f74f42 | 2015-10-21 12:38:37 -0700 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // This example demonstrates how you can serialize and deserialize a generated |
| 6 | // mojom into and out of a buffer. |
| 7 | |
| 8 | #include "examples/serialization/serialization.mojom.h" |
| 9 | #include "mojo/public/cpp/bindings/array.h" |
| 10 | #include "mojo/public/cpp/environment/logging.h" |
| 11 | |
| 12 | int main() { |
| 13 | examples::MyStruct in; |
| 14 | examples::MyStruct out; |
| 15 | |
| 16 | in.a = 1; |
| 17 | in.b = 2.0f; |
| 18 | in.c = "hello world!"; |
| 19 | |
| 20 | char buf[1000]; |
| 21 | MOJO_CHECK(in.Serialize(buf, sizeof(buf))); |
Vardhan Mudunuru | bbe5f8b | 2016-03-31 13:02:39 -0700 | [diff] [blame] | 22 | MOJO_CHECK(out.Deserialize(buf, sizeof(buf))); |
Vardhan Mudunuru | 5f74f42 | 2015-10-21 12:38:37 -0700 | [diff] [blame] | 23 | MOJO_CHECK(out.a == 1); |
| 24 | MOJO_CHECK(out.b == 2.0f); |
| 25 | MOJO_CHECK(out.c == "hello world!"); |
| 26 | |
| 27 | return 0; |
| 28 | } |