Skip to content

Commit 83c9d82

Browse files
committed
Unify definite/indefinite enums 2/2
1 parent 2fbc823 commit 83c9d82

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

src/cbor.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ cbor_item_t * cbor_new_definite_string()
10051005
*item = (cbor_item_t){
10061006
.refcount = 1,
10071007
.type = CBOR_TYPE_STRING,
1008-
.metadata = { .string_metadata = { _CBOR_STRING_METADATA_DEFINITE, 0 } }
1008+
.metadata = { .string_metadata = { _CBOR_METADATA_DEFINITE, 0 } }
10091009
};
10101010
return item;
10111011
}
@@ -1016,7 +1016,7 @@ cbor_item_t * cbor_new_indefinite_string()
10161016
*item = (cbor_item_t){
10171017
.refcount = 1,
10181018
.type = CBOR_TYPE_STRING,
1019-
.metadata = { .string_metadata = { .type = _CBOR_STRING_METADATA_INDEFINITE, .length = 0 } },
1019+
.metadata = { .string_metadata = { .type = _CBOR_METADATA_INDEFINITE, .length = 0 } },
10201020
.data = malloc(sizeof(struct cbor_indefinite_string_data))
10211021
};
10221022
*((struct cbor_indefinite_string_data *)item->data) = (struct cbor_indefinite_string_data){
@@ -1088,7 +1088,7 @@ size_t cbor_string_codepoint_count(const cbor_item_t * item)
10881088
bool cbor_string_is_definite(const cbor_item_t * item)
10891089
{
10901090
assert(cbor_isa_string(item));
1091-
return item->metadata.string_metadata.type == _CBOR_STRING_METADATA_DEFINITE;
1091+
return item->metadata.string_metadata.type == _CBOR_METADATA_DEFINITE;
10921092
}
10931093

10941094
bool cbor_string_is_indefinite(const cbor_item_t * item)
@@ -1103,7 +1103,7 @@ cbor_item_t * cbor_new_definite_bytestring()
11031103
*item = (cbor_item_t){
11041104
.refcount = 1,
11051105
.type = CBOR_TYPE_BYTESTRING,
1106-
.metadata = { .bytestring_metadata = { _CBOR_STRING_METADATA_DEFINITE, 0 } }
1106+
.metadata = { .bytestring_metadata = { _CBOR_METADATA_DEFINITE, 0 } }
11071107
};
11081108
return item;
11091109
}
@@ -1114,7 +1114,7 @@ cbor_item_t * cbor_new_indefinite_bytestring()
11141114
*item = (cbor_item_t){
11151115
.refcount = 1,
11161116
.type = CBOR_TYPE_BYTESTRING,
1117-
.metadata = { .bytestring_metadata = { .type = _CBOR_STRING_METADATA_INDEFINITE, .length = 0 } },
1117+
.metadata = { .bytestring_metadata = { .type = _CBOR_METADATA_INDEFINITE, .length = 0 } },
11181118
.data = malloc(sizeof(struct cbor_indefinite_string_data))
11191119
};
11201120
*((struct cbor_indefinite_string_data *)item->data) = (struct cbor_indefinite_string_data){
@@ -1356,7 +1356,7 @@ unsigned char * cbor_bytestring_handle(const cbor_item_t * item) {
13561356
bool cbor_bytestring_is_definite(const cbor_item_t * item)
13571357
{
13581358
assert(cbor_isa_bytestring(item));
1359-
return item->metadata.bytestring_metadata.type == _CBOR_STRING_METADATA_DEFINITE;
1359+
return item->metadata.bytestring_metadata.type == _CBOR_METADATA_DEFINITE;
13601360
}
13611361

13621362
bool cbor_bytestring_is_indefinite(const cbor_item_t * item)

src/cbor.h

+11-15
Original file line numberDiff line numberDiff line change
@@ -82,33 +82,29 @@ typedef enum {
8282
_CBOR_METADATA_RESUMABLE = 0x02, /* Parsing may be resumed */
8383
} _cbor_metadata;
8484

85+
typedef enum {
86+
_CBOR_METADATA_DEFINITE,
87+
_CBOR_METADATA_INDEFINITE
88+
} _cbor_dst_metadata;
89+
90+
8591
struct _cbor_int_metadata {
8692
cbor_int_width width;
8793
};
8894

89-
typedef enum {
90-
_CBOR_STRING_METADATA_DEFINITE,
91-
_CBOR_STRING_METADATA_INDEFINITE
92-
} _cbor_string_type_metadata;
93-
9495
struct _cbor_bytestring_metadata {
9596
size_t length;
96-
_cbor_string_type_metadata type;
97+
_cbor_dst_metadata type;
9798
};
9899

99100
struct _cbor_string_metadata {
100-
size_t length;
101-
size_t codepoint_count; /* Sum of chunks' codepoint_counts for indefinite strings */
102-
_cbor_string_type_metadata type;
101+
size_t length;
102+
size_t codepoint_count; /* Sum of chunks' codepoint_counts for indefinite strings */
103+
_cbor_dst_metadata type;
103104
};
104105

105-
typedef enum {
106-
_CBOR_METADATA_DEFINITE,
107-
_CBOR_METADATA_INDEFINITE
108-
} _cbor_dst_metadata;
109-
110106
struct _cbor_array_metadata {
111-
size_t size;
107+
size_t size;
112108
_cbor_dst_metadata type;
113109
};
114110

0 commit comments

Comments
 (0)