summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-11-21 15:50:40 +0100
committerDaniel Friesel <derf@finalrewind.org>2018-11-21 15:50:40 +0100
commit51d9da1532cc37608bce150540e99157cbc6a6d2 (patch)
tree59e398dd5de9b9335ba869b7f0cfa2fce7679a09
parente8de5b7e285645b520f0516a2facbd76556d15aa (diff)
prototest: autogen capnproto_c
-rw-r--r--src/app/prototest/capnp_c_bench.capnp24
-rw-r--r--src/app/prototest/main.cc65
2 files changed, 50 insertions, 39 deletions
diff --git a/src/app/prototest/capnp_c_bench.capnp b/src/app/prototest/capnp_c_bench.capnp
index 54e0252..b6d5ba3 100644
--- a/src/app/prototest/capnp_c_bench.capnp
+++ b/src/app/prototest/capnp_c_bench.capnp
@@ -1,17 +1,17 @@
@0xad5b236043de2389;
struct Benchmark {
-# data @0 :List(Float64);
-# nesting @1 :Nesting;
- sensor @0 :Text;
- time @1 :Int64;
+ data @0 :List(Float64);
+ nesting @1 :Nesting;
+ sensor @2 :Text;
+ time @3 :Int64;
-# struct Nesting {
-# foo @0 :Foo;
-#
-# struct Foo {
-# hurr @0 :Text;
-# qwop @1 :Int64;
-# }
-# }
+ struct Nesting {
+ foo @0 :Foo;
+
+ struct Foo {
+ hurr @0 :Text;
+ qwop @1 :Int64;
+ }
+ }
}
diff --git a/src/app/prototest/main.cc b/src/app/prototest/main.cc
index 84322ac..1234139 100644
--- a/src/app/prototest/main.cc
+++ b/src/app/prototest/main.cc
@@ -113,37 +113,48 @@ kout << "}" << endl;
for (unsigned int i = 0; i < sizeof(buf); i++) {
buf[i] = 0;
}
- struct capn c;
- capn_init_malloc(&c);
- capn_ptr cr = capn_root(&c);
- struct capn_segment *cs = cr.seg;
- struct Benchmark benchmark;
- //struct Benchmark_Nesting benchmark_nesting;
- //struct Benchmark_Nesting_Foo benchmark_nesting_foo;
- benchmark.time = ts + 1;
-
- capn_text sensor_text;
- sensor_text.len = 3;
- sensor_text.str = "gps";
- sensor_text.seg = NULL;
-
- benchmark.sensor = sensor_text;
-
- //benchmark.nesting = new_Benchmark_Nesting(cs);
- //benchmark_nesting.foo = new_Benchmark_Nesting_Foo(cs);
-
- //write_Benchmark_Nesting_Foo(&benchmark_nesting_foo, benchmark_nesting.foo);
- //write_Benchmark_Nesting(&benchmark_nesting, benchmark.nesting);
-
- Benchmark_ptr benchmark_ptr = new_Benchmark(cs);
- write_Benchmark(&benchmark, benchmark_ptr);
-
- capn_write_mem(&c, buf, sizeof(buf), 0 /* packed */);
+struct capn c;
+capn_init_malloc(&c);
+capn_ptr cr = capn_root(&c);
+struct capn_segment *cs = cr.seg;
+
+struct Benchmark benchmark;
+benchmark.data = capn_new_list64(cs, 2);
+capn_set64(benchmark.data, 0, capn_from_f64(48.756080));
+capn_set64(benchmark.data, 1, capn_from_f64(2.302038));
+benchmark.nesting = new_Benchmark_Nesting(cs);
+struct Benchmark_Nesting nesting;
+nesting.foo = new_Benchmark_Nesting_Foo(cs);
+struct Benchmark_Nesting_Foo foo;
+capn_text hurr_text;
+hurr_text.len = 4;
+hurr_text.str = "durr";
+hurr_text.seg = NULL;
+foo.hurr = hurr_text;
+
+foo.qwop = 9001;
+
+write_Benchmark_Nesting_Foo(&foo, nesting.foo);
+write_Benchmark_Nesting(&nesting, benchmark.nesting);
+capn_text sensor_text;
+sensor_text.len = 3;
+sensor_text.str = "gps";
+sensor_text.seg = NULL;
+benchmark.sensor = sensor_text;
+
+benchmark.time = ts;
+
+Benchmark_ptr benchmark_ptr = new_Benchmark(cs);
+write_Benchmark(&benchmark, benchmark_ptr);
+capn_setp(cr, 0, benchmark_ptr.p);
+
+
+ unsigned int sz = capn_write_mem(&c, buf, sizeof(buf), 0 /* packed */);
capn_free(&c);
kout << "capnproto is " << hex;
- for (unsigned int i = 0; i < sizeof(buf); i++) {
+ for (unsigned int i = 0; i < sz; i++) {
kout << buf[i];
}
kout << endl;