diff options
author | Sven Gothel <[email protected]> | 2021-10-02 15:57:58 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2021-10-02 15:57:58 +0200 |
commit | 55e4e3cd9ffdf6ae4d73e72e79577b549e81b24b (patch) | |
tree | 7adb39a64c932b8ce8f8a4f5a698bb29cebf2ae8 | |
parent | 0cfdff9453f5c98fbf5b28e530f4fae30273f745 (diff) |
Add uuid_t::getTypeSizeString()
-rw-r--r-- | include/jau/uuid.hpp | 6 | ||||
-rw-r--r-- | src/uuid.cpp | 9 |
2 files changed, 15 insertions, 0 deletions
diff --git a/include/jau/uuid.hpp b/include/jau/uuid.hpp index 6459617..5dd4d52 100644 --- a/include/jau/uuid.hpp +++ b/include/jau/uuid.hpp @@ -58,6 +58,7 @@ public: static constexpr jau::nsize_t number(const TypeSize rhs) noexcept { return static_cast<jau::nsize_t>(rhs); } + static std::string getTypeSizeString(const TypeSize v) noexcept; private: TypeSize type; @@ -90,6 +91,7 @@ public: TypeSize getTypeSize() const noexcept { return type; } jau::nsize_t getTypeSizeInt() const noexcept { return uuid_t::number(type); } + std::string getTypeSizeString() const noexcept { return getTypeSizeString(type); } uuid128_t toUUID128(uuid128_t const & base_uuid=BT_BASE_UUID, jau::nsize_t const uuid32_le_octet_index=12) const noexcept; @@ -100,6 +102,10 @@ public: virtual jau::nsize_t put(uint8_t * const buffer, jau::nsize_t const byte_offset, bool const littleEndian) const noexcept = 0; }; +inline std::string to_string(const uuid_t::TypeSize v) noexcept { + return uuid_t::getTypeSizeString(v); +} + class uuid16_t : public uuid_t { public: uint16_t value; diff --git a/src/uuid.cpp b/src/uuid.cpp index 35061ab..879ba57 100644 --- a/src/uuid.cpp +++ b/src/uuid.cpp @@ -35,6 +35,15 @@ static uint8_t bt_base_uuid_be[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB }; uuid128_t jau::BT_BASE_UUID( bt_base_uuid_be, 0, false ); +std::string uuid_t::getTypeSizeString(const TypeSize v) noexcept { + switch( static_cast<TypeSize>(v) ) { + case TypeSize::UUID16_SZ: return "uuid16"; + case TypeSize::UUID32_SZ: return "uuid32"; + case TypeSize::UUID128_SZ: return "uuid128"; + default: return "uuid_t unsupported size "+std::to_string(number(v)); + } +} + uuid_t::TypeSize uuid_t::toTypeSize(const jau::nsize_t size) { switch( static_cast<TypeSize>(size) ) { case TypeSize::UUID16_SZ: return TypeSize::UUID16_SZ; |