uuid
ballerina/uuid
Package overview
This package provides functions related to UUID (Universally unique identifier). For an example on the usage of the operations, see the UUID Example.
Functions
createType1AsRecord
Returns a UUID of type 1 as a UUID record.
uuid:Uuid|uuid:Error uuid1 = uuid:createType1AsRecord();
createType1AsString
function createType1AsString() returns string
Returns a UUID of type 1 as a string.
string uuid1 = uuid:createType1AsString();
Return Type
- string - UUID of type 1 as a string
createType3AsRecord
function createType3AsRecord(NamespaceUUID namespace, string name) returns Uuid|Error
Returns a UUID of type 3 as a UUID record.
uuid:Uuid|uuid:Error uuid3 = uuid:createType3AsRecord(uuid:NAME_SPACE_DNS, “ballerina.io”);
Parameters
- namespace NamespaceUUID - string representation for pre-defined namespace UUIDs
- name string - a name within the namespace
createType3AsString
function createType3AsString(NamespaceUUID namespace, string name) returns string|Error
Returns a UUID of type 3 as a string.
string|uuid:Error uuid3 = uuid:createType3AsString(uuid:NAME_SPACE_DNS, “ballerina.io”);
Parameters
- namespace NamespaceUUID - string representation for pre-defined namespace UUIDs
- name string - a name within the namespace
createType4AsRecord
Returns a UUID of type 4 as a UUID record.
uuid:Uuid|uuid:Error uuid4 = uuid:createType4AsRecord();
createType4AsString
function createType4AsString() returns string
Returns a UUID of type 4 as a string.
string uuid4 = uuid:createType4AsString();
Return Type
- string - UUID of type 4 as a string
createType5AsRecord
function createType5AsRecord(NamespaceUUID namespace, string name) returns Uuid|Error
Returns a UUID of type 5 as a UUID record.
uuid:Uuid|uuid:Error uuid5 = uuid:createType5AsRecord(uuid:NAME_SPACE_DNS, “ballerina.io”);
Parameters
- namespace NamespaceUUID - string representation for pre-defined namespace UUIDs
- name string - a name within the namespace
createType5AsString
function createType5AsString(NamespaceUUID namespace, string name) returns string|Error
Returns a UUID of type 5 as a string.
string|uuid:Error uuid5 = uuid:createType5AsString(uuid:NAME_SPACE_DNS, “ballerina.io”);
Parameters
- namespace NamespaceUUID - string representation for pre-defined namespace UUIDs
- name string - a name within the namespace
getVersion
Detect RFC version of a UUID. Returns an error if the UUID is invalid.
uuid:Version|uuid:Error v = uuid:getVersion("4397465e-35f9-11eb-adc1-0242ac120002");
Parameters
- uuid string - UUID
nilAsRecord
function nilAsRecord() returns Uuid
Returns a nil UUID as a UUID record.
uuid:Uuid nilUUID = uuid:nilAsRecord();
Return Type
- Uuid - nil UUID
nilAsString
function nilAsString() returns string
Returns a nil UUID as a string.
string nilUUID = uuid:nilAsString();
Return Type
- string - nil UUID
toBytes
Convert to an array of bytes. Returns an error if the UUID is invalid.
byte[]|uuid:Error b = uuid:toBytes(“6ec0bd7f-11c0-43da-975e-2aesass0b”);
Return Type
- byte[]|Error - UUID as bytes
toRecord
Convert to UUID record. Returns error if the array is invalid.
uuid:Uuid|uuid:Error r1 = uuid:toRecord("4397465e-35f9-11eb-adc1-0242ac120002"); uuid:Uuid|uuid:Error r2 = uuid:toRecord([10, 20, 30]);
Parameters
- uuid string|byte[] - UUID to be converted
toString
Convert to UUID string. Returns error if the array is invalid.
string|error s = uuid:toString([5, 12, 16, 35]);
Parameters
- uuid byte[]|Uuid - UUID to be converted
validate
Test a string to see if it is a valid UUID.
boolean valid = uuid:validate("4397465e-35f9-11eb-adc1-0242ac120002");
Parameters
- uuid string - UUID to be tested
Return Type
- boolean - true if a valied UUID, false if not
Records
uuid: Uuid
Represents a UUID.
Fields
- timeLow Unsigned32 - The low field of the timestamp
- timeMid Unsigned16 - The middle field of the timestamp
- timeHiAndVersion Unsigned16 - The high field of the timestamp multiplexed with the version number
- clockSeqHiAndReserved Unsigned8 - The high field of the clock sequence multiplexed with the variant
- clockSeqLo Unsigned8 - The low field of the clock sequence
- node int - The spatially unique node identifier
Enums
uuid: NamespaceUUID
Represents UUIDs strings of well known namespace IDs.
Members
uuid: Version
Represents the UUID versions.
Members
Errors
uuid: Error
Represents UUID module related errors.