Skip to content

Commit bd7b314

Browse files
committed
lyb parser CHANGE avoid code duplication, unify data reading
1 parent a343e1f commit bd7b314

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/parser_lyb.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,10 @@ lyb_read_string(const char *data, char **str, int with_length, struct lyb_state
165165
{
166166
int next_chunk = 0, r, ret = 0;
167167
size_t len = 0, cur_len;
168-
uint8_t len_buf[2];
169168

170169
if (with_length) {
171-
ret += (r = lyb_read(data, len_buf, 2, lybs));
170+
ret += (r = lyb_read_number(&len, 2, data, lybs));
172171
LYB_HAVE_READ_GOTO(r, data, error);
173-
len = len_buf[0] | (len_buf[1] << 8);
174172
} else {
175173
/* read until the end of this subtree */
176174
len = lybs->written[lybs->used - 1];
@@ -1140,12 +1138,10 @@ static int
11401138
lyb_parse_data_models(const char *data, struct lyb_state *lybs)
11411139
{
11421140
int i, r, ret = 0;
1143-
uint8_t mod_count_buf[2];
11441141

11451142
/* read model count */
1146-
ret += (r = lyb_read(data, mod_count_buf, 2, lybs));
1143+
ret += (r = lyb_read_number((uint64_t *)&lybs->mod_count, 2, data, lybs));
11471144
LYB_HAVE_READ_RETURN(r, data, -1);
1148-
lybs->mod_count = mod_count_buf[0] | (mod_count_buf[1] << 8);
11491145

11501146
lybs->models = malloc(lybs->mod_count * sizeof *lybs->models);
11511147
LY_CHECK_ERR_RETURN(!lybs->models, LOGMEM(lybs->ctx), -1);

0 commit comments

Comments
 (0)