Commit d8b578f4 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

import MPack. Does not work with embedded yet

parent 404f207f
Loading
Loading
Loading
Loading
+7151 −0

File added.

Preview size limit exceeded, changes collapsed.

+6 −0
Original line number Diff line number Diff line
@@ -8,6 +8,12 @@ ifeq (${prototest_modernjson}, 1)
	COMMON_FLAGS += -DPROTOTEST_MODERNJSON
endif

ifeq (${prototest_mpack}, 1)
	COMMON_FLAGS += -DPROTOTEST_MPACK
	TARGETS += src/lib/mpack/mpack.cc
	INCLUDES += -Iinclude/lib/mpack
endif

ifeq (${prototest_nanopb}, 1)
	COMMON_FLAGS += -DPROTOTEST_NANOPB
	TARGETS += src/app/prototest/nanopb.pb.cc src/lib/nanopb/pb_common.cc
+35 −0
Original line number Diff line number Diff line
@@ -8,6 +8,9 @@
#ifdef PROTOTEST_MODERNJSON
#include "lib/modernjson/json.h"
#endif
#ifdef PROTOTEST_MPACK
#include "mpack.h"
#endif
#ifdef PROTOTEST_NANOPB
#include <pb.h>
#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

	/*

src/lib/mpack/mpack.cc

0 → 100644
+6440 −0

File added.

Preview size limit exceeded, changes collapsed.