Skip to content

Commit c9e689b

Browse files
Use TLV parser for generic parser slice
1 parent faaca65 commit c9e689b

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

src_features/generic_tx_parser/gtp_data_path.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ static bool handle_slice(const s_tlv_data *data, s_data_path_context *context) {
7878

7979
ctx.args = &context->data_path->elements[context->data_path->size].slice;
8080
explicit_bzero(ctx.args, sizeof(*ctx.args));
81-
if (!tlv_parse(data->value, data->length, (f_tlv_data_handler) &handle_slice_struct, &ctx))
81+
if (!handle_slice_struct(data, &ctx)){
8282
return false;
83+
}
8384
context->data_path->elements[context->data_path->size].type = ELEMENT_TYPE_SLICE;
8485
context->data_path->size += 1;
8586
return true;

src_features/generic_tx_parser/gtp_path_slice.c

+10-19
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@
22

33
#include "gtp_path_slice.h"
44
#include "os_print.h"
5+
#include "tlv_library.h"
56
#include "read.h"
67

7-
enum {
8-
TAG_START = 0x01,
9-
TAG_END = 0x02,
10-
};
11-
128
static bool handle_start(const s_tlv_data *data, s_path_slice_context *context) {
139
if (data->length != sizeof(context->args->start)) {
1410
return false;
@@ -27,21 +23,16 @@ static bool handle_end(const s_tlv_data *data, s_path_slice_context *context) {
2723
return true;
2824
}
2925

30-
bool handle_slice_struct(const s_tlv_data *data, s_path_slice_context *context) {
31-
bool ret;
26+
// clang-format off
27+
#define TLV_TAGS(X) \
28+
X(0x01, TAG_START, handle_start, ENFORCE_UNIQUE_TAG) \
29+
X(0x02, TAG_END, handle_end, ENFORCE_UNIQUE_TAG)
3230

33-
switch (data->tag) {
34-
case TAG_START:
35-
ret = handle_start(data, context);
36-
break;
37-
case TAG_END:
38-
ret = handle_end(data, context);
39-
break;
40-
default:
41-
PRINTF(TLV_TAG_ERROR_MSG, data->tag);
42-
ret = false;
43-
}
44-
return ret;
31+
DEFINE_TLV_PARSER(TLV_TAGS, parse_tlv_slice_struct)
32+
33+
bool handle_slice_struct(const s_tlv_data *data, s_path_slice_context *context) {
34+
buffer_t payload_buffer = {.ptr = data->value, .size = data->length};
35+
return parse_tlv_slice_struct(&payload_buffer, context, NULL);
4536
}
4637

4738
#endif // HAVE_GENERIC_TX_PARSER

0 commit comments

Comments
 (0)