diff options
author | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2022-01-12 02:58:02 +0100 |
---|---|---|
committer | Neels Hofmeyr <neels@hofmeyr.de> | 2022-06-16 13:04:33 +0200 |
commit | e011b04c6b2e31bdc46320e5d8a4f48715681f15 (patch) | |
tree | 4e4f9a4ad06ca68996cbb3dd899081d75979b713 /tests/libosmo-gtlv/test_gtlv_gen/myproto_ies_custom.h | |
parent | f842c8c8d0d809b298668c9f547e6df837532fce (diff) |
libosmo-gtlv: add C code generator for IE structs and arrays
Defining a protocol of message types with lists of IEs bears a lot of
repetitive, copy-paste-error-prone writing out of data structures.
Add a third layer to libosmo-gtlv, which allows helpful code generation.
By non-repetitive data structures that briefly describe the protocol's
messages and IEs, generate possibly repetitive IE list arrays and
decoded-struct definitions automatically, avoiding grunt work errors.
I tried C macros for this at first, but it became too convoluted.
Generating C code that can be read and grepped makes things easier.
A usage example is found in tests/libosmo-gtlv/test_gtlv_gen/.
Related: SYS#5599
Change-Id: Ifb3ea54d2797ce060b95834aa117725ec2d6c4cf
Diffstat (limited to 'tests/libosmo-gtlv/test_gtlv_gen/myproto_ies_custom.h')
-rw-r--r-- | tests/libosmo-gtlv/test_gtlv_gen/myproto_ies_custom.h | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/libosmo-gtlv/test_gtlv_gen/myproto_ies_custom.h b/tests/libosmo-gtlv/test_gtlv_gen/myproto_ies_custom.h new file mode 100644 index 0000000..56039af --- /dev/null +++ b/tests/libosmo-gtlv/test_gtlv_gen/myproto_ies_custom.h @@ -0,0 +1,70 @@ +/* Definitions for decoded message IEs, to be used by the auto-generated myproto_ies_auto.c. */ +/* + * (C) 2021-2022 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de> + * All Rights Reserved. + * + * Author: Neels Janosch Hofmeyr <nhofmeyr@sysmocom.de> + * + * SPDX-License-Identifier: GPL-2.0+ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#pragma once + +#include <osmocom/core/utils.h> + +enum myproto_msg_type { + MYPROTO_MSGT_MOO = 1, + MYPROTO_MSGT_GOO = 7, +}; + +extern const struct value_string myproto_msg_type_names[]; + +enum myproto_iei { + MYPROTO_IEI_FOO = 1, + MYPROTO_IEI_BAR, + MYPROTO_IEI_BAZ, + MYPROTO_IEI_REPEAT_INT, + MYPROTO_IEI_REPEAT_STRUCT, + MYPROTO_IEI_MOO_NEST, + MYPROTO_IEI_VAL, + MYPROTO_IEI_GOO_NEST, +}; + +extern const struct value_string myproto_iei_names[]; + +struct myproto_ie_bar { + char str[23]; +}; + +struct myproto_ie_baz { + int v_int; + bool v_bool; +}; + +enum myproto_repeat_enum { + R_A, + R_B, + R_C, +}; + +extern const struct value_string myproto_repeat_enum_names[]; + +struct myproto_ie_repeat_struct { + int v_int; + bool v_bool; + enum myproto_repeat_enum v_enum; +}; |