5 #ifndef LODESTAR_NANOPBWRAPPER_HPP
6 #define LODESTAR_NANOPBWRAPPER_HPP
8 #include "Lodestar/io/proto/ls.proto.herald.pb.h"
9 #include "Lodestar/io/proto/ls.proto.types.pb.h"
10 #include "Lodestar/io/proto/ls.proto.matrix.pb.h"
11 #include "Lodestar/io/proto/ls.proto.vector.pb.h"
12 #include "Lodestar/io/proto/ls.proto.array.pb.h"
14 #include <pb_encode.h>
15 #include <pb_decode.h>
17 #include <Lodestar/aux/AlwaysFalse.hpp>
18 #include <Eigen/Dense>
19 #include <libhydrogen/hydrogen.h>
24 static void toCharBuffer(
void *a,
const T &n)
26 memcpy(a, &n,
sizeof(T));
30 static void fromCharBuffer(
const void *a, T &n)
32 memcpy(&n, a,
sizeof(T));
38 unsigned long publicKey = 0;
39 bool encrypted =
false;
40 ::std::uint8_t sign[64];
41 ls_proto_Type type = ls_proto_Type_unknown_t;
44 template<
typename TType =
void>
52 using arrayType = void;
55 pbType = ls_proto_Type_unknown_t
62 pbType = ls_proto_Type_unknown_t
74 pbType = ls_proto_Type_bool_t
80 using arrayType = ls_proto_ArrayBool;
82 static ls_proto_Herald makeHerald()
84 ls_proto_Herald herald = ls_proto_Herald_init_default;
85 herald.msgType =
static_cast<ls_proto_Type
>(pbType);
94 pbType = ls_proto_Type_char_t
100 using arrayType = ls_proto_ArrayBytes;
102 static ls_proto_Herald makeHerald()
104 ls_proto_Herald herald = ls_proto_Herald_init_default;
105 herald.msgType =
static_cast<ls_proto_Type
>(pbType);
114 pbType = ls_proto_Type_double_t
120 using arrayType = ls_proto_ArrayDouble;
122 static ls_proto_Herald makeHerald()
124 ls_proto_Herald herald = ls_proto_Herald_init_default;
125 herald.msgType =
static_cast<ls_proto_Type
>(pbType);
134 pbType = ls_proto_Type_float_t
140 using arrayType = ls_proto_ArrayFloat;
142 static ls_proto_Herald makeHerald()
144 ls_proto_Herald herald = ls_proto_Herald_init_default;
145 herald.msgType =
static_cast<ls_proto_Type
>(pbType);
154 pbType = ls_proto_Type_uint32_t
160 using arrayType = ls_proto_ArrayInt32;
162 static ls_proto_Herald makeHerald()
164 ls_proto_Herald herald = ls_proto_Herald_init_default;
165 herald.msgType =
static_cast<ls_proto_Type
>(pbType);
174 pbType = ls_proto_Type_int32_t
180 using arrayType = ls_proto_ArrayInt32;
182 static ls_proto_Herald makeHerald()
184 ls_proto_Herald herald = ls_proto_Herald_init_default;
185 herald.msgType =
static_cast<ls_proto_Type
>(pbType);
194 pbType = ls_proto_Type_uint64_t
200 using arrayType = ls_proto_ArrayUInt64;
202 static ls_proto_Herald makeHerald()
204 ls_proto_Herald herald = ls_proto_Herald_init_default;
205 herald.msgType =
static_cast<ls_proto_Type
>(pbType);
214 pbType = ls_proto_Type_int64_t
220 using arrayType = ls_proto_ArrayInt64;
222 static ls_proto_Herald makeHerald()
224 ls_proto_Herald herald = ls_proto_Herald_init_default;
225 herald.msgType =
static_cast<ls_proto_Type
>(pbType);
232 ::std::function<bool(pb_ostream_t *,
const pb_field_t *,
void *
const *)> *fEncode;
233 ::std::function<bool(pb_istream_t *,
const pb_field_t *,
void **)> *fDecode;
235 void const *dataConst;
238 static bool encode_nanopb(pb_ostream_t *stream,
const pb_field_t *field,
void *
const *arg)
242 return mArg->fEncode->operator()(stream, field, arg);
245 static bool decode_nanopb(pb_istream_t *stream,
const pb_field_t *field,
void **arg)
247 auto mArg = (NanopbArg *) *arg;
249 return mArg->fDecode->operator()(stream, field, arg);
252 template<
typename TScalar,
int NRows,
int NCols,
int NOptions>
254 static_assert((NRows >= 0) && (NCols >= 0),
"Matrix must be of fixed size.");
258 pbType = ls_proto_Type_matrix_t
261 using heraldType = ls_proto_Herald;
262 using subHeraldType = ls_proto_MatrixHerald;
263 using msgType =
typename NanopbWrapper<TScalar>::arrayType;
269 static ls_proto_Herald makeHerald()
271 ls_proto_Herald herald = ls_proto_Herald_init_default;
272 herald.msgType =
static_cast<ls_proto_Type
>(pbType);
277 static ls_proto_MatrixHerald makeSubHerald()
279 ls_proto_MatrixHerald matrixHerald = ls_proto_MatrixHerald_init_default;
282 matrixHerald.rows = NRows;
283 matrixHerald.cols = NCols;
284 if ((NOptions & Eigen::StorageOptions::RowMajor) == Eigen::StorageOptions::RowMajor) {
285 matrixHerald.has_ordering =
true;
286 matrixHerald.ordering = ls_proto_MatrixOrdering_rowMajor;
287 }
else if ((NOptions & Eigen::StorageOptions::ColMajor) == Eigen::StorageOptions::ColMajor) {
288 matrixHerald.has_ordering =
true;
289 matrixHerald.ordering = ls_proto_MatrixOrdering_colMajor;
295 static auto makeEncodingMessage(
const Eigen::Matrix<TScalar, NRows, NCols, NOptions> &M,
NanopbArg &nArg,
296 const ls_proto_MatrixHerald &mHerald) ->
typename NanopbWrapper<TScalar>::arrayType
298 typename NanopbWrapper<TScalar>::arrayType array;
301 static ::std::function<bool(pb_ostream_t *,
const pb_field_t *,
void *
const *)> fEncode;
303 if (mHerald.type == ls_proto_Type_double_t) {
304 array = ls_proto_ArrayDouble_init_default;
305 if (mHerald.has_ordering) {
306 if (mHerald.ordering == ls_proto_MatrixOrdering_rowMajor) {
307 fEncode = decltype(fEncode){
308 [](pb_ostream_t *stream,
const pb_field_t *field,
void *
const *arg) ->
bool {
310 auto M = (
const Eigen::Matrix<TScalar, NRows, NCols, NOptions> *) mArg->dataConst;
312 for (
int i = 0; i < NRows; i++) {
313 for (
int j = 0; j < NCols; j++) {
314 if (!pb_encode_tag_for_field(stream, field))
319 if (!pb_encode_fixed64(stream, &value))
327 fEncode = decltype(fEncode){
328 [](pb_ostream_t *stream,
const pb_field_t *field,
void *
const *arg) ->
bool {
330 auto M = (
const Eigen::Matrix<TScalar, NRows, NCols, NOptions> *) mArg->dataConst;
332 for (
int j = 0; j < NCols; j++) {
333 for (
int i = 0; i < NRows; i++) {
334 if (!pb_encode_tag_for_field(stream, field))
339 if (!pb_encode_fixed64(stream, &value))
348 fEncode = decltype(fEncode){
349 [](pb_ostream_t *stream,
const pb_field_t *field,
void *
const *arg) ->
bool {
351 auto M = (
const Eigen::Matrix<TScalar, NRows, NCols, NOptions> *) mArg->dataConst;
353 for (
int j = 0; j < NCols; j++) {
354 for (
int i = 0; i < NRows; i++) {
355 if (!pb_encode_tag_for_field(stream, field))
360 if (!pb_encode_fixed64(stream, &value))
370 if (mHerald.type == ls_proto_Type_float_t) {
371 array = ls_proto_ArrayFloat_init_default;
372 if (mHerald.has_ordering) {
373 if (mHerald.ordering == ls_proto_MatrixOrdering_rowMajor) {
374 fEncode = decltype(fEncode){
375 [](pb_ostream_t *stream,
const pb_field_t *field,
void *
const *arg) ->
bool {
377 auto M = (
const Eigen::Matrix<TScalar, NRows, NCols, NOptions> *) mArg->dataConst;
379 for (
int i = 0; i < NRows; i++) {
380 for (
int j = 0; j < NCols; j++) {
381 if (!pb_encode_tag_for_field(stream, field))
386 if (!pb_encode_fixed32(stream, &value))
394 fEncode = decltype(fEncode){
395 [](pb_ostream_t *stream,
const pb_field_t *field,
void *
const *arg) ->
bool {
397 auto M = (
const Eigen::Matrix<TScalar, NRows, NCols, NOptions> *) mArg->dataConst;
399 for (
int j = 0; j < NCols; j++) {
400 for (
int i = 0; i < NRows; i++) {
401 if (!pb_encode_tag_for_field(stream, field))
406 if (!pb_encode_fixed32(stream, &value))
415 fEncode = decltype(fEncode){
416 [](pb_ostream_t *stream,
const pb_field_t *field,
void *
const *arg) ->
bool {
418 auto M = (
const Eigen::Matrix<TScalar, NRows, NCols, NOptions> *) mArg->dataConst;
420 for (
int j = 0; j < NCols; j++) {
421 for (
int i = 0; i < NRows; i++) {
422 if (!pb_encode_tag_for_field(stream, field))
427 if (!pb_encode_fixed32(stream, &value))
437 nArg.fEncode = &fEncode;
439 array.values.funcs.encode = &encode_nanopb;
440 array.values.arg = (
void *) &nArg;
441 array.size = NRows * NCols;
446 struct MatrixCounter {
453 makeDecodingMessage(Eigen::Matrix<TScalar, NRows, NCols, NOptions> &M,
NanopbArg &nArg, MatrixCounter &MC,
454 const ls_proto_MatrixHerald &mHerald) ->
typename NanopbWrapper<TScalar>::arrayType
456 typename NanopbWrapper<TScalar>::arrayType array;
457 array.size = NRows * NCols;
469 static ::std::function<bool(pb_istream_t *,
const pb_field_t *,
void **)> fDecode;
471 if (mHerald.type == ls_proto_Type_double_t) {
472 array = ls_proto_ArrayDouble_init_default;
473 if (mHerald.has_ordering) {
474 if (mHerald.ordering == ls_proto_MatrixOrdering_rowMajor) {
475 fDecode = decltype(fDecode){
476 [](pb_istream_t *stream,
const pb_field_t *field,
void **arg) ->
bool {
477 auto MC = (MatrixCounter *) ((
NanopbArg *) *arg)->data;
478 auto M = (Eigen::Matrix<TScalar, NRows, NCols, NOptions> *) MC->M;
481 if (!pb_decode_fixed64(stream, &value))
484 (*M)(MC->i, MC->j) = value;
487 MC->j = MC->j % NCols;
491 MC->i = MC->i % NRows;
497 fDecode = decltype(fDecode){
498 [](pb_istream_t *stream,
const pb_field_t *field,
void **arg) ->
bool {
499 auto MC = (MatrixCounter *) ((NanopbArg *) *arg)->data;
500 auto M = (Eigen::Matrix<TScalar, NRows, NCols, NOptions> *) MC->M;
503 if (!pb_decode_fixed64(stream, &value))
506 (*M)(MC->i, MC->j) = value;
509 MC->i = MC->i % NRows;
513 MC->j = MC->j % NCols;
520 fDecode = decltype(fDecode){
521 [](pb_istream_t *stream,
const pb_field_t *field,
void **arg) ->
bool {
522 auto MC = (MatrixCounter *) ((NanopbArg *) *arg)->data;
523 auto M = (Eigen::Matrix<TScalar, NRows, NCols, NOptions> *) MC->M;
526 if (!pb_decode_fixed64(stream, &value))
529 (*M)(MC->i, MC->j) = value;
532 MC->i = MC->i % NRows;
536 MC->j = MC->j % NCols;
544 if (mHerald.type == ls_proto_Type_float_t) {
545 array = ls_proto_ArrayFloat_init_default;
546 if (mHerald.has_ordering) {
547 if (mHerald.ordering == ls_proto_MatrixOrdering_rowMajor) {
548 fDecode = decltype(fDecode){
549 [](pb_istream_t *stream,
const pb_field_t *field,
void **arg) ->
bool {
550 auto MC = (MatrixCounter *) ((NanopbArg *) *arg)->data;
551 auto M = (Eigen::Matrix<TScalar, NRows, NCols, NOptions> *) MC->M;
554 if (!pb_decode_fixed32(stream, &value))
557 (*M)(MC->i, MC->j) = value;
560 MC->j = MC->j % NCols;
564 MC->i = MC->i % NRows;
570 fDecode = decltype(fDecode){
571 [](pb_istream_t *stream,
const pb_field_t *field,
void **arg) ->
bool {
572 auto MC = (MatrixCounter *) ((NanopbArg *) *arg)->data;
573 auto M = (Eigen::Matrix<TScalar, NRows, NCols, NOptions> *) MC->M;
576 if (!pb_decode_fixed32(stream, &value))
579 (*M)(MC->i, MC->j) = value;
582 MC->i = MC->i % NRows;
586 MC->j = MC->j % NCols;
593 fDecode = decltype(fDecode){
594 [](pb_istream_t *stream,
const pb_field_t *field,
void **arg) ->
bool {
595 auto MC = (MatrixCounter *) ((NanopbArg *) *arg)->data;
596 auto M = (Eigen::Matrix<TScalar, NRows, NCols, NOptions> *) MC->M;
599 if (!pb_decode_fixed32(stream, &value))
602 (*M)(MC->i, MC->j) = value;
605 MC->i = MC->i % NRows;
609 MC->j = MC->j % NCols;
617 nArg.fDecode = &fDecode;
619 array.values.funcs.decode = &decode_nanopb;
620 array.values.arg = (
void *) &nArg;
626 encode(
const Eigen::Matrix<TScalar, NRows, NCols, NOptions> &M,
const MsgInfo &info, pb_ostream_t &stream)
628 static auto herald = makeHerald();
629 static auto subHerald = makeSubHerald();
631 static auto msg = makeEncodingMessage(M, *msgArg, subHerald);
633 herald.blockId = info.id;
634 herald.slotId = info.slot;
635 herald.msgType = info.type;
636 if (info.encrypted) {
637 herald.has_sign =
true;
640 msgArg->dataConst = &M;
642 if (::std::is_same<TScalar, double>::value)
643 return pb_encode_delimited(&stream, ls_proto_Herald_fields, &herald) &&
644 pb_encode_delimited(&stream, ls_proto_MatrixHerald_fields, &subHerald) &&
645 pb_encode_delimited(&stream, ls_proto_ArrayDouble_fields, &msg);
646 if (::std::is_same<TScalar, float>::value)
647 return pb_encode_delimited(&stream, ls_proto_Herald_fields, &herald) &&
648 pb_encode_delimited(&stream, ls_proto_MatrixHerald_fields, &subHerald) &&
649 pb_encode_delimited(&stream, ls_proto_ArrayFloat_fields, &msg);
652 static bool decode(Eigen::Matrix<TScalar, NRows, NCols, NOptions> &M, MsgInfo &info, pb_istream_t &stream)
654 static auto heraldRecv = makeHerald();
655 static auto subHeraldRecv = makeSubHerald();
658 static auto msgRecv = makeDecodingMessage(M, *msgArgRecv, MC, subHeraldRecv);
660 auto heraldRes = pb_decode_delimited(&stream, ls_proto_Herald_fields, &heraldRecv);
662 info.id = heraldRecv.blockId;
663 info.slot = heraldRecv.slotId;
664 info.type = heraldRecv.msgType;
665 if (heraldRecv.has_sign) {
666 info.encrypted =
true;
669 if (::std::is_same<TScalar, double>::value)
671 pb_decode_delimited(&stream, ls_proto_MatrixHerald_fields, &subHeraldRecv) &&
672 pb_decode_delimited(&stream, ls_proto_ArrayDouble_fields, &msgRecv);
673 if (::std::is_same<TScalar, float>::value)
675 pb_decode_delimited(&stream, ls_proto_MatrixHerald_fields, &subHeraldRecv) &&
676 pb_decode_delimited(&stream, ls_proto_ArrayFloat_fields, &msgRecv);
680 kMessageSize = ls_proto_Herald_size + ls_proto_MatrixHerald_size + NRows * NCols *
sizeof(TScalar) + 50
684 template<
typename TScalar,
int NRows>
686 static_assert((NRows >= 0),
"Vector must be of fixed size.");
690 pbType = ls_proto_Type_vector_t
697 using heraldType = ls_proto_Herald;
698 using subHeraldType = ls_proto_VectorHerald;
699 using msgType =
typename NanopbWrapper<TScalar>::arrayType;
701 static ls_proto_Herald makeHerald()
703 ls_proto_Herald herald = ls_proto_Herald_init_default;
704 herald.msgType =
static_cast<ls_proto_Type
>(pbType);
709 static ls_proto_VectorHerald makeSubHerald()
711 ls_proto_VectorHerald vectorHerald = ls_proto_VectorHerald_init_default;
714 vectorHerald.size = NRows;
715 vectorHerald.has_vectorType =
false;
720 static auto makeEncodingMessage(
const Eigen::Vector<TScalar, NRows> &v,
NanopbArg &nArg,
721 const ls_proto_VectorHerald &mHerald) ->
typename NanopbWrapper<TScalar>::arrayType
723 typename NanopbWrapper<TScalar>::arrayType array;
726 static ::std::function<bool(pb_ostream_t *,
const pb_field_t *,
void *
const *)> fEncode;
728 if (mHerald.type == ls_proto_Type_double_t) {
729 array = ls_proto_ArrayDouble_init_default;
730 fEncode = decltype(fEncode){
731 [](pb_ostream_t *stream,
const pb_field_t *field,
void *
const *arg) ->
bool {
733 auto v = (
const Eigen::Vector<TScalar, NRows> *) mArg->dataConst;
735 for (
int i = 0; i < NRows; i++) {
736 if (!pb_encode_tag_for_field(stream, field))
741 if (!pb_encode_fixed64(stream, &value))
749 if (mHerald.type == ls_proto_Type_float_t) {
750 array = ls_proto_ArrayFloat_init_default;
751 fEncode = decltype(fEncode){
752 [](pb_ostream_t *stream,
const pb_field_t *field,
void *
const *arg) ->
bool {
754 auto v = (
const Eigen::Vector<TScalar, NRows> *) mArg->dataConst;
756 for (
int i = 0; i < NRows; i++) {
757 if (!pb_encode_tag_for_field(stream, field))
762 if (!pb_encode_fixed32(stream, &value))
770 nArg.fEncode = &fEncode;
772 array.values.funcs.encode = &encode_nanopb;
773 array.values.arg = (
void *) &nArg;
779 static ls_proto_ArrayBytes
780 makeEncryptedEncodingMessage(
const Eigen::Vector<TScalar, NRows> &v,
NanopbArg &nArg,
781 const ls_proto_VectorHerald &mHerald,
const ls_proto_Herald &herald)
784 ls_proto_ArrayBytes array;
786 ::std::uint8_t sk[hydro_secretbox_KEYBYTES] = {0};
788 toCharBuffer(sk, herald.sign.sign0);
789 toCharBuffer(sk + 8, herald.sign.sign1);
790 toCharBuffer(sk + 16, herald.sign.sign2);
791 toCharBuffer(sk + 24, herald.sign.sign3);
794 static ::std::function<bool(pb_ostream_t *,
const pb_field_t *,
void *
const *)> fEncode;
796 array = ls_proto_ArrayBytes_init_default;
797 fEncode = decltype(fEncode){
798 [=](pb_ostream_t *stream,
const pb_field_t *field,
void *
const *arg) ->
bool {
800 auto v = (
const Eigen::Vector<TScalar, NRows> *) mArg->dataConst;
802 ::std::uint8_t cipher[NRows *
sizeof(TScalar) + hydro_secretbox_HEADERBYTES] = {0};
803 ::std::uint8_t buffer[NRows *
sizeof(TScalar)] = {0};
805 for (
size_t i = 0; i < NRows; i++)
806 toCharBuffer(buffer + i *
sizeof(TScalar), (*v)[i]);
808 if (!pb_encode_tag_for_field(stream, field))
811 hydro_secretbox_encrypt(cipher, buffer,
sizeof(buffer), 0,
"Lodestar", sk);
813 if (!pb_encode_string(stream, cipher,
820 nArg.fEncode = &fEncode;
822 array.values.funcs.encode = &encode_nanopb;
823 array.values.arg = (
void *) &nArg;
824 array.size = NRows *
sizeof(TScalar) + hydro_secretbox_HEADERBYTES;
829 struct VectorCounter {
834 static auto makeDecodingMessage(Eigen::Vector<TScalar, NRows> &v,
NanopbArg &nArg, VectorCounter &vC,
835 const ls_proto_VectorHerald &vHerald) ->
typename NanopbWrapper<TScalar>::arrayType
837 typename NanopbWrapper<TScalar>::arrayType array;
848 static ::std::function<bool(pb_istream_t *,
const pb_field_t *,
void **)> fDecode;
850 if (vHerald.type == ls_proto_Type_double_t) {
851 array = ls_proto_ArrayDouble_init_default;
853 fDecode = decltype(fDecode){[](pb_istream_t *stream,
const pb_field_t *field,
void **arg) ->
bool {
854 auto vC = (VectorCounter *) ((
NanopbArg *) *arg)->data;
855 auto v = (Eigen::Vector<TScalar, NRows> *) vC->v;
858 if (!pb_decode_fixed64(stream, &value))
864 vC->i = vC->i % NRows;
870 if (vHerald.type == ls_proto_Type_float_t) {
871 array = ls_proto_ArrayFloat_init_default;
872 fDecode = decltype(fDecode){[](pb_istream_t *stream,
const pb_field_t *field,
void **arg) ->
bool {
873 auto vC = (VectorCounter *) ((NanopbArg *) *arg)->data;
874 auto v = (Eigen::Vector<TScalar, NRows> *) vC->v;
877 if (!pb_decode_fixed32(stream, &value))
883 vC->i = vC->i % NRows;
889 nArg.fDecode = &fDecode;
891 array.values.funcs.decode = &decode_nanopb;
892 array.values.arg = (
void *) &nArg;
897 static ls_proto_ArrayBytes
898 makeEncryptedDecodingMessage(Eigen::Vector<TScalar, NRows> &v, NanopbArg &nArg, VectorCounter &vC,
899 const ls_proto_VectorHerald &vHerald,
const ls_proto_Herald &herald)
901 ls_proto_ArrayBytes array;
904 ::std::uint8_t sk[hydro_secretbox_KEYBYTES] = {0};
906 toCharBuffer(sk, herald.sign.sign0);
907 toCharBuffer(sk + 8, herald.sign.sign1);
908 toCharBuffer(sk + 16, herald.sign.sign2);
909 toCharBuffer(sk + 24, herald.sign.sign3);
920 static ::std::function<bool(pb_istream_t *,
const pb_field_t *,
void **)> fDecode;
922 array = ls_proto_ArrayBytes_init_default;
924 fDecode = decltype(fDecode){[=](pb_istream_t *stream,
const pb_field_t *field,
void **arg) ->
bool {
925 ::std::uint8_t buffer[NRows *
sizeof(TScalar) + hydro_secretbox_HEADERBYTES] = {0};
926 ::std::uint8_t decrypted[NRows *
sizeof(TScalar)] = {0};
928 auto vC = (VectorCounter *) ((NanopbArg *) *arg)->data;
929 auto v = (Eigen::Vector<TScalar, NRows> *) vC->v;
932 if (stream->bytes_left >
sizeof(buffer) || !pb_read(stream, buffer,
sizeof(buffer)))
935 if (hydro_secretbox_decrypt(decrypted, buffer,
936 NRows *
sizeof(TScalar) + hydro_secretbox_HEADERBYTES, 0,
"Lodestar",
940 for (
size_t i = 0; i < NRows; i++) {
941 (*v)[vC->i] =
reinterpret_cast<const TScalar *
>(decrypted)[i];
944 vC->i = vC->i % NRows;
950 nArg.fDecode = &fDecode;
952 array.values.funcs.decode = &decode_nanopb;
953 array.values.arg = (
void *) &nArg;
958 static bool encode(
const Eigen::Vector<TScalar, NRows> &v,
const MsgInfo &info, pb_ostream_t &stream)
960 static auto herald = makeHerald();
961 static auto subHerald = makeSubHerald();
963 msgArg->dataConst = &v;
965 herald.blockId = info.id;
966 herald.slotId = info.slot;
967 herald.msgType = info.type;
969 if (info.encrypted) {
970 static auto msg = makeEncryptedEncodingMessage(v, *msgArg, subHerald, herald);
972 herald.has_sign =
true;
973 herald.sign.has_sign0 =
true;
974 fromCharBuffer(
reinterpret_cast<const ::std::uint64_t *
>(info.sign), herald.sign.sign0);
975 herald.sign.has_sign1 =
true;
976 fromCharBuffer(
reinterpret_cast<const ::std::uint64_t *
>(info.sign) + 1, herald.sign.sign1);
977 herald.sign.has_sign2 =
true;
978 fromCharBuffer(
reinterpret_cast<const ::std::uint64_t *
>(info.sign) + 2, herald.sign.sign2);
979 herald.sign.has_sign3 =
true;
980 fromCharBuffer(
reinterpret_cast<const ::std::uint64_t *
>(info.sign) + 3, herald.sign.sign3);
981 herald.sign.has_sign4 =
true;
982 fromCharBuffer(
reinterpret_cast<const ::std::uint64_t *
>(info.sign) + 4, herald.sign.sign4);
983 herald.sign.has_sign5 =
true;
984 fromCharBuffer(
reinterpret_cast<const ::std::uint64_t *
>(info.sign) + 5, herald.sign.sign5);
985 herald.sign.has_sign6 =
true;
986 fromCharBuffer(
reinterpret_cast<const ::std::uint64_t *
>(info.sign) + 6, herald.sign.sign6);
987 herald.sign.has_sign7 =
true;
988 fromCharBuffer(
reinterpret_cast<const ::std::uint64_t *
>(info.sign) + 7, herald.sign.sign7);
990 return pb_encode_delimited(&stream, ls_proto_Herald_fields, &herald) &&
991 pb_encode_delimited(&stream, ls_proto_VectorHerald_fields, &subHerald) &&
992 pb_encode_delimited(&stream, ls_proto_ArrayBytes_fields, &msg);
994 static auto msg = makeEncodingMessage(v, *msgArg, subHerald);
996 if (::std::is_same<TScalar, double>::value)
997 return pb_encode_delimited(&stream, ls_proto_Herald_fields, &herald) &&
998 pb_encode_delimited(&stream, ls_proto_VectorHerald_fields, &subHerald) &&
999 pb_encode_delimited(&stream, ls_proto_ArrayDouble_fields, &msg);
1000 if (::std::is_same<TScalar, float>::value)
1001 return pb_encode_delimited(&stream, ls_proto_Herald_fields, &herald) &&
1002 pb_encode_delimited(&stream, ls_proto_VectorHerald_fields, &subHerald) &&
1003 pb_encode_delimited(&stream, ls_proto_ArrayFloat_fields, &msg);
1007 static bool decode(Eigen::Vector<TScalar, NRows> &v, MsgInfo &info, pb_istream_t &stream)
1009 static auto heraldRecv = makeHerald();
1010 static auto subHeraldRecv = makeSubHerald();
1014 auto heraldRes = pb_decode_delimited(&stream, ls_proto_Herald_fields, &heraldRecv);
1016 info.id = heraldRecv.blockId;
1017 info.slot = heraldRecv.slotId;
1018 info.type = heraldRecv.msgType;
1019 if (heraldRecv.has_sign) {
1020 info.encrypted =
true;
1021 toCharBuffer(
reinterpret_cast<::std::uint64_t *
>(info.sign), heraldRecv.sign.sign0);
1022 toCharBuffer(
reinterpret_cast<::std::uint64_t *
>(info.sign) + 1, heraldRecv.sign.sign1);
1023 toCharBuffer(
reinterpret_cast<::std::uint64_t *
>(info.sign) + 2, heraldRecv.sign.sign2);
1024 toCharBuffer(
reinterpret_cast<::std::uint64_t *
>(info.sign) + 3, heraldRecv.sign.sign3);
1025 toCharBuffer(
reinterpret_cast<::std::uint64_t *
>(info.sign) + 4, heraldRecv.sign.sign4);
1026 toCharBuffer(
reinterpret_cast<::std::uint64_t *
>(info.sign) + 5, heraldRecv.sign.sign5);
1027 toCharBuffer(
reinterpret_cast<::std::uint64_t *
>(info.sign) + 6, heraldRecv.sign.sign6);
1028 toCharBuffer(
reinterpret_cast<::std::uint64_t *
>(info.sign) + 7, heraldRecv.sign.sign7);
1030 static auto msgRecv = makeEncryptedDecodingMessage(v, *msgArgRecv, vc, subHeraldRecv, heraldRecv);
1033 pb_decode_delimited(&stream, ls_proto_VectorHerald_fields, &subHeraldRecv) &&
1034 pb_decode_delimited(&stream, ls_proto_ArrayBytes_fields, &msgRecv);
1036 static auto msgRecv = makeDecodingMessage(v, *msgArgRecv, vc, subHeraldRecv);
1038 if (::std::is_same<TScalar, double>::value)
1040 pb_decode_delimited(&stream, ls_proto_VectorHerald_fields, &subHeraldRecv) &&
1041 pb_decode_delimited(&stream, ls_proto_ArrayDouble_fields, &msgRecv);
1042 if (::std::is_same<TScalar, float>::value)
1044 pb_decode_delimited(&stream, ls_proto_VectorHerald_fields, &subHeraldRecv) &&
1045 pb_decode_delimited(&stream, ls_proto_ArrayFloat_fields, &msgRecv);
1050 kMessageSize = ls_proto_Herald_size + ls_proto_VectorHerald_size + NRows *
sizeof(TScalar) + 50
1057 #endif //LODESTAR_NANOPBWRAPPER_HPP