44#include <string.h>
55#include "gtp_path_array.h"
66#include "read.h"
7+ #include "tlv_library.h"
8+ #include "buffer.h"
79#include "os_print.h"
810#include "utils.h"
911
10- enum {
11- TAG_WEIGHT = 0x01 ,
12- TAG_START = 0x02 ,
13- TAG_END = 0x03 ,
14- };
15-
16- static bool handle_weight (const s_tlv_data * data , s_path_array_context * context ) {
17- if (data -> length != sizeof (context -> args -> weight )) {
18- return false;
19- }
20- context -> args -> weight = data -> value [0 ];
21- return true;
12+ static bool handle_weight (const tlv_data_t * data , s_path_array_context * context ) {
13+ return get_uint8_t_from_tlv_data (data , & context -> args -> weight );
2214}
2315
24- static bool handle_start (const s_tlv_data * data , s_path_array_context * context ) {
16+ static bool handle_start (const tlv_data_t * data , s_path_array_context * context ) {
2517 if (data -> length != sizeof (context -> args -> start )) {
2618 return false;
2719 }
@@ -30,7 +22,7 @@ static bool handle_start(const s_tlv_data *data, s_path_array_context *context)
3022 return true;
3123}
3224
33- static bool handle_end (const s_tlv_data * data , s_path_array_context * context ) {
25+ static bool handle_end (const tlv_data_t * data , s_path_array_context * context ) {
3426 if (data -> length != sizeof (context -> args -> end )) {
3527 return false;
3628 }
@@ -39,24 +31,17 @@ static bool handle_end(const s_tlv_data *data, s_path_array_context *context) {
3931 return true;
4032}
4133
34+ // clang-format off
35+ #define TLV_TAGS (X ) \
36+ X(0x01, TAG_WEIGHT, handle_weight, ALLOW_MULTIPLE_TAG) \
37+ X(0x02, TAG_START, handle_start, ENFORCE_UNIQUE_TAG) \
38+ X(0x03, TAG_END, handle_end, ENFORCE_UNIQUE_TAG)
39+
40+ DEFINE_TLV_PARSER (TLV_TAGS , parse_tlv_array )
41+
4242bool handle_array_struct (const s_tlv_data * data , s_path_array_context * context ) {
43- bool ret ;
44-
45- switch (data -> tag ) {
46- case TAG_WEIGHT :
47- ret = handle_weight (data , context );
48- break ;
49- case TAG_START :
50- ret = handle_start (data , context );
51- break ;
52- case TAG_END :
53- ret = handle_end (data , context );
54- break ;
55- default :
56- PRINTF (TLV_TAG_ERROR_MSG , data -> tag );
57- ret = false;
58- }
59- return ret ;
43+ buffer_t payload_buffer = {.ptr = data -> value , .size = data -> length };
44+ return parse_tlv_array (& payload_buffer , context , NULL );
6045}
6146
6247#endif // HAVE_GENERIC_TX_PARSER
0 commit comments