4
4
#include <string.h>
5
5
#include "gtp_path_array.h"
6
6
#include "read.h"
7
+ #include "tlv_library.h"
8
+ #include "buffer.h"
7
9
#include "os_print.h"
8
10
#include "utils.h"
9
11
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 );
22
14
}
23
15
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 ) {
25
17
if (data -> length != sizeof (context -> args -> start )) {
26
18
return false;
27
19
}
@@ -30,7 +22,7 @@ static bool handle_start(const s_tlv_data *data, s_path_array_context *context)
30
22
return true;
31
23
}
32
24
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 ) {
34
26
if (data -> length != sizeof (context -> args -> end )) {
35
27
return false;
36
28
}
@@ -39,24 +31,17 @@ static bool handle_end(const s_tlv_data *data, s_path_array_context *context) {
39
31
return true;
40
32
}
41
33
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
+
42
42
bool 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 );
60
45
}
61
46
62
47
#endif // HAVE_GENERIC_TX_PARSER
0 commit comments