ds: uuid: convert uuid bytes struct to union

This commit is contained in:
2026-02-03 14:45:30 +00:00
parent 5639aefd61
commit f5c4fa561f
2 changed files with 12 additions and 9 deletions

View File

@@ -17,8 +17,11 @@ B_DECLARE_TYPE(b_uuid);
B_TYPE_CLASS_DECLARATION_BEGIN(b_uuid)
B_TYPE_CLASS_DECLARATION_END(b_uuid)
typedef struct b_uuid_bytes {
unsigned char uuid_bytes[B_UUID_NBYTES];
typedef union b_uuid_bytes {
uint8_t uuid_bytes[B_UUID_NBYTES];
uint16_t uuid_words[B_UUID_NBYTES / 2];
uint32_t uuid_dwords[B_UUID_NBYTES / 4];
uint64_t uuid_qwords[B_UUID_NBYTES / 8];
} b_uuid_bytes;
BLUE_API b_type b_uuid_get_type(void);

View File

@@ -9,7 +9,7 @@
/*** PRIVATE DATA *************************************************************/
struct b_uuid_p {
struct b_uuid_bytes uuid_bytes;
union b_uuid_bytes uuid_bytes;
};
/*** PRIVATE FUNCTIONS ********************************************************/
@@ -39,12 +39,12 @@ static void uuid_get_bytes(
}
static void uuid_get_uuid_bytes(
const struct b_uuid_p *uuid, struct b_uuid_bytes *bytes)
const struct b_uuid_p *uuid, union b_uuid_bytes *bytes)
{
memcpy(bytes, &uuid->uuid_bytes, sizeof *bytes);
}
static struct b_uuid_bytes *uuid_ptr(struct b_uuid_p *uuid)
static union b_uuid_bytes *uuid_ptr(struct b_uuid_p *uuid)
{
return &uuid->uuid_bytes;
}
@@ -101,7 +101,7 @@ b_uuid *b_uuid_create_from_bytev(const unsigned char bytes[B_UUID_NBYTES])
b_uuid *b_uuid_create_from_cstr(const char *str)
{
struct b_uuid_bytes bytes;
union b_uuid_bytes bytes;
bool valid = true;
bool is_guid = false;
@@ -169,19 +169,19 @@ void b_uuid_get_bytes(const b_uuid *uuid, unsigned char bytes[B_UUID_NBYTES])
B_CLASS_DISPATCH_STATIC(B_TYPE_UUID, uuid_get_bytes, uuid, bytes);
}
void b_uuid_get_uuid_bytes(const b_uuid *uuid, struct b_uuid_bytes *bytes)
void b_uuid_get_uuid_bytes(const b_uuid *uuid, union b_uuid_bytes *bytes)
{
B_CLASS_DISPATCH_STATIC(B_TYPE_UUID, uuid_get_uuid_bytes, uuid, bytes);
}
struct b_uuid_bytes *b_uuid_ptr(b_uuid *uuid)
union b_uuid_bytes *b_uuid_ptr(b_uuid *uuid)
{
B_CLASS_DISPATCH_STATIC_0(B_TYPE_UUID, uuid_ptr, uuid);
}
/*** PUBLIC ALIAS FUNCTIONS ***************************************************/
b_uuid *b_uuid_create_from_uuid_bytes(const struct b_uuid_bytes *bytes)
b_uuid *b_uuid_create_from_uuid_bytes(const union b_uuid_bytes *bytes)
{
return b_uuid_create_from_bytev(bytes->uuid_bytes);
}