Mbed OS Reference
Loading...
Searching...
No Matches
UUID Class Reference

Representation of a Universally Unique Identifier (UUID). More...

#include <UUID.h>

Public Types

enum  UUID_Type_t { UUID_TYPE_SHORT = 0 , UUID_TYPE_LONG = 1 }
 Enumeration of the types of UUIDs. More...
 
enum  ByteOrder_t { MSB , LSB }
 Enumeration of byte ordering. More...
 
typedef uint16_t ShortUUIDBytes_t
 Type for a 16-bit UUID. More...
 
typedef uint8_t LongUUIDBytes_t[LENGTH_OF_LONG_UUID]
 Type for a 128-bit UUID. More...
 

Public Member Functions

 UUID (const char *stringUUID)
 Construct a 128-bit UUID from a string. More...
 
 UUID (const LongUUIDBytes_t longUUID, ByteOrder_t order=UUID::MSB)
 Construct a new UUID from a 128-bit representation. More...
 
 UUID (ShortUUIDBytes_t _shortUUID)
 Creates a new 16-bit UUID. More...
 
 UUID (const UUID &source)
 UUID copy constructor. More...
 
UUIDoperator= (const UUID &source)=default
 UUID copy assignment. More...
 
 UUID ()
 Default constructor. More...
 
void setupLong (const LongUUIDBytes_t longUUID, ByteOrder_t order=UUID::MSB)
 Replace existing value with a 128-bit UUID. More...
 
UUID_Type_t shortOrLong () const
 Return the internal type of the UUID. More...
 
const uint8_t * getBaseUUID () const
 Get a pointer to the UUID value based on the current UUID type. More...
 
ShortUUIDBytes_t getShortUUID () const
 Get the uint16_t value of the UUID. More...
 
uint8_t getLen () const
 Get the length (in bytes) of the internal UUID representation. More...
 
bool operator== (const UUID &other) const
 Equal to operator between UUIDs. More...
 
bool operator!= (const UUID &other) const
 Not equal to operator. More...
 

Static Public Attributes

static const unsigned LENGTH_OF_LONG_UUID = 16
 Length in bytes of a long UUID. More...
 
static const unsigned MAX_UUID_STRING_LENGTH = LENGTH_OF_LONG_UUID * 2 + 4
 Maximum length for the string representation of a UUID excluding the null terminator. More...
 

Detailed Description

Representation of a Universally Unique Identifier (UUID).

UUIDs are 128-bit wide numbers used to identify data type and elements in many layers of the Bluetooth specification.

Two representations of UUIDS exist:

  • 16-bit UUIDs: Shortened representation of the 128 bit UUID 0000xxxx-0000-1000-8000-00805F9B34FB where xxxx is the 16 bit UUID. Values of those UUIDs are defined by the Bluetooth body. The short representation saves bandwidth during protocol transactions.
  • 128-bit UUIDs: Complete representation of a UUID. They are commonly used for user defined UUID.

This class acts as an adapter over these two kinds of UUIDs to allow indiscriminate use of both forms in Mbed BLE APIs.

Note
32-bit UUID representation is not supported currently.

Definition at line 76 of file common/UUID.h.

Member Typedef Documentation

◆ ShortUUIDBytes_t

typedef uint16_t ShortUUIDBytes_t

Type for a 16-bit UUID.

Definition at line 114 of file common/UUID.h.

◆ LongUUIDBytes_t

typedef uint8_t LongUUIDBytes_t[LENGTH_OF_LONG_UUID]

Type for a 128-bit UUID.

Definition at line 124 of file common/UUID.h.

Member Enumeration Documentation

◆ UUID_Type_t

Enumeration of the types of UUIDs.

Enumerator
UUID_TYPE_SHORT 

16-bit wide UUID representation.

UUID_TYPE_LONG 

128-bit wide UUID representation.

Definition at line 82 of file common/UUID.h.

◆ ByteOrder_t

Enumeration of byte ordering.

It is used to construct 128-byte UUIDs.

Enumerator
MSB 

Most significant byte first (at the smallest address).

LSB 

Least significant byte first (at the smallest address).

Definition at line 99 of file common/UUID.h.

Constructor & Destructor Documentation

◆ UUID() [1/5]

UUID ( const char *  stringUUID)

Construct a 128-bit UUID from a string.

Parameters
[in]stringUUIDHuman readable representation of the UUID following the format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.
Note
Upper and lower case are supported.
Hyphens are optional. The string must include at most four hyphens.
Internally, the UUID is stored in the little endian order as a 16-byte array.

Definition at line 149 of file common/UUID.h.

◆ UUID() [2/5]

UUID ( const LongUUIDBytes_t  longUUID,
ByteOrder_t  order = UUID::MSB 
)

Construct a new UUID from a 128-bit representation.

Parameters
[in]longUUIDThe 128-bit (16-byte) of the UUID value.
[in]orderBytes order of longUUID.

Definition at line 200 of file common/UUID.h.

◆ UUID() [3/5]

UUID ( ShortUUIDBytes_t  _shortUUID)

Creates a new 16-bit UUID.

The Bluetooth standard body defines 16-bit wide UUIDs. They are the shortened version of the UUID 0000xxxx-0000-1000-8000-00805F9B34FB, where xxxx is the value of the 16-bit UUID.

Attention
16-bit UUIDs are not used in user defined data type or user defined element ID.
Parameters
[in]_shortUUID16-bit part of the standard UUID. The short UUID value.
Note
User defined UUIDs are commonly named vendor-specific UUIDs across the Bluetooth literature.

Definition at line 220 of file common/UUID.h.

◆ UUID() [4/5]

UUID ( const UUID source)

UUID copy constructor.

Parameters
[in]sourceThe UUID to copy.

Definition at line 231 of file common/UUID.h.

◆ UUID() [5/5]

UUID ( )

Default constructor.

Construct an invalid UUID.

Postcondition
shortOrLong() returns the value UUID_TYPE_SHORT.
getShortUUID() returns the value BLE_UUID_UNKNOWN.

Definition at line 253 of file common/UUID.h.

Member Function Documentation

◆ operator=()

UUID & operator= ( const UUID source)
default

UUID copy assignment.

Parameters
[in]sourceThe UUID to copy.

◆ setupLong()

void setupLong ( const LongUUIDBytes_t  longUUID,
ByteOrder_t  order = UUID::MSB 
)

Replace existing value with a 128-bit UUID.

Parameters
[in]longUUIDNew 16-byte wide UUID value.
[in]orderByte ordering of longUUID.

Definition at line 264 of file common/UUID.h.

◆ shortOrLong()

UUID_Type_t shortOrLong ( ) const

Return the internal type of the UUID.

Returns
UUID_TYPE_SHORT if the UUID is 16-bit wide.
UUID_TYPE_LONG if the UUID is 128-bit wide.

Definition at line 286 of file common/UUID.h.

◆ getBaseUUID()

const uint8_t * getBaseUUID ( ) const

Get a pointer to the UUID value based on the current UUID type.

Returns
A pointer to an uint16_t object if the UUID is 16 bits long.
A pointer to an array of 16 bytes if the UUID is 128 bits long.

Definition at line 297 of file common/UUID.h.

◆ getShortUUID()

ShortUUIDBytes_t getShortUUID ( ) const

Get the uint16_t value of the UUID.

Attention
This function is not used on long UUIDs.
Returns
The value of the shortened UUID.

Definition at line 313 of file common/UUID.h.

◆ getLen()

uint8_t getLen ( ) const

Get the length (in bytes) of the internal UUID representation.

Returns
sizeof(ShortUUIDBytes_t) if the UUID type is UUID_TYPE_SHORT.
LENGTH_OF_LONG_UUID if the UUID type is UUID_TYPE_LONG.

Definition at line 324 of file common/UUID.h.

◆ operator==()

bool operator== ( const UUID other) const

Equal to operator between UUIDs.

Parameters
[in]otherThe UUID to compare to this.
Returns
true if both UUIDs are equal and false otherwise.

Definition at line 338 of file common/UUID.h.

◆ operator!=()

bool operator!= ( const UUID other) const

Not equal to operator.

Parameters
[in]otherThe UUID compared to this.
Returns
true if both UUIDs are not equal and false otherwise.

Definition at line 360 of file common/UUID.h.

Field Documentation

◆ LENGTH_OF_LONG_UUID

const unsigned LENGTH_OF_LONG_UUID = 16
static

Length in bytes of a long UUID.

Definition at line 119 of file common/UUID.h.

◆ MAX_UUID_STRING_LENGTH

const unsigned MAX_UUID_STRING_LENGTH = LENGTH_OF_LONG_UUID * 2 + 4
static

Maximum length for the string representation of a UUID excluding the null terminator.

The string is composed of two characters per byte plus four '-' characters.

Definition at line 133 of file common/UUID.h.