From f5c4fa561f8c9afc6d76297dbb3acdca31a914f4 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Tue, 3 Feb 2026 14:45:30 +0000 Subject: [PATCH] ds: uuid: convert uuid bytes struct to union --- ds/include/blue/ds/uuid.h | 7 +++++-- ds/uuid.c | 14 +++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ds/include/blue/ds/uuid.h b/ds/include/blue/ds/uuid.h index 6973a79..94eaf11 100644 --- a/ds/include/blue/ds/uuid.h +++ b/ds/include/blue/ds/uuid.h @@ -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); diff --git a/ds/uuid.c b/ds/uuid.c index 1ff5726..02151c7 100644 --- a/ds/uuid.c +++ b/ds/uuid.c @@ -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); }