-
Notifications
You must be signed in to change notification settings - Fork 7
/
nanopb_cpp.h
612 lines (534 loc) · 24.3 KB
/
nanopb_cpp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
#ifndef NANOPB_CPP_NANOPB_CPP_H
#define NANOPB_CPP_NANOPB_CPP_H
#include <string>
#include <memory>
#include "pb.h"
#include "pb_encode.h"
#include "pb_decode.h"
#include "pb_common.h"
#ifndef NANOPB_CPP_ASSERT
#ifndef NDEBUG
#include <cassert>
#define NANOPB_CPP_ASSERT(expr) assert(expr)
#else
#define _nanopb_cpp_unused(x) ((void)(x))
#define NANOPB_CPP_ASSERT(expr) _nanopb_cpp_unused(expr)
#endif
#endif
namespace NanoPb {
using BufferType = std::string;
using BufferPtr = std::unique_ptr<BufferType>;
/**
* StringOutputStream
*/
class StringOutputStream : public pb_ostream_t {
public:
/**
* Create output stream without max size limits.
* NOTE: Prefer to use `StringOutputStream(size_t maxStreamSize)` constructor to avoid filling all RAM.
*/
StringOutputStream();
/**
* Create output memory stream with constant max size
*
* @param maxStreamSize
*/
StringOutputStream(size_t maxStreamSize);
BufferPtr release();
private:
static bool _pbCallback(pb_ostream_t *stream, const pb_byte_t *buf, size_t count);
BufferPtr _buffer;
};
/**
* StringInputStream
*/
class StringInputStream : public pb_istream_t {
public:
StringInputStream(BufferPtr&& buffer);
private:
BufferPtr _buffer;
size_t _position;
};
/**
* Encode message
*/
template<class MESSAGE_CONVERTER>
bool encode(pb_ostream_t &stream, const typename MESSAGE_CONVERTER::LocalType& v){
using ProtoType = typename MESSAGE_CONVERTER::ProtoType;
using LocalType = typename MESSAGE_CONVERTER::LocalType;
const LocalType& local = v;
ProtoType proto = MESSAGE_CONVERTER::encoderInit(local);
return pb_encode(&stream, MESSAGE_CONVERTER::getMsgType(), &proto);
}
/**
* Encode sub message
*/
template<class MESSAGE_CONVERTER>
bool encodeSubMessage(pb_ostream_t &stream, const typename MESSAGE_CONVERTER::LocalType& v){
using ProtoType = typename MESSAGE_CONVERTER::ProtoType;
using LocalType = typename MESSAGE_CONVERTER::LocalType;
const LocalType& local = v;
ProtoType proto = MESSAGE_CONVERTER::encoderInit(local);
return pb_encode_submessage(&stream, MESSAGE_CONVERTER::getMsgType(), &proto);
}
/**
* Encode union message
*/
template<class MESSAGE_CONVERTER>
bool encodeUnionMessage(pb_ostream_t &stream, const typename MESSAGE_CONVERTER::LocalType& v, const pb_msgdesc_t* unionContainer){
using ProtoType = typename MESSAGE_CONVERTER::ProtoType;
using LocalType = typename MESSAGE_CONVERTER::LocalType;
pb_field_iter_t iter;
const LocalType& local = v;
ProtoType proto = MESSAGE_CONVERTER::encoderInit(local);
if (!pb_field_iter_begin(&iter, unionContainer, &proto))
return false;
do
{
if (iter.submsg_desc == MESSAGE_CONVERTER::getMsgType()){
/* This is our field, encode the message using it. */
if (!pb_encode_tag_for_field(&stream, &iter))
return false;
return pb_encode_submessage(&stream, MESSAGE_CONVERTER::getMsgType(), &proto);
}
} while (pb_field_iter_next(&iter));
/* Didn't find the field for messagetype */
return false;
}
/**
* Decode message from stream
*/
template<class MESSAGE_CONVERTER>
bool decode(pb_istream_t &stream, typename MESSAGE_CONVERTER::LocalType& v){
using ProtoType = typename MESSAGE_CONVERTER::ProtoType;
using DecoderContext = typename MESSAGE_CONVERTER::DecoderContext;
DecoderContext local = v;
ProtoType proto = MESSAGE_CONVERTER::decoderInit(local);
if (!pb_decode(&stream, MESSAGE_CONVERTER::getMsgType(), &proto))
return false;
if (!MESSAGE_CONVERTER::decoderApply(proto, local))
return false;
return true;
}
/**
* Decode from buffer in memory
*/
template<class MESSAGE_CONVERTER>
bool decode(const void* data, const pb_size_t dataSize, typename MESSAGE_CONVERTER::LocalType& v){
pb_istream_t stream = pb_istream_from_buffer((pb_byte_t*)data, dataSize);
return decode<MESSAGE_CONVERTER>(stream, v);
}
/**
* Decode sub message
*/
template<class MESSAGE_CONVERTER>
bool decodeSubMessage(pb_istream_t &stream, typename MESSAGE_CONVERTER::LocalType& v){
pb_istream_t subStream;
if (!pb_make_string_substream(&stream, &subStream))
return false;
if (!decode<MESSAGE_CONVERTER>(subStream, v))
return false;
if (!pb_close_string_substream(&stream, &subStream))
return false;
return true;
}
/**
* Decode union message type
*/
const pb_msgdesc_t* decodeUnionMessageType(pb_istream_t &stream, const pb_msgdesc_t* unionContainer);
/**
* Basic Scalar types.
*
* Should implement
* encode()/decode()
*
*/
namespace Type {
template<class LOCAL_TYPE>
class AbstractScalarType {
public:
using LocalType = LOCAL_TYPE;
};
class Int32 : public AbstractScalarType<int32_t>{
public:
static bool encode(pb_ostream_t *stream, const LocalType& value);
static bool decode(pb_istream_t *stream, LocalType& value);
};
class SInt32 : public AbstractScalarType<int32_t>{
public:
static bool encode(pb_ostream_t *stream, const LocalType& value);
static bool decode(pb_istream_t *stream, LocalType& value);
};
class UInt32 : public AbstractScalarType<uint32_t>{
public:
static bool encode(pb_ostream_t *stream, const LocalType& value);
static bool decode(pb_istream_t *stream, LocalType& value);
};
class Fixed32 : public AbstractScalarType<uint32_t>{
public:
static bool encode(pb_ostream_t *stream, const LocalType& value);
static bool decode(pb_istream_t *stream, LocalType& value);
};
class SFixed32 : public AbstractScalarType<int32_t>{
public:
static bool encode(pb_ostream_t *stream, const LocalType& value);
static bool decode(pb_istream_t *stream, LocalType& value);
};
class Float : public AbstractScalarType<float>{
public:
static bool encode(pb_ostream_t *stream, const LocalType& value);
static bool decode(pb_istream_t *stream, LocalType& value);
};
class Bool : public AbstractScalarType<bool>{
public:
static bool encode(pb_ostream_t *stream, const LocalType& value);
static bool decode(pb_istream_t *stream, LocalType& value);
};
/**
* NOTE: encode()/decode() **does NOT** add length for String/Bytes
*/
class String : public AbstractScalarType<std::string>{
public:
static bool encode(pb_ostream_t *stream, const LocalType& value);
static bool decode(pb_istream_t *stream, LocalType& value);
};
/**
* NOTE: encode()/decode() **does NOT** add length for String/Bytes
*/
class Bytes : public AbstractScalarType<std::string>{ // use std::string as container
public:
static bool encode(pb_ostream_t *stream, const LocalType& value);
static bool decode(pb_istream_t *stream, LocalType& value);
};
#ifndef PB_WITHOUT_64BIT
class Int64 : public AbstractScalarType<int64_t>{
public:
static bool encode(pb_ostream_t *stream, const LocalType& value);
static bool decode(pb_istream_t *stream, LocalType& value);
};
class SInt64 : public AbstractScalarType<int64_t>{
public:
static bool encode(pb_ostream_t *stream, const LocalType& value);
static bool decode(pb_istream_t *stream, LocalType& value);
};
class UInt64 : public AbstractScalarType<uint64_t>{
public:
static bool encode(pb_ostream_t *stream, const LocalType& value);
static bool decode(pb_istream_t *stream, LocalType& value);
};
class Fixed64 : public AbstractScalarType<uint64_t>{
public:
static bool encode(pb_ostream_t *stream, const LocalType& value);
static bool decode(pb_istream_t *stream, LocalType& value);
};
class SFixed64 : public AbstractScalarType<int64_t>{
public:
static bool encode(pb_ostream_t *stream, const LocalType& value);
static bool decode(pb_istream_t *stream, LocalType& value);
};
class Double : public AbstractScalarType<double>{
public:
static bool encode(pb_ostream_t *stream, const LocalType& value);
static bool decode(pb_istream_t *stream, LocalType& value);
};
#endif
}
namespace Converter {
/**
* Callback converter
*
* Derived class must implement next methods:
*
* static bool encodeCallback(pb_ostream_t *stream, const pb_field_t *field, const LocalType &local);
* static bool decodeCallback(pb_istream_t *stream, const pb_field_t *field, LocalType &local);
*
* NOTE: Usually user must implement `MessageConverter` and NOT extend this class directly.
*
* @tparam DERIVED - Derived class
* @tparam LOCAL_TYPE - Local type
*/
template<class DERIVED, class LOCAL_TYPE>
class CallbackConverter {
public:
using LocalType = LOCAL_TYPE;
public:
static pb_callback_t encoderCallbackInit(const LocalType& local) { return pb_callback_t{ .funcs = { .encode = _pbEncodeCallback }, .arg = (void*)&local }; }
static pb_callback_t decoderCallbackInit(LocalType& local) { return pb_callback_t{ .funcs = { .decode = _pbDecodeCallback }, .arg = (void*)&local }; }
private:
static bool _pbEncodeCallback(pb_ostream_t *stream, const pb_field_t *field, void *const *arg){
return DERIVED::encodeCallback(stream, field, *(static_cast<const LocalType *>(*arg)));
};
static bool _pbDecodeCallback(pb_istream_t *stream, const pb_field_t *field, void **arg){
return DERIVED::decodeCallback(stream, field, *(static_cast<LocalType *>(*arg)));
};
public: // for internal use
template<class T> static void _mapEncoderApply(T& pair){}
};
/**
* Enum converter
*
* Derived class must implement next methods:
*
* static ProtoType encode(const LocalType& local);
* static LocalType decode(const ProtoType& proto);
*
* @tparam DERIVED - Derived class
* @tparam LOCAL_TYPE - Local type
* @tparam PROTO_TYPE - NanoPb type
*/
template<class DERIVED, class LOCAL_TYPE, class PROTO_TYPE>
class EnumConverter : public CallbackConverter<
EnumConverter<DERIVED, LOCAL_TYPE, PROTO_TYPE>,
LOCAL_TYPE>
{
public:
using LocalType = LOCAL_TYPE;
using ProtoType = PROTO_TYPE;
public:
static bool encodeCallback(pb_ostream_t *stream, const pb_field_t *field, const LocalType &local){
if (!pb_encode_tag_for_field(stream, field))
return false;
ProtoType v = DERIVED::encode(local);
return Type::Int32::encode(stream, v);
}
static bool decodeCallback(pb_istream_t *stream, const pb_field_t *field, LocalType &local){
int32_t v;
if (!Type::Int32::decode(stream, v))
return false;
local = DERIVED::decode(static_cast<ProtoType>(v));
return true;
}
public:
static ProtoType encoderInit(const LocalType& local){
return DERIVED::encode(local);
}
static ProtoType decoderInit(LocalType& local){ return ProtoType{}; }
static bool decoderApply(const ProtoType& proto, LocalType& local){
local = DERIVED::decode(proto);
return true;
}
public: // for internal use
template<class T> static void _mapEncoderApply(T& pair){}
};
/**
* Message converter
*
* Derived class must implement next methods:
*
* static ProtoType encoderInit(const LocalType& local);
* static ProtoType decoderInit(LocalType& local);
* static bool decoderApply(const ProtoType& proto, LocalType& local);
*
* @tparam DERIVED - Derived class
* @tparam LOCAL_TYPE - Local type
* @tparam PROTO_TYPE - NanoPb type
* @tparam PROTO_TYPE_MSG - NanoPb msg descriptor
*/
template<class DERIVED, class LOCAL_TYPE, class PROTO_TYPE, const pb_msgdesc_t* PROTO_TYPE_MSG>
class MessageConverter : public CallbackConverter<
MessageConverter<DERIVED, LOCAL_TYPE, PROTO_TYPE, PROTO_TYPE_MSG>,
LOCAL_TYPE>
{
public:
using LocalType = LOCAL_TYPE;
using ProtoType = PROTO_TYPE;
/**
* You can define custom DecoderContext.
* This can be useful to store temporary vars.
* See examples/comlex/converters.hpp for the details.
*/
using DecoderContext = LocalType&;
public:
static constexpr const pb_msgdesc_t *getMsgType(){ return PROTO_TYPE_MSG; }
public:
static bool encodeCallback(pb_ostream_t *stream, const pb_field_t *field, const LocalType &local){
if (!pb_encode_tag_for_field(stream, field))
return false;
return encodeSubMessage<DERIVED>(*stream, local);
}
static bool decodeCallback(pb_istream_t *stream, const pb_field_t *field, LocalType &local){
return decode<DERIVED>(*stream, local);
}
public: // for internal use
template<class T>
static void _mapEncoderApply(T& pair){ pair.has_value = true; }
};
/**
* Union message converter
*
* Derived class must implement:
*
* - all methods from MessageConverter.
* - additional methods:
*
* static bool unionDecodeCallback(pb_istream_t *stream, const pb_field_t *field, LocalType &local);
*
* @tparam DERIVED - Derived class
* @tparam LOCAL_TYPE - Local type
* @tparam PROTO_TYPE - NanoPb type
* @tparam PROTO_TYPE_MSG - NanoPb msg descriptor
*/
template<class DERIVED, class LOCAL_TYPE, class PROTO_TYPE, const pb_msgdesc_t* PROTO_TYPE_MSG>
class UnionMessageConverter : public MessageConverter<DERIVED, LOCAL_TYPE, PROTO_TYPE, PROTO_TYPE_MSG>{
public:
using LocalType = LOCAL_TYPE;
using ProtoType = PROTO_TYPE;
static pb_callback_t unionDecoderInit(LocalType& local) { return pb_callback_t{ .funcs = { .decode = _unionDecodeCallback }, .arg = (void*)&local }; }
private:
static bool _unionDecodeCallback(pb_istream_t *stream, const pb_field_t *field, void **arg){
return DERIVED::unionDecodeCallback(stream, field, *(static_cast<LocalType *>(*arg)));
}
};
/**
* Basic scalar converter.
*
* Can be used for field with wire types: PB_WT_VARINT, PB_WT_64BIT, PB_WT_32BIT
*
* @tparam DERIVED - Derived class
* @tparam SCALAR - Scalar with one of listed above wire type.
*/
template <class DERIVED, class SCALAR>
class AbstractScalarConverter : public CallbackConverter<DERIVED, typename SCALAR::LocalType> {
public:
using LocalType = typename SCALAR::LocalType;
using ProtoType = typename SCALAR::LocalType; // Proto type for basic scalar is same as local.
public:
static bool encodeCallback(pb_ostream_t *stream, const pb_field_t *field, const LocalType &local){
if (!pb_encode_tag_for_field(stream, field))
return false;
return SCALAR::encode(stream, local);
}
static bool decodeCallback(pb_istream_t *stream, const pb_field_t *field, LocalType &local){
return SCALAR::decode(stream, local);
}
public:
static ProtoType encoderInit(const LocalType& local){ return local;}
static ProtoType decoderInit(LocalType& local){ return ProtoType{}; }
static bool decoderApply(const ProtoType& proto, LocalType& local){
local = proto;
return true;
}
};
/**
* Set of basic scalar types converters to used in ArrayConverter and other cases
*/
class Int32Converter : public AbstractScalarConverter<Int32Converter,Type::Int32> {};
class SInt32Converter : public AbstractScalarConverter<SInt32Converter,Type::SInt32> {};
class UInt32Converter : public AbstractScalarConverter<UInt32Converter,Type::UInt32> {};
class Fixed32Converter : public AbstractScalarConverter<Fixed32Converter,Type::Fixed32> {};
class SFixed32Converter : public AbstractScalarConverter<SFixed32Converter,Type::SFixed32> {};
class FloatConverter : public AbstractScalarConverter<FloatConverter,Type::Float> {};
class BoolConverter : public AbstractScalarConverter<BoolConverter,Type::Bool> {};
#ifndef PB_WITHOUT_64BIT
class Int64Converter : public AbstractScalarConverter<Int64Converter,Type::Int64> {};
class SInt64Converter : public AbstractScalarConverter<SInt64Converter,Type::SInt64> {};
class UInt64Converter : public AbstractScalarConverter<UInt64Converter,Type::UInt64> {};
class Fixed64Converter : public AbstractScalarConverter<Fixed64Converter,Type::Fixed64> {};
class SFixed64Converter : public AbstractScalarConverter<SFixed64Converter,Type::SFixed64> {};
class DoubleConverter : public AbstractScalarConverter<DoubleConverter,Type::Double> {};
#endif
class StringConverter : public CallbackConverter<StringConverter, std::string> {
public:
static bool encodeCallback(pb_ostream_t *stream, const pb_field_t *field, const LocalType &local);
static bool decodeCallback(pb_istream_t *stream, const pb_field_t *field, LocalType &local);
public:
static pb_callback_t encoderInit(const LocalType& local){ return encoderCallbackInit(local);}
static pb_callback_t decoderInit(LocalType& local){ return decoderCallbackInit(local);}
static bool decoderApply(const pb_callback_t& proto, LocalType& local){ return true;/* nothing to apply */}
};
class BytesConverter : public CallbackConverter<BytesConverter, std::string> {
public:
static bool encodeCallback(pb_ostream_t *stream, const pb_field_t *field, const LocalType &local);
static bool decodeCallback(pb_istream_t *stream, const pb_field_t *field, LocalType &local);
public:
static pb_callback_t encoderInit(const LocalType& local){ return encoderCallbackInit(local);}
static pb_callback_t decoderInit(LocalType& local){ return decoderCallbackInit(local);}
static bool decoderApply(const pb_callback_t& proto, LocalType& local){ return true;/* nothing to apply */}
};
/**
* Array converter for items
*
* @tparam ITEM_CONVERTER - Derived from MessageConverter class
* @tparam CONTAINER can be std::vector<ITEM_CONVERTER::LocalType> or std::ITEM_CONVERTER::LocalType>
*
* NOTE: ITEM_CONVERTER::LocalType and CONTAINER::value_type should match each other
*/
template<class ITEM_CONVERTER, class CONTAINER>
class ArrayConverter : public CallbackConverter<ArrayConverter<ITEM_CONVERTER, CONTAINER>,CONTAINER>
{
static_assert(std::is_same<typename ITEM_CONVERTER::LocalType, typename CONTAINER::value_type>::value,
"ITEM_CONVERTER::LocalType and CONTAINER::value_type should be same type");
public:
static bool encodeCallback(pb_ostream_t *stream, const pb_field_t *field, const CONTAINER &container){
for (const auto &item: container) {
if (!ITEM_CONVERTER::encodeCallback(stream, field, item))
return false;
}
return true;
}
static bool decodeCallback(pb_istream_t *stream, const pb_field_t *field, CONTAINER &container){
container.emplace_back(typename ITEM_CONVERTER::LocalType());
typename ITEM_CONVERTER::LocalType& item = *container.rbegin();
if (!ITEM_CONVERTER::decodeCallback(stream, field, item))
return false;
return true;
}
};
/**
* Map converter
*
* @tparam KEY_CONVERTER - Key converter
* @tparam VALUE_CONVERTER - Value converter
* @tparam CONTAINER - std::map<> of any type
* @tparam PROTO_PAIR_TYPE - NanoPb XXX_xxxEntry struct, where xxx is map field
* @tparam PROTO_PAIR_TYPE_MSG - NanoPb msg descriptor for PROTO_PAIR_TYPE
*/
template<class KEY_CONVERTER, class VALUE_CONVERTER, class CONTAINER, class PROTO_PAIR_TYPE, const pb_msgdesc_t* PROTO_PAIR_TYPE_MSG>
class MapConverter : public CallbackConverter<
MapConverter<KEY_CONVERTER, VALUE_CONVERTER, CONTAINER, PROTO_PAIR_TYPE, PROTO_PAIR_TYPE_MSG>,
CONTAINER>
{
static_assert(std::is_same<typename KEY_CONVERTER::LocalType, typename CONTAINER::key_type>::value,
"KEY_CONVERTER::LocalType and CONTAINER::key_type should be same type");
static_assert(std::is_same<typename VALUE_CONVERTER::LocalType, typename CONTAINER::mapped_type>::value,
"VALUE_CONVERTER::LocalType and CONTAINER::mapped_type should be same type");
private:
using LocalKeyType = typename CONTAINER::key_type;
using LocalValueType = typename CONTAINER::mapped_type;
using ProtoPairType = PROTO_PAIR_TYPE;
using ContextPairType = std::pair<LocalKeyType,LocalValueType>;
public:
static bool encodeCallback(pb_ostream_t *stream, const pb_field_t *field, const CONTAINER &container){
for (auto &pair: container) {
if (!pb_encode_tag_for_field(stream, field))
return false;
ProtoPairType protoPair {
.key = KEY_CONVERTER::encoderInit(pair.first),
.value = VALUE_CONVERTER::encoderInit(pair.second)
};
VALUE_CONVERTER::template _mapEncoderApply<ProtoPairType>(protoPair);
if (!pb_encode_submessage(stream, PROTO_PAIR_TYPE_MSG, &protoPair))
return false;
}
return true;
}
static bool decodeCallback(pb_istream_t *stream, const pb_field_t *field, CONTAINER &container){
LocalKeyType localKey;
LocalValueType localValue;
ProtoPairType protoPair {
.key = KEY_CONVERTER::decoderInit(localKey),
.value = VALUE_CONVERTER::decoderInit(localValue)
};
if (!pb_decode(stream, PROTO_PAIR_TYPE_MSG, &protoPair))
return false;
if (!KEY_CONVERTER::decoderApply(protoPair.key, localKey))
return false;
if (!VALUE_CONVERTER::decoderApply(protoPair.value, localValue))
return false;
container.insert(std::move(ContextPairType(std::move(localKey), std::move(localValue))));
return true;
}
};
}
}
#endif //NANOPB_CPP_NANOPB_CPP_H