Skip to content

Commit 6845e81

Browse files
committed
union REFACTOR better macro name
1 parent 9784492 commit 6845e81

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/plugins_types/union.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
*/
4242

4343
/**
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.
4545
*/
46-
#define IDX_SIZE 4
46+
#define TYPE_IDX_SIZE 4
4747

4848
/**
4949
* @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_
9595
uint64_t type_idx = 0;
9696

9797
/* Basic validation. */
98-
if (lyb_data_len < IDX_SIZE) {
98+
if (lyb_data_len < TYPE_IDX_SIZE) {
9999
ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Invalid LYB union value size %zu (expected at least 4).",
100100
lyb_data_len);
101101
return ret;
102102
}
103103

104104
/* Get index in correct byte order. */
105-
memcpy(&type_idx, lyb_data, IDX_SIZE);
105+
memcpy(&type_idx, lyb_data, TYPE_IDX_SIZE);
106106
type_idx = le64toh(type_idx);
107107
if (type_idx >= LY_ARRAY_COUNT(type_u->types)) {
108108
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
132132
assert(lyb_data && !(lyb_value && !lyb_value_len));
133133

134134
if (type_idx) {
135-
memcpy(&num, lyb_data, IDX_SIZE);
135+
memcpy(&num, lyb_data, TYPE_IDX_SIZE);
136136
num = le64toh(num);
137137

138138
*type_idx = num;
139139
}
140140

141141
if (lyb_value && lyb_value_len && lyb_data_len) {
142142
/* Get lyb_value and its length. */
143-
if (lyb_data_len == IDX_SIZE) {
143+
if (lyb_data_len == TYPE_IDX_SIZE) {
144144
*lyb_value_len = 0;
145145
*lyb_value = "";
146146
} 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;
149149
}
150150
}
151151
}
@@ -505,14 +505,14 @@ lyb_union_print(const struct ly_ctx *ctx, struct lysc_type_union *type_u, struct
505505
LY_CHECK_RET(!pval, NULL);
506506

507507
/* Create LYB data. */
508-
*value_len = IDX_SIZE + pval_len;
508+
*value_len = TYPE_IDX_SIZE + pval_len;
509509
ret = malloc(*value_len);
510510
LY_CHECK_RET(!ret, NULL);
511511

512512
num = type_idx;
513513
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);
516516

517517
if (dynamic) {
518518
free(pval);

0 commit comments

Comments
 (0)