From d8b578f42c5fbac101c77249c05939fd04d50722 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 13 Nov 2018 11:18:00 +0100 Subject: import MPack. Does not work with embedded yet --- src/app/prototest/main.cc | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/app/prototest/main.cc') diff --git a/src/app/prototest/main.cc b/src/app/prototest/main.cc index fe33ae0..aebfaea 100644 --- a/src/app/prototest/main.cc +++ b/src/app/prototest/main.cc @@ -8,6 +8,9 @@ #ifdef PROTOTEST_MODERNJSON #include "lib/modernjson/json.h" #endif +#ifdef PROTOTEST_MPACK +#include "mpack.h" +#endif #ifdef PROTOTEST_NANOPB #include #include "nanopb.pb.h" @@ -111,6 +114,38 @@ void loop(void) kout << len << " bytes written" << endl; } +#endif + + /* + * MPack + */ + +#ifdef PROTOTEST_MPACK + char buf[128]; + for (unsigned int i = 0; i < 128; i++) { + buf[i] = 0; + } + mpack_writer_t writer; + mpack_writer_init(&writer, buf, sizeof(buf)); + + mpack_start_map(&writer, 2); + mpack_write_cstr(&writer, "gps"); + mpack_write_uint(&writer, ts); + mpack_start_array(&writer, 2); + mpack_write_float(&writer, 48.756080); + mpack_write_float(&writer, 2.302038); + mpack_finish_array(&writer); + mpack_finish_map(&writer); + + if (mpack_writer_destroy(&writer) != mpack_ok) { + kout << "Encoding failed" << endl; + } + kout << "mpack is " << hex; + for (unsigned int i = 0; i < 128; i++) { + kout << (uint8_t)buf[i]; + } + kout << endl; + #endif /* -- cgit v1.2.3