diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2013-12-09 19:19:12 +0200 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2013-12-29 18:35:57 +0200 |
commit | 25516b059137be64735276bbe3a96029f4c926be (patch) | |
tree | 046dc037c96cf9b4243e2eba533d4a555bf15f1f /tests | |
parent | 414e637867c513ba9aa199e106c6d576e5b60287 (diff) |
Organize allocation logic in generator, add pb_bytes_ptr_t.
Allocation decision is now made before the field data type is decided.
This way the data type decisions can more cleanly account for the allocation
type, i.e. FT_DEFAULT logic etc.
Added pb_bytes_ptr_t for pointer-allocated bytes-fields. There is no point
generating separate structs for these, as they would all be of the same type.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/alltypes_pointer/encode_alltypes_pointer.c | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/tests/alltypes_pointer/encode_alltypes_pointer.c b/tests/alltypes_pointer/encode_alltypes_pointer.c index cb2fe3d5..7e648e39 100644 --- a/tests/alltypes_pointer/encode_alltypes_pointer.c +++ b/tests/alltypes_pointer/encode_alltypes_pointer.c @@ -24,9 +24,8 @@ int main(int argc, char **argv) double value_double = 1000.0f; char *value_string = "1000"; - AllTypes_req_bytes_t value_req_bytes; - AllTypes_rep_bytes_t value_rep_bytes; - AllTypes_opt_bytes_t value_opt_bytes; + + pb_bytes_ptr_t value_bytes = {4, (uint8_t*)"1000"}; SubMessage value_submessage = {0}; MyEnum value_enum = MyEnum_Truth; @@ -51,11 +50,9 @@ int main(int argc, char **argv) alltypes.req_sfixed64 = &value_int64; alltypes.req_double = &value_double; - value_req_bytes.bytes = (uint8_t*)"1000"; - value_req_bytes.size = 4; - alltypes.req_string = value_string; - alltypes.req_bytes = &value_req_bytes; + + alltypes.req_bytes = &value_bytes; value_submessage.substuff1 = value_string; value_submessage.substuff2 = &value_int32; @@ -80,11 +77,8 @@ int main(int argc, char **argv) alltypes.rep_sfixed64_count = 1; alltypes.rep_sfixed64 = &value_int64; alltypes.rep_double_count = 1; alltypes.rep_double = &value_double; - value_rep_bytes.bytes = (uint8_t*)"1000"; - value_rep_bytes.size = 4; - alltypes.rep_string_count = 1; alltypes.rep_string = (char **)&value_string; - alltypes.rep_bytes_count = 0; alltypes.rep_bytes = &value_rep_bytes; + alltypes.rep_bytes_count = 1; alltypes.rep_bytes = &value_bytes; alltypes.rep_submsg_count = 1; alltypes.rep_submsg = &value_submessage; alltypes.rep_enum_count = 1; alltypes.rep_enum = &value_enum; @@ -109,11 +103,9 @@ int main(int argc, char **argv) alltypes.opt_sfixed64 = &value_int64; alltypes.opt_double = &value_double; - value_opt_bytes.bytes = (uint8_t*)"1000"; - value_opt_bytes.size = 4; - alltypes.opt_string = value_string; - alltypes.opt_bytes = &value_opt_bytes; + + alltypes.opt_bytes = &value_bytes; alltypes.opt_submsg = &value_submessage; alltypes.opt_enum = &value_enum; |