|
41 | 41 | */ |
42 | 42 |
|
43 | 43 | /** |
44 | | - * @brief Size in bytes of the index in the LYB Binary Format. |
| 44 | + * @brief Size in bytes of the used type index in the LYB Binary Format. |
45 | 45 | */ |
46 | | -#define IDX_SIZE 4 |
| 46 | +#define TYPE_IDX_SIZE 4 |
47 | 47 |
|
48 | 48 | /** |
49 | 49 | * @brief Assign a value to the union subvalue. |
@@ -95,14 +95,14 @@ lyb_union_validate(const void *lyb_data, size_t lyb_data_len, const struct lysc_ |
95 | 95 | uint64_t type_idx = 0; |
96 | 96 |
|
97 | 97 | /* Basic validation. */ |
98 | | - if (lyb_data_len < IDX_SIZE) { |
| 98 | + if (lyb_data_len < TYPE_IDX_SIZE) { |
99 | 99 | ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Invalid LYB union value size %zu (expected at least 4).", |
100 | 100 | lyb_data_len); |
101 | 101 | return ret; |
102 | 102 | } |
103 | 103 |
|
104 | 104 | /* Get index in correct byte order. */ |
105 | | - memcpy(&type_idx, lyb_data, IDX_SIZE); |
| 105 | + memcpy(&type_idx, lyb_data, TYPE_IDX_SIZE); |
106 | 106 | type_idx = le64toh(type_idx); |
107 | 107 | if (type_idx >= LY_ARRAY_COUNT(type_u->types)) { |
108 | 108 | ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, |
@@ -132,20 +132,20 @@ lyb_parse_union(const void *lyb_data, size_t lyb_data_len, uint32_t *type_idx, c |
132 | 132 | assert(lyb_data && !(lyb_value && !lyb_value_len)); |
133 | 133 |
|
134 | 134 | if (type_idx) { |
135 | | - memcpy(&num, lyb_data, IDX_SIZE); |
| 135 | + memcpy(&num, lyb_data, TYPE_IDX_SIZE); |
136 | 136 | num = le64toh(num); |
137 | 137 |
|
138 | 138 | *type_idx = num; |
139 | 139 | } |
140 | 140 |
|
141 | 141 | if (lyb_value && lyb_value_len && lyb_data_len) { |
142 | 142 | /* Get lyb_value and its length. */ |
143 | | - if (lyb_data_len == IDX_SIZE) { |
| 143 | + if (lyb_data_len == TYPE_IDX_SIZE) { |
144 | 144 | *lyb_value_len = 0; |
145 | 145 | *lyb_value = ""; |
146 | 146 | } else { |
147 | | - *lyb_value_len = lyb_data_len - IDX_SIZE; |
148 | | - *lyb_value = (char *)lyb_data + IDX_SIZE; |
| 147 | + *lyb_value_len = lyb_data_len - TYPE_IDX_SIZE; |
| 148 | + *lyb_value = (char *)lyb_data + TYPE_IDX_SIZE; |
149 | 149 | } |
150 | 150 | } |
151 | 151 | } |
@@ -505,14 +505,14 @@ lyb_union_print(const struct ly_ctx *ctx, struct lysc_type_union *type_u, struct |
505 | 505 | LY_CHECK_RET(!pval, NULL); |
506 | 506 |
|
507 | 507 | /* Create LYB data. */ |
508 | | - *value_len = IDX_SIZE + pval_len; |
| 508 | + *value_len = TYPE_IDX_SIZE + pval_len; |
509 | 509 | ret = malloc(*value_len); |
510 | 510 | LY_CHECK_RET(!ret, NULL); |
511 | 511 |
|
512 | 512 | num = type_idx; |
513 | 513 | num = htole64(num); |
514 | | - memcpy(ret, &num, IDX_SIZE); |
515 | | - memcpy((char *)ret + IDX_SIZE, pval, pval_len); |
| 514 | + memcpy(ret, &num, TYPE_IDX_SIZE); |
| 515 | + memcpy((char *)ret + TYPE_IDX_SIZE, pval, pval_len); |
516 | 516 |
|
517 | 517 | if (dynamic) { |
518 | 518 | free(pval); |
|
0 commit comments