34static uint8_t
bt_base_uuid_be[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
35 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB };
38std::string uuid_t::getTypeSizeString(
const TypeSize v)
noexcept {
40 case TypeSize::UUID16_SZ:
return "uuid16";
41 case TypeSize::UUID32_SZ:
return "uuid32";
42 case TypeSize::UUID128_SZ:
return "uuid128";
48 switch(
static_cast<TypeSize>(size) ) {
58 return std::make_unique<uuid16_t>(buffer, le_or_be);
60 return std::make_unique<uuid32_t>(buffer, le_or_be);
62 return std::make_unique<uuid128_t>(buffer, le_or_be);
67 const size_t len = str.length();
70 return std::make_unique<uuid16_t>(str);
72 return std::make_unique<uuid32_t>(str);
74 return std::make_unique<uuid128_t>(str);
76 std::string msg(
"UUID string not of length 4, 8 or 36 but ");
98 if( type != o.getTypeSize() ) {
101 switch(
static_cast<TypeSize>(type) ) {
102 case TypeSize::UUID16_SZ:
return static_cast<uuid16_t const *
>(
this)->value ==
static_cast<uuid16_t const *
>(&o)->
value;
103 case TypeSize::UUID32_SZ:
return static_cast<uuid32_t const *
>(
this)->value ==
static_cast<uuid32_t const *
>(&o)->
value;
104 case TypeSize::UUID128_SZ:
return static_cast<uuid128_t const *
>(
this)->value ==
static_cast<uuid128_t const *
>(&o)->
value;
113 if( getTypeSize() == o.getTypeSize() ) {
116 return toUUID128() == o.toUUID128();
121 case TypeSize::UUID16_SZ:
return uuid128_t( *(
static_cast<const uuid16_t*
>(
this) ), base_uuid, uuid32_le_octet_index);
122 case TypeSize::UUID32_SZ:
return uuid128_t( *(
static_cast<const uuid32_t*
>(
this) ), base_uuid, uuid32_le_octet_index);
123 case TypeSize::UUID128_SZ:
return uuid128_t( *(
static_cast<const uuid128_t*
>(
this) ) );
130:
uuid_t(TypeSize::UUID128_SZ), value(
merge_uint128(uuid16.value, base_uuid.value, uuid16_le_octet_index)) {}
133:
uuid_t(TypeSize::UUID128_SZ), value(
merge_uint128(uuid32.value, base_uuid.value, uuid32_le_octet_index)) {}
138 str.reserve(length+1);
142 if( length != count ) {
143 ABORT(
"UUID16 string not of length %d but %d", length, count);
150 uuid128_t u128(*
this, base_uuid, le_octet_index);
157 str.reserve(length+1);
161 if( length != count ) {
162 ABORT(
"UUID32 string not of length %d but %d", length, count);
169 uuid128_t u128(*
this, base_uuid, le_octet_index);
188 str.reserve(length+1);
190 uint32_t part0, part4;
191 uint16_t part1, part2, part3, part5;
210 const jau::nsize_t count = snprintf(&str[0], str.capacity(),
"%.8x-%.4x-%.4x-%.4x-%.8x%.4x",
211 part0, part1, part2, part3, part4, part5);
212 if( length != count ) {
213 ABORT(
"UUID128 string not of length %d but %d", length, count);
223 if( 4 != str.length() ) {
224 std::string msg(
"UUID16 string not of length 4 but ");
226 msg.append(
": "+str);
229 if ( sscanf(str.c_str(),
"%04hx", &part0) != 1 ) {
230 std::string msg(
"UUID16 string not in format '0000' but "+str);
243 if( 8 != str.length() ) {
244 std::string msg(
"UUID32 string not of length 8 but ");
246 msg.append(
": "+str);
250 if ( sscanf(str.c_str(),
"%08x", &part0) != 1 ) {
251 std::string msg(
"UUID32 string not in format '00000000' but "+str);
262 uint32_t part0, part4;
263 uint16_t part1, part2, part3, part5;
265 if( 36 != str.length() ) {
266 std::string msg(
"UUID128 string not of length 36 but ");
268 msg.append(
": "+str);
271 if ( sscanf(str.c_str(),
"%08x-%04hx-%04hx-%04hx-%08x%04hx",
272 &part0, &part1, &part2, &part3, &part4, &part5) != 6 )
274 std::string msg(
"UUID128 string not in format '00000000-0000-1000-8000-00805F9B34FB' but "+str);
std::string toString() const noexcept override
Returns the string representation in BE network order, i.e.
std::string toString() const noexcept override
Returns the string representation in BE network order, i.e.
std::string toUUID128String(uuid128_t const &base_uuid=BT_BASE_UUID, jau::nsize_t const le_octet_index=12) const noexcept override
Returns the uuid128_t string representation in BE network order, i.e.
uuid16_t(uint16_t const v) noexcept
std::string toString() const noexcept override
Returns the string representation in BE network order, i.e.
std::string toUUID128String(uuid128_t const &base_uuid=BT_BASE_UUID, jau::nsize_t const le_octet_index=12) const noexcept override
Returns the uuid128_t string representation in BE network order, i.e.
uuid32_t(uint32_t const v) noexcept
uuid128_t toUUID128(uuid128_t const &base_uuid=BT_BASE_UUID, jau::nsize_t const uuid32_le_octet_index=12) const noexcept
TypeSize
Underlying integer value present octet count.
bool operator==(uuid_t const &o) const noexcept
Strict equality operator.
bool equivalent(uuid_t const &o) const noexcept
Relaxed equality operator.
static std::unique_ptr< uuid_t > create(TypeSize const t, uint8_t const *const buffer, lb_endian_t const le_or_be)
std::unique_ptr< uuid_t > clone() const noexcept
#define ABORT(...)
Use for unconditional ::abort() call with given messages, prefix '[elapsed_time] ABORT @ file:line fu...
constexpr bool is_big_endian() noexcept
Evaluates true if platform is running in big endian mode, i.e.
constexpr bool is_defined_endian(const endian_t &v) noexcept
Evaluates true if the given endian is defined, i.e.
constexpr uint16_t get_uint16(uint8_t const *buffer) noexcept
Returns a uint16_t value from the given byte address using packed_t to resolve a potential memory ali...
constexpr bool is_little_or_big_endian() noexcept
Evaluates true if platform is running in little or big endian mode, i.e.
constexpr uint32_t get_uint32(uint8_t const *buffer) noexcept
See get_uint16() for reference.
constexpr void put_uint32(uint8_t *buffer, const uint32_t v) noexcept
See put_uint16() for reference.
lb_endian_t
Simplified reduced endian type only covering little- and big-endian.
constexpr void put_uint16(uint8_t *buffer, const uint16_t v) noexcept
Put the given uint16_t value into the given byte address using packed_t to resolve a potential memory...
@ native
Identifier for native platform type, one of the above.
std::string to_string(const alphabet &v) noexcept
constexpr uint32_t number(const iostate rhs) noexcept
uint_fast32_t nsize_t
Natural 'size_t' alternative using uint_fast32_t as its natural sized type.
uint128dp_t merge_uint128(uint16_t const uuid16, uint128dp_t const &base_uuid, nsize_t const uuid16_le_octet_index)
Merge the given 'uuid16' into a 'base_uuid' copy at the given little endian 'uuid16_le_octet_index' p...
uuid128_t BT_BASE_UUID
Bluetooth UUID https://www.bluetooth.com/specifications/assigned-numbers/service-discovery/
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
static uint8_t bt_base_uuid_be[]