add nanopb (manual)

This commit is contained in:
Philippe G
2022-01-04 11:01:14 -08:00
parent 06b637c55b
commit 39f5a81238
554 changed files with 36793 additions and 3831 deletions

View File

@@ -0,0 +1,11 @@
# Check that the old generated .pb.c/.pb.h files are still compatible with the
# current version of nanopb.
Import("env")
enc = env.Program(["encode_legacy.c", "alltypes_legacy.c", "$COMMON/pb_encode.o", "$COMMON/pb_common.o"])
dec = env.Program(["decode_legacy.c", "alltypes_legacy.c", "$COMMON/pb_decode.o", "$COMMON/pb_common.o"])
env.RunTest(enc)
env.RunTest([dec, "encode_legacy.output"])

View File

@@ -0,0 +1,40 @@
/* Automatically generated nanopb constant definitions */
/* Generated by nanopb-0.4.0-dev */
#include "alltypes_legacy.h"
/* @@protoc_insertion_point(includes) */
#if PB_PROTO_HEADER_VERSION != 40
#error Regenerate this file with the current version of nanopb generator.
#endif
pb_byte_t SubMessage_DEFAULT[] = {0x0a, 0x01, 0x31, 0x10, 0x02, 0x1d, 0x03, 0x00, 0x00, 0x00, 0x00};
pb_byte_t EmptyMessage_DEFAULT[] = {0x00};
pb_byte_t Limits_DEFAULT[] = {0x08, 0xff, 0xff, 0xff, 0xff, 0x07, 0x10, 0x81, 0x80, 0x80, 0x80, 0xf8, 0xff, 0xff, 0xff, 0xff, 0x01, 0x18, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x20, 0x00, 0x28, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x30, 0x81, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01, 0x38, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x40, 0x00, 0x48, 0xff, 0xff, 0xff, 0xff, 0x07, 0x50, 0x81, 0x80, 0x80, 0x80, 0xf8, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00};
pb_byte_t AllTypes_DEFAULT[] = {0xc8, 0x02, 0xc9, 0x1f, 0xd0, 0x02, 0xca, 0x1f, 0xd8, 0x02, 0xcb, 0x1f, 0xe0, 0x02, 0xcc, 0x1f, 0xe8, 0x02, 0x9a, 0x3f, 0xf0, 0x02, 0x9c, 0x3f, 0xf8, 0x02, 0x00, 0x85, 0x03, 0xd0, 0x0f, 0x00, 0x00, 0x8d, 0x03, 0xd1, 0x0f, 0x00, 0x00, 0x95, 0x03, 0x00, 0x20, 0x7d, 0x45, 0x99, 0x03, 0xd3, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa1, 0x03, 0xd4, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa9, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaf, 0x40, 0xb2, 0x03, 0x04, 0x34, 0x30, 0x35, 0x34, 0xba, 0x03, 0x04, 0x34, 0x30, 0x35, 0x35, 0xc8, 0x03, 0x02, 0x00};
PB_BIND(SubMessage, SubMessage, AUTO)
PB_BIND(EmptyMessage, EmptyMessage, AUTO)
PB_BIND(Limits, Limits, AUTO)
PB_BIND(AllTypes, AllTypes, 2)
#ifndef PB_CONVERT_DOUBLE_FLOAT
/* On some platforms (such as AVR), double is really float.
* Using double on these platforms is not directly supported
* by nanopb, but see example_avr_double.
* To get rid of this error, remove any double fields from your .proto.
*/
PB_STATIC_ASSERT(sizeof(double) == 8, DOUBLE_MUST_BE_8_BYTES)
#endif
/* @@protoc_insertion_point(eof) */

View File

@@ -0,0 +1,348 @@
/* Automatically generated nanopb header */
/* Generated by nanopb-0.4.0-dev */
#ifndef PB_ALLTYPES_LEGACY_H_INCLUDED
#define PB_ALLTYPES_LEGACY_H_INCLUDED
#include <pb.h>
/* @@protoc_insertion_point(includes) */
#if PB_PROTO_HEADER_VERSION != 40
#error Regenerate this file with the current version of nanopb generator.
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* Enum definitions */
typedef enum _HugeEnum {
HugeEnum_Negative = -2147483647,
HugeEnum_Positive = 2147483647
} HugeEnum;
#define _HugeEnum_MIN HugeEnum_Negative
#define _HugeEnum_MAX HugeEnum_Positive
#define _HugeEnum_ARRAYSIZE ((HugeEnum)(HugeEnum_Positive+1))
typedef enum _MyEnum {
MyEnum_Zero = 0,
MyEnum_First = 1,
MyEnum_Second = 2,
MyEnum_Truth = 42
} MyEnum;
#define _MyEnum_MIN MyEnum_Zero
#define _MyEnum_MAX MyEnum_Truth
#define _MyEnum_ARRAYSIZE ((MyEnum)(MyEnum_Truth+1))
/* Struct definitions */
typedef struct _EmptyMessage {
char dummy_field;
/* @@protoc_insertion_point(struct:EmptyMessage) */
} EmptyMessage;
typedef struct _Limits {
int32_t int32_min;
int32_t int32_max;
uint32_t uint32_min;
uint32_t uint32_max;
int64_t int64_min;
int64_t int64_max;
uint64_t uint64_min;
uint64_t uint64_max;
HugeEnum enum_min;
HugeEnum enum_max;
/* @@protoc_insertion_point(struct:Limits) */
} Limits;
typedef struct _SubMessage {
char substuff1[16];
int32_t substuff2;
bool has_substuff3;
uint32_t substuff3;
/* @@protoc_insertion_point(struct:SubMessage) */
} SubMessage;
typedef PB_BYTES_ARRAY_T(16) AllTypes_req_bytes_t;
typedef PB_BYTES_ARRAY_T(16) AllTypes_rep_bytes_t;
typedef PB_BYTES_ARRAY_T(16) AllTypes_opt_bytes_t;
typedef struct _AllTypes {
int32_t req_int32;
int64_t req_int64;
uint32_t req_uint32;
uint64_t req_uint64;
int32_t req_sint32;
int64_t req_sint64;
bool req_bool;
uint32_t req_fixed32;
int32_t req_sfixed32;
float req_float;
uint64_t req_fixed64;
int64_t req_sfixed64;
double req_double;
char req_string[16];
AllTypes_req_bytes_t req_bytes;
SubMessage req_submsg;
MyEnum req_enum;
pb_size_t rep_int32_count;
int32_t rep_int32[5];
pb_size_t rep_int64_count;
int64_t rep_int64[5];
pb_size_t rep_uint32_count;
uint32_t rep_uint32[5];
pb_size_t rep_uint64_count;
uint64_t rep_uint64[5];
pb_size_t rep_sint32_count;
int32_t rep_sint32[5];
pb_size_t rep_sint64_count;
int64_t rep_sint64[5];
pb_size_t rep_bool_count;
bool rep_bool[5];
pb_size_t rep_fixed32_count;
uint32_t rep_fixed32[5];
pb_size_t rep_sfixed32_count;
int32_t rep_sfixed32[5];
pb_size_t rep_float_count;
float rep_float[5];
pb_size_t rep_fixed64_count;
uint64_t rep_fixed64[5];
pb_size_t rep_sfixed64_count;
int64_t rep_sfixed64[5];
pb_size_t rep_double_count;
double rep_double[5];
pb_size_t rep_string_count;
char rep_string[5][16];
pb_size_t rep_bytes_count;
AllTypes_rep_bytes_t rep_bytes[5];
pb_size_t rep_submsg_count;
SubMessage rep_submsg[5];
pb_size_t rep_enum_count;
MyEnum rep_enum[5];
bool has_opt_int32;
int32_t opt_int32;
bool has_opt_int64;
int64_t opt_int64;
bool has_opt_uint32;
uint32_t opt_uint32;
bool has_opt_uint64;
uint64_t opt_uint64;
bool has_opt_sint32;
int32_t opt_sint32;
bool has_opt_sint64;
int64_t opt_sint64;
bool has_opt_bool;
bool opt_bool;
bool has_opt_fixed32;
uint32_t opt_fixed32;
bool has_opt_sfixed32;
int32_t opt_sfixed32;
bool has_opt_float;
float opt_float;
bool has_opt_fixed64;
uint64_t opt_fixed64;
bool has_opt_sfixed64;
int64_t opt_sfixed64;
bool has_opt_double;
double opt_double;
bool has_opt_string;
char opt_string[16];
bool has_opt_bytes;
AllTypes_opt_bytes_t opt_bytes;
bool has_opt_submsg;
SubMessage opt_submsg;
bool has_opt_enum;
MyEnum opt_enum;
int32_t end;
pb_extension_t *extensions;
/* @@protoc_insertion_point(struct:AllTypes) */
} AllTypes;
/* Initializer values for message structs */
#define SubMessage_init_default {"1", 2, false, 3u}
#define EmptyMessage_init_default {0}
#define Limits_init_default {2147483647, -2147483647, 4294967295u, 0u, 9223372036854775807ll, -9223372036854775807ll, 18446744073709551615ull, 0ull, HugeEnum_Positive, HugeEnum_Negative}
#define AllTypes_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", {0, {0}}, SubMessage_init_default, _MyEnum_MIN, 0, {0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0}, 0, {"", "", "", "", ""}, 0, {{0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}}, 0, {SubMessage_init_default, SubMessage_init_default, SubMessage_init_default, SubMessage_init_default, SubMessage_init_default}, 0, {_MyEnum_MIN, _MyEnum_MIN, _MyEnum_MIN, _MyEnum_MIN, _MyEnum_MIN}, false, 4041, false, 4042ll, false, 4043u, false, 4044ull, false, 4045, false, 4046, false, false, false, 4048u, false, 4049, false, 4050, false, 4051ull, false, 4052ll, false, 4053, false, "4054", false, {4, {0x34,0x30,0x35,0x35}}, false, SubMessage_init_default, false, MyEnum_Second, 0, NULL}
#define SubMessage_init_zero {"", 0, false, 0}
#define EmptyMessage_init_zero {0}
#define Limits_init_zero {0, 0, 0, 0, 0, 0, 0, 0, _HugeEnum_MIN, _HugeEnum_MIN}
#define AllTypes_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", {0, {0}}, SubMessage_init_zero, _MyEnum_MIN, 0, {0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0}, 0, {"", "", "", "", ""}, 0, {{0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}}, 0, {SubMessage_init_zero, SubMessage_init_zero, SubMessage_init_zero, SubMessage_init_zero, SubMessage_init_zero}, 0, {_MyEnum_MIN, _MyEnum_MIN, _MyEnum_MIN, _MyEnum_MIN, _MyEnum_MIN}, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, "", false, {0, {0}}, false, SubMessage_init_zero, false, _MyEnum_MIN, 0, NULL}
/* Field tags (for use in manual encoding/decoding) */
#define Limits_int32_min_tag 1
#define Limits_int32_max_tag 2
#define Limits_uint32_min_tag 3
#define Limits_uint32_max_tag 4
#define Limits_int64_min_tag 5
#define Limits_int64_max_tag 6
#define Limits_uint64_min_tag 7
#define Limits_uint64_max_tag 8
#define Limits_enum_min_tag 9
#define Limits_enum_max_tag 10
#define SubMessage_substuff1_tag 1
#define SubMessage_substuff2_tag 2
#define SubMessage_substuff3_tag 3
#define AllTypes_req_int32_tag 1
#define AllTypes_req_int64_tag 2
#define AllTypes_req_uint32_tag 3
#define AllTypes_req_uint64_tag 4
#define AllTypes_req_sint32_tag 5
#define AllTypes_req_sint64_tag 6
#define AllTypes_req_bool_tag 7
#define AllTypes_req_fixed32_tag 8
#define AllTypes_req_sfixed32_tag 9
#define AllTypes_req_float_tag 10
#define AllTypes_req_fixed64_tag 11
#define AllTypes_req_sfixed64_tag 12
#define AllTypes_req_double_tag 13
#define AllTypes_req_string_tag 14
#define AllTypes_req_bytes_tag 15
#define AllTypes_req_submsg_tag 16
#define AllTypes_req_enum_tag 17
#define AllTypes_rep_int32_tag 21
#define AllTypes_rep_int64_tag 22
#define AllTypes_rep_uint32_tag 23
#define AllTypes_rep_uint64_tag 24
#define AllTypes_rep_sint32_tag 25
#define AllTypes_rep_sint64_tag 26
#define AllTypes_rep_bool_tag 27
#define AllTypes_rep_fixed32_tag 28
#define AllTypes_rep_sfixed32_tag 29
#define AllTypes_rep_float_tag 30
#define AllTypes_rep_fixed64_tag 31
#define AllTypes_rep_sfixed64_tag 32
#define AllTypes_rep_double_tag 33
#define AllTypes_rep_string_tag 34
#define AllTypes_rep_bytes_tag 35
#define AllTypes_rep_submsg_tag 36
#define AllTypes_rep_enum_tag 37
#define AllTypes_opt_int32_tag 41
#define AllTypes_opt_int64_tag 42
#define AllTypes_opt_uint32_tag 43
#define AllTypes_opt_uint64_tag 44
#define AllTypes_opt_sint32_tag 45
#define AllTypes_opt_sint64_tag 46
#define AllTypes_opt_bool_tag 47
#define AllTypes_opt_fixed32_tag 48
#define AllTypes_opt_sfixed32_tag 49
#define AllTypes_opt_float_tag 50
#define AllTypes_opt_fixed64_tag 51
#define AllTypes_opt_sfixed64_tag 52
#define AllTypes_opt_double_tag 53
#define AllTypes_opt_string_tag 54
#define AllTypes_opt_bytes_tag 55
#define AllTypes_opt_submsg_tag 56
#define AllTypes_opt_enum_tag 57
#define AllTypes_end_tag 99
/* Struct field encoding specification for nanopb */
#define SubMessage_FIELDLIST(X, a) \
X(a, STATIC, REQUIRED, STRING, substuff1, 1) \
X(a, STATIC, REQUIRED, INT32, substuff2, 2) \
X(a, STATIC, OPTIONAL, FIXED32, substuff3, 3)
#define SubMessage_CALLBACK NULL
#define EmptyMessage_FIELDLIST(X, a) \
#define EmptyMessage_CALLBACK NULL
#define Limits_FIELDLIST(X, a) \
X(a, STATIC, REQUIRED, INT32, int32_min, 1) \
X(a, STATIC, REQUIRED, INT32, int32_max, 2) \
X(a, STATIC, REQUIRED, UINT32, uint32_min, 3) \
X(a, STATIC, REQUIRED, UINT32, uint32_max, 4) \
X(a, STATIC, REQUIRED, INT64, int64_min, 5) \
X(a, STATIC, REQUIRED, INT64, int64_max, 6) \
X(a, STATIC, REQUIRED, UINT64, uint64_min, 7) \
X(a, STATIC, REQUIRED, UINT64, uint64_max, 8) \
X(a, STATIC, REQUIRED, ENUM, enum_min, 9) \
X(a, STATIC, REQUIRED, ENUM, enum_max, 10)
#define Limits_CALLBACK NULL
#define AllTypes_FIELDLIST(X, a) \
X(a, STATIC, REQUIRED, INT32, req_int32, 1) \
X(a, STATIC, REQUIRED, INT64, req_int64, 2) \
X(a, STATIC, REQUIRED, UINT32, req_uint32, 3) \
X(a, STATIC, REQUIRED, UINT64, req_uint64, 4) \
X(a, STATIC, REQUIRED, SINT32, req_sint32, 5) \
X(a, STATIC, REQUIRED, SINT64, req_sint64, 6) \
X(a, STATIC, REQUIRED, BOOL, req_bool, 7) \
X(a, STATIC, REQUIRED, FIXED32, req_fixed32, 8) \
X(a, STATIC, REQUIRED, SFIXED32, req_sfixed32, 9) \
X(a, STATIC, REQUIRED, FLOAT, req_float, 10) \
X(a, STATIC, REQUIRED, FIXED64, req_fixed64, 11) \
X(a, STATIC, REQUIRED, SFIXED64, req_sfixed64, 12) \
X(a, STATIC, REQUIRED, DOUBLE, req_double, 13) \
X(a, STATIC, REQUIRED, STRING, req_string, 14) \
X(a, STATIC, REQUIRED, BYTES, req_bytes, 15) \
X(a, STATIC, REQUIRED, MESSAGE, req_submsg, 16) \
X(a, STATIC, REQUIRED, UENUM, req_enum, 17) \
X(a, STATIC, REPEATED, INT32, rep_int32, 21) \
X(a, STATIC, REPEATED, INT64, rep_int64, 22) \
X(a, STATIC, REPEATED, UINT32, rep_uint32, 23) \
X(a, STATIC, REPEATED, UINT64, rep_uint64, 24) \
X(a, STATIC, REPEATED, SINT32, rep_sint32, 25) \
X(a, STATIC, REPEATED, SINT64, rep_sint64, 26) \
X(a, STATIC, REPEATED, BOOL, rep_bool, 27) \
X(a, STATIC, REPEATED, FIXED32, rep_fixed32, 28) \
X(a, STATIC, REPEATED, SFIXED32, rep_sfixed32, 29) \
X(a, STATIC, REPEATED, FLOAT, rep_float, 30) \
X(a, STATIC, REPEATED, FIXED64, rep_fixed64, 31) \
X(a, STATIC, REPEATED, SFIXED64, rep_sfixed64, 32) \
X(a, STATIC, REPEATED, DOUBLE, rep_double, 33) \
X(a, STATIC, REPEATED, STRING, rep_string, 34) \
X(a, STATIC, REPEATED, BYTES, rep_bytes, 35) \
X(a, STATIC, REPEATED, MESSAGE, rep_submsg, 36) \
X(a, STATIC, REPEATED, UENUM, rep_enum, 37) \
X(a, STATIC, OPTIONAL, INT32, opt_int32, 41) \
X(a, STATIC, OPTIONAL, INT64, opt_int64, 42) \
X(a, STATIC, OPTIONAL, UINT32, opt_uint32, 43) \
X(a, STATIC, OPTIONAL, UINT64, opt_uint64, 44) \
X(a, STATIC, OPTIONAL, SINT32, opt_sint32, 45) \
X(a, STATIC, OPTIONAL, SINT64, opt_sint64, 46) \
X(a, STATIC, OPTIONAL, BOOL, opt_bool, 47) \
X(a, STATIC, OPTIONAL, FIXED32, opt_fixed32, 48) \
X(a, STATIC, OPTIONAL, SFIXED32, opt_sfixed32, 49) \
X(a, STATIC, OPTIONAL, FLOAT, opt_float, 50) \
X(a, STATIC, OPTIONAL, FIXED64, opt_fixed64, 51) \
X(a, STATIC, OPTIONAL, SFIXED64, opt_sfixed64, 52) \
X(a, STATIC, OPTIONAL, DOUBLE, opt_double, 53) \
X(a, STATIC, OPTIONAL, STRING, opt_string, 54) \
X(a, STATIC, OPTIONAL, BYTES, opt_bytes, 55) \
X(a, STATIC, OPTIONAL, MESSAGE, opt_submsg, 56) \
X(a, STATIC, OPTIONAL, UENUM, opt_enum, 57) \
X(a, STATIC, REQUIRED, INT32, end, 99) \
X(a, CALLBACK, OPTIONAL, EXTENSION, extensions, 200)
#define AllTypes_CALLBACK pb_default_field_callback
#define AllTypes_req_submsg_MSGTYPE SubMessage
#define AllTypes_rep_submsg_MSGTYPE SubMessage
#define AllTypes_opt_submsg_MSGTYPE SubMessage
extern const pb_msgdesc_t SubMessage_msg;
extern pb_byte_t SubMessage_default[];
extern const pb_msgdesc_t EmptyMessage_msg;
extern pb_byte_t EmptyMessage_default[];
extern const pb_msgdesc_t Limits_msg;
extern pb_byte_t Limits_default[];
extern const pb_msgdesc_t AllTypes_msg;
extern pb_byte_t AllTypes_default[];
/* Defines for backwards compatibility with code written before nanopb-0.4.0 */
#define SubMessage_fields &SubMessage_msg
#define EmptyMessage_fields &EmptyMessage_msg
#define Limits_fields &Limits_msg
#define AllTypes_fields &AllTypes_msg
/* Maximum encoded size of messages (where known) */
#define SubMessage_size 33
#define EmptyMessage_size 0
#define Limits_size 100
#define AllTypes_size 1320
#ifdef __cplusplus
} /* extern "C" */
#endif
/* @@protoc_insertion_point(eof) */
#endif

View File

@@ -0,0 +1,3 @@
* max_size:16
* max_count:5

View File

@@ -0,0 +1,110 @@
syntax = "proto2";
message SubMessage {
required string substuff1 = 1 [default = "1"];
required int32 substuff2 = 2 [default = 2];
optional fixed32 substuff3 = 3 [default = 3];
}
message EmptyMessage {
}
enum HugeEnum {
Negative = -2147483647; /* protoc doesn't accept -2147483648 here */
Positive = 2147483647;
}
message Limits {
required int32 int32_min = 1 [default = 2147483647];
required int32 int32_max = 2 [default = -2147483647];
required uint32 uint32_min = 3 [default = 4294967295];
required uint32 uint32_max = 4 [default = 0];
required int64 int64_min = 5 [default = 9223372036854775807];
required int64 int64_max = 6 [default = -9223372036854775807];
required uint64 uint64_min = 7 [default = 18446744073709551615];
required uint64 uint64_max = 8 [default = 0];
required HugeEnum enum_min = 9 [default = Positive];
required HugeEnum enum_max = 10 [default = Negative];
}
enum MyEnum {
Zero = 0;
First = 1;
Second = 2;
Truth = 42;
}
message AllTypes {
required int32 req_int32 = 1;
required int64 req_int64 = 2;
required uint32 req_uint32 = 3;
required uint64 req_uint64 = 4;
required sint32 req_sint32 = 5;
required sint64 req_sint64 = 6;
required bool req_bool = 7;
required fixed32 req_fixed32 = 8;
required sfixed32 req_sfixed32= 9;
required float req_float = 10;
required fixed64 req_fixed64 = 11;
required sfixed64 req_sfixed64= 12;
required double req_double = 13;
required string req_string = 14;
required bytes req_bytes = 15;
required SubMessage req_submsg = 16;
required MyEnum req_enum = 17;
repeated int32 rep_int32 = 21 [packed = true];
repeated int64 rep_int64 = 22 [packed = true];
repeated uint32 rep_uint32 = 23 [packed = true];
repeated uint64 rep_uint64 = 24 [packed = true];
repeated sint32 rep_sint32 = 25 [packed = true];
repeated sint64 rep_sint64 = 26 [packed = true];
repeated bool rep_bool = 27 [packed = true];
repeated fixed32 rep_fixed32 = 28 [packed = true];
repeated sfixed32 rep_sfixed32= 29 [packed = true];
repeated float rep_float = 30 [packed = true];
repeated fixed64 rep_fixed64 = 31 [packed = true];
repeated sfixed64 rep_sfixed64= 32 [packed = true];
repeated double rep_double = 33 [packed = true];
repeated string rep_string = 34;
repeated bytes rep_bytes = 35;
repeated SubMessage rep_submsg = 36;
repeated MyEnum rep_enum = 37 [packed = true];
optional int32 opt_int32 = 41 [default = 4041];
optional int64 opt_int64 = 42 [default = 4042];
optional uint32 opt_uint32 = 43 [default = 4043];
optional uint64 opt_uint64 = 44 [default = 4044];
optional sint32 opt_sint32 = 45 [default = 4045];
optional sint64 opt_sint64 = 46 [default = 4046];
optional bool opt_bool = 47 [default = false];
optional fixed32 opt_fixed32 = 48 [default = 4048];
optional sfixed32 opt_sfixed32= 49 [default = 4049];
optional float opt_float = 50 [default = 4050];
optional fixed64 opt_fixed64 = 51 [default = 4051];
optional sfixed64 opt_sfixed64= 52 [default = 4052];
optional double opt_double = 53 [default = 4053];
optional string opt_string = 54 [default = "4054"];
optional bytes opt_bytes = 55 [default = "4055"];
optional SubMessage opt_submsg = 56;
optional MyEnum opt_enum = 57 [default = Second];
// Just to make sure that the size of the fields has been calculated
// properly, i.e. otherwise a bug in last field might not be detected.
required int32 end = 99;
extensions 200 to 255;
}

View File

@@ -0,0 +1,196 @@
/* Tests the decoding of all types.
* This is a backwards-compatibility test, using alltypes_legacy.h.
* It is similar to decode_alltypes, but duplicated in order to allow
* decode_alltypes to test any new features introduced later.
*
* Run e.g. ./encode_legacy | ./decode_legacy
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <pb_decode.h>
#include "alltypes_legacy.h"
#include "test_helpers.h"
#include "unittests.h"
/* This function is called once from main(), it handles
the decoding and checks the fields. */
bool check_alltypes(pb_istream_t *stream, int mode)
{
AllTypes alltypes = {0};
int status = 0;
if (!pb_decode(stream, AllTypes_fields, &alltypes))
return false;
TEST(alltypes.req_int32 == -1001);
TEST(alltypes.req_int64 == -1002);
TEST(alltypes.req_uint32 == 1003);
TEST(alltypes.req_uint64 == 1004);
TEST(alltypes.req_sint32 == -1005);
TEST(alltypes.req_sint64 == -1006);
TEST(alltypes.req_bool == true);
TEST(alltypes.req_fixed32 == 1008);
TEST(alltypes.req_sfixed32 == -1009);
TEST(alltypes.req_float == 1010.0f);
TEST(alltypes.req_fixed64 == 1011);
TEST(alltypes.req_sfixed64 == -1012);
TEST(alltypes.req_double == 1013.0f);
TEST(strcmp(alltypes.req_string, "1014") == 0);
TEST(alltypes.req_bytes.size == 4);
TEST(memcmp(alltypes.req_bytes.bytes, "1015", 4) == 0);
TEST(strcmp(alltypes.req_submsg.substuff1, "1016") == 0);
TEST(alltypes.req_submsg.substuff2 == 1016);
TEST(alltypes.req_submsg.substuff3 == 3);
TEST(alltypes.req_enum == MyEnum_Truth);
TEST(alltypes.rep_int32_count == 5 && alltypes.rep_int32[4] == -2001 && alltypes.rep_int32[0] == 0);
TEST(alltypes.rep_int64_count == 5 && alltypes.rep_int64[4] == -2002 && alltypes.rep_int64[0] == 0);
TEST(alltypes.rep_uint32_count == 5 && alltypes.rep_uint32[4] == 2003 && alltypes.rep_uint32[0] == 0);
TEST(alltypes.rep_uint64_count == 5 && alltypes.rep_uint64[4] == 2004 && alltypes.rep_uint64[0] == 0);
TEST(alltypes.rep_sint32_count == 5 && alltypes.rep_sint32[4] == -2005 && alltypes.rep_sint32[0] == 0);
TEST(alltypes.rep_sint64_count == 5 && alltypes.rep_sint64[4] == -2006 && alltypes.rep_sint64[0] == 0);
TEST(alltypes.rep_bool_count == 5 && alltypes.rep_bool[4] == true && alltypes.rep_bool[0] == false);
TEST(alltypes.rep_fixed32_count == 5 && alltypes.rep_fixed32[4] == 2008 && alltypes.rep_fixed32[0] == 0);
TEST(alltypes.rep_sfixed32_count == 5 && alltypes.rep_sfixed32[4] == -2009 && alltypes.rep_sfixed32[0] == 0);
TEST(alltypes.rep_float_count == 5 && alltypes.rep_float[4] == 2010.0f && alltypes.rep_float[0] == 0.0f);
TEST(alltypes.rep_fixed64_count == 5 && alltypes.rep_fixed64[4] == 2011 && alltypes.rep_fixed64[0] == 0);
TEST(alltypes.rep_sfixed64_count == 5 && alltypes.rep_sfixed64[4] == -2012 && alltypes.rep_sfixed64[0] == 0);
TEST(alltypes.rep_double_count == 5 && alltypes.rep_double[4] == 2013.0 && alltypes.rep_double[0] == 0.0);
TEST(alltypes.rep_string_count == 5 && strcmp(alltypes.rep_string[4], "2014") == 0 && alltypes.rep_string[0][0] == '\0');
TEST(alltypes.rep_bytes_count == 5 && alltypes.rep_bytes[4].size == 4 && alltypes.rep_bytes[0].size == 0);
TEST(memcmp(alltypes.rep_bytes[4].bytes, "2015", 4) == 0);
TEST(alltypes.rep_submsg_count == 5);
TEST(strcmp(alltypes.rep_submsg[4].substuff1, "2016") == 0 && alltypes.rep_submsg[0].substuff1[0] == '\0');
TEST(alltypes.rep_submsg[4].substuff2 == 2016 && alltypes.rep_submsg[0].substuff2 == 0);
TEST(alltypes.rep_submsg[4].substuff3 == 2016 && alltypes.rep_submsg[0].substuff3 == 3);
TEST(alltypes.rep_enum_count == 5 && alltypes.rep_enum[4] == MyEnum_Truth && alltypes.rep_enum[0] == MyEnum_Zero);
if (mode == 0)
{
/* Expect default values */
TEST(alltypes.has_opt_int32 == false);
TEST(alltypes.opt_int32 == 4041);
TEST(alltypes.has_opt_int64 == false);
TEST(alltypes.opt_int64 == 4042);
TEST(alltypes.has_opt_uint32 == false);
TEST(alltypes.opt_uint32 == 4043);
TEST(alltypes.has_opt_uint64 == false);
TEST(alltypes.opt_uint64 == 4044);
TEST(alltypes.has_opt_sint32 == false);
TEST(alltypes.opt_sint32 == 4045);
TEST(alltypes.has_opt_sint64 == false);
TEST(alltypes.opt_sint64 == 4046);
TEST(alltypes.has_opt_bool == false);
TEST(alltypes.opt_bool == false);
TEST(alltypes.has_opt_fixed32 == false);
TEST(alltypes.opt_fixed32 == 4048);
TEST(alltypes.has_opt_sfixed32 == false);
TEST(alltypes.opt_sfixed32 == 4049);
TEST(alltypes.has_opt_float == false);
TEST(alltypes.opt_float == 4050.0f);
TEST(alltypes.has_opt_fixed64 == false);
TEST(alltypes.opt_fixed64 == 4051);
TEST(alltypes.has_opt_sfixed64 == false);
TEST(alltypes.opt_sfixed64 == 4052);
TEST(alltypes.has_opt_double == false);
TEST(alltypes.opt_double == 4053.0);
TEST(alltypes.has_opt_string == false);
TEST(strcmp(alltypes.opt_string, "4054") == 0);
TEST(alltypes.has_opt_bytes == false);
TEST(alltypes.opt_bytes.size == 4);
TEST(memcmp(alltypes.opt_bytes.bytes, "4055", 4) == 0);
TEST(alltypes.has_opt_submsg == false);
TEST(strcmp(alltypes.opt_submsg.substuff1, "1") == 0);
TEST(alltypes.opt_submsg.substuff2 == 2);
TEST(alltypes.opt_submsg.substuff3 == 3);
TEST(alltypes.has_opt_enum == false);
TEST(alltypes.opt_enum == MyEnum_Second);
}
else
{
/* Expect filled-in values */
TEST(alltypes.has_opt_int32 == true);
TEST(alltypes.opt_int32 == 3041);
TEST(alltypes.has_opt_int64 == true);
TEST(alltypes.opt_int64 == 3042);
TEST(alltypes.has_opt_uint32 == true);
TEST(alltypes.opt_uint32 == 3043);
TEST(alltypes.has_opt_uint64 == true);
TEST(alltypes.opt_uint64 == 3044);
TEST(alltypes.has_opt_sint32 == true);
TEST(alltypes.opt_sint32 == 3045);
TEST(alltypes.has_opt_sint64 == true);
TEST(alltypes.opt_sint64 == 3046);
TEST(alltypes.has_opt_bool == true);
TEST(alltypes.opt_bool == true);
TEST(alltypes.has_opt_fixed32 == true);
TEST(alltypes.opt_fixed32 == 3048);
TEST(alltypes.has_opt_sfixed32 == true);
TEST(alltypes.opt_sfixed32 == 3049);
TEST(alltypes.has_opt_float == true);
TEST(alltypes.opt_float == 3050.0f);
TEST(alltypes.has_opt_fixed64 == true);
TEST(alltypes.opt_fixed64 == 3051);
TEST(alltypes.has_opt_sfixed64 == true);
TEST(alltypes.opt_sfixed64 == 3052);
TEST(alltypes.has_opt_double == true);
TEST(alltypes.opt_double == 3053.0);
TEST(alltypes.has_opt_string == true);
TEST(strcmp(alltypes.opt_string, "3054") == 0);
TEST(alltypes.has_opt_bytes == true);
TEST(alltypes.opt_bytes.size == 4);
TEST(memcmp(alltypes.opt_bytes.bytes, "3055", 4) == 0);
TEST(alltypes.has_opt_submsg == true);
TEST(strcmp(alltypes.opt_submsg.substuff1, "3056") == 0);
TEST(alltypes.opt_submsg.substuff2 == 3056);
TEST(alltypes.opt_submsg.substuff3 == 3);
TEST(alltypes.has_opt_enum == true);
TEST(alltypes.opt_enum == MyEnum_Truth);
}
TEST(alltypes.end == 1099);
return status == 0;
}
int main(int argc, char **argv)
{
uint8_t buffer[1024];
size_t count;
pb_istream_t stream;
/* Whether to expect the optional values or the default values. */
int mode = (argc > 1) ? atoi(argv[1]) : 0;
/* Read the data into buffer */
SET_BINARY_MODE(stdin);
count = fread(buffer, 1, sizeof(buffer), stdin);
/* Construct a pb_istream_t for reading from the buffer */
stream = pb_istream_from_buffer(buffer, count);
/* Decode and print out the stuff */
if (!check_alltypes(&stream, mode))
{
printf("Parsing failed: %s\n", PB_GET_ERROR(&stream));
return 1;
} else {
return 0;
}
}

View File

@@ -0,0 +1,135 @@
/* Attempts to test all the datatypes supported by ProtoBuf.
* This is a backwards-compatibility test, using alltypes_legacy.h.
* It is similar to encode_alltypes, but duplicated in order to allow
* encode_alltypes to test any new features introduced later.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pb_encode.h>
#include "alltypes_legacy.h"
#include "test_helpers.h"
int main(int argc, char **argv)
{
int mode = (argc > 1) ? atoi(argv[1]) : 0;
/* Initialize the structure with constants */
AllTypes alltypes = {0};
alltypes.req_int32 = -1001;
alltypes.req_int64 = -1002;
alltypes.req_uint32 = 1003;
alltypes.req_uint64 = 1004;
alltypes.req_sint32 = -1005;
alltypes.req_sint64 = -1006;
alltypes.req_bool = true;
alltypes.req_fixed32 = 1008;
alltypes.req_sfixed32 = -1009;
alltypes.req_float = 1010.0f;
alltypes.req_fixed64 = 1011;
alltypes.req_sfixed64 = -1012;
alltypes.req_double = 1013.0;
strcpy(alltypes.req_string, "1014");
alltypes.req_bytes.size = 4;
memcpy(alltypes.req_bytes.bytes, "1015", 4);
strcpy(alltypes.req_submsg.substuff1, "1016");
alltypes.req_submsg.substuff2 = 1016;
alltypes.req_enum = MyEnum_Truth;
alltypes.rep_int32_count = 5; alltypes.rep_int32[4] = -2001;
alltypes.rep_int64_count = 5; alltypes.rep_int64[4] = -2002;
alltypes.rep_uint32_count = 5; alltypes.rep_uint32[4] = 2003;
alltypes.rep_uint64_count = 5; alltypes.rep_uint64[4] = 2004;
alltypes.rep_sint32_count = 5; alltypes.rep_sint32[4] = -2005;
alltypes.rep_sint64_count = 5; alltypes.rep_sint64[4] = -2006;
alltypes.rep_bool_count = 5; alltypes.rep_bool[4] = true;
alltypes.rep_fixed32_count = 5; alltypes.rep_fixed32[4] = 2008;
alltypes.rep_sfixed32_count = 5; alltypes.rep_sfixed32[4] = -2009;
alltypes.rep_float_count = 5; alltypes.rep_float[4] = 2010.0f;
alltypes.rep_fixed64_count = 5; alltypes.rep_fixed64[4] = 2011;
alltypes.rep_sfixed64_count = 5; alltypes.rep_sfixed64[4] = -2012;
alltypes.rep_double_count = 5; alltypes.rep_double[4] = 2013.0;
alltypes.rep_string_count = 5; strcpy(alltypes.rep_string[4], "2014");
alltypes.rep_bytes_count = 5; alltypes.rep_bytes[4].size = 4;
memcpy(alltypes.rep_bytes[4].bytes, "2015", 4);
alltypes.rep_submsg_count = 5;
strcpy(alltypes.rep_submsg[4].substuff1, "2016");
alltypes.rep_submsg[4].substuff2 = 2016;
alltypes.rep_submsg[4].has_substuff3 = true;
alltypes.rep_submsg[4].substuff3 = 2016;
alltypes.rep_enum_count = 5; alltypes.rep_enum[4] = MyEnum_Truth;
if (mode != 0)
{
/* Fill in values for optional fields */
alltypes.has_opt_int32 = true;
alltypes.opt_int32 = 3041;
alltypes.has_opt_int64 = true;
alltypes.opt_int64 = 3042;
alltypes.has_opt_uint32 = true;
alltypes.opt_uint32 = 3043;
alltypes.has_opt_uint64 = true;
alltypes.opt_uint64 = 3044;
alltypes.has_opt_sint32 = true;
alltypes.opt_sint32 = 3045;
alltypes.has_opt_sint64 = true;
alltypes.opt_sint64 = 3046;
alltypes.has_opt_bool = true;
alltypes.opt_bool = true;
alltypes.has_opt_fixed32 = true;
alltypes.opt_fixed32 = 3048;
alltypes.has_opt_sfixed32 = true;
alltypes.opt_sfixed32 = 3049;
alltypes.has_opt_float = true;
alltypes.opt_float = 3050.0f;
alltypes.has_opt_fixed64 = true;
alltypes.opt_fixed64 = 3051;
alltypes.has_opt_sfixed64 = true;
alltypes.opt_sfixed64 = 3052;
alltypes.has_opt_double = true;
alltypes.opt_double = 3053.0;
alltypes.has_opt_string = true;
strcpy(alltypes.opt_string, "3054");
alltypes.has_opt_bytes = true;
alltypes.opt_bytes.size = 4;
memcpy(alltypes.opt_bytes.bytes, "3055", 4);
alltypes.has_opt_submsg = true;
strcpy(alltypes.opt_submsg.substuff1, "3056");
alltypes.opt_submsg.substuff2 = 3056;
alltypes.has_opt_enum = true;
alltypes.opt_enum = MyEnum_Truth;
}
alltypes.end = 1099;
{
uint8_t buffer[1024];
pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
/* Now encode it and check if we succeeded. */
if (pb_encode(&stream, AllTypes_fields, &alltypes))
{
SET_BINARY_MODE(stdout);
fwrite(buffer, 1, stream.bytes_written, stdout);
return 0; /* Success */
}
else
{
fprintf(stderr, "Encoding failed!\n");
return 1; /* Failure */
}
}
}