RobotRaconteurCompanion.Util.IdentifierUtil

Utility class for working with Robot Raconteur identifiers. Identifiers in Robot Raconteur consist of a UUID and a name. The UUID is a 16 byte array, and the name is a string. The UUID is used to uniquely identify the object, and the name is used to identify the object to humans. The name is not guaranteed to be unique, and should not be used to identify the object in a production environment.

UUIDs are statistically guaranteed to be unique. The use of UUIDs eliminates the need for a central registry for object identifiers, and allows for easy discovery of devices and services on a network. The name is used to identify services and devices when guaranteed unique identification is not required.

import RobotRaconteur as RR
RRN = RR.RobotRaconteurNode.s
import RobotRaconteurCompanion as RRC
from RobotRaconeteurCompanion.Util.IdentifierUtil import IdentifierUtil

RRC.RegisterStdRobDefServiceTypes(RRN)

# Create an IdentifierUtil
id_util = IdentifierUtil(RRN)

# Create an identifier from a name
my_device_identifier = id_util.CreateIdentifierFromName("my_device")

# Convert the identifier to a string
my_device_identifier_str = id_util.IdentifierToString(my_device_identifier)

# Convert the identifier string back to an identifier
my_device_identifier2 = id_util.StringToIdentifier(my_device_identifier_str)

# Compare identifiers
assert id_util.IsIdentifierMatch(my_device_identifier, my_device_identifier2)

IdentifierUtil

class RobotRaconteurCompanion.Util.IdentifierUtil.IdentifierUtil(node=None, client_obj=None)

Utility class for working with Robot Raconteur identifiers

Parameters:
  • node (RobotRaconteur.RobotRaconteurNode) – (optional) The Robot Raconteur node to use for parsing. Defaults to RobotRaconteurNode.s

  • client_obj (RobotRaconteur.ClientObject) – (optional) The client object to use for finding types. Defaults to None

CreateIdentifier(name, uuid)

Create an identifier from a name and UUID

Parameters:
  • name (str) – The name of the identifier

  • uuid (str) – The UUID of the identifier

Returns:

The created identifier

Return type:

com.robotraconteur.identifier.Identifier

CreateIdentifierFromName(name)

Create an identifier from a name. The UUID will be all zeros.

Parameters:

name (str) – The name of the identifier

Returns:

The created identifier

Return type:

com.robotraconteur.identifier.Identifier

IdentifierToString(identifier)

Create a string representation of an identifier. The string representation is in the form “name|uuid”.

Parameters:

identifier (com.robotraconteur.identifier.Identifier) – The identifier to convert to a string

Returns:

The string representation of the identifier

Return type:

str

IsIdentifierAny(identifier)

Check if an identifier is “any” (UUID is all zeros and name is empty)

Parameters:

identifier (com.robotraconteur.identifier.Identifier) – The identifier to check

Returns:

True if the identifier is “any”

Return type:

bool

IsIdentifierAnyName(identifier)

Check if an identifier is “any” (name is empty)

Parameters:

identifier (com.robotraconteur.identifier.Identifier) – The identifier to check

Returns:

True if the identifier is “any”

Return type:

bool

IsIdentifierAnyUuid(identifier)

Check if an identifier is “any” (UUID is all zeros)

Parameters:

identifier (com.robotraconteur.identifier.Identifier) – The identifier to check

Returns:

True if the identifier is “any”

Return type:

bool

IsIdentifierMatch(expected, test)

Check if two identifiers match

Identifiers have a complex matching rules:

  • If both identifiers are “any”, they match

  • If either identifier is “any”, they match

  • If both identifiers have the same name and UUID, they match

  • If the name is Any for either identifier and UUID matches, they match

  • If the UUID is Any for either identifier and name matches, they match

  • Otherwise, they do not match

Parameters:
  • expected (com.robotraconteur.identifier.Identifier) – The expected identifier

  • test (com.robotraconteur.identifier.Identifier) – The test identifier

Returns:

True if the identifiers match

Return type:

bool

StringToIdentifier(string_id)

Parse a string representation of an identifier. The string representation is in the form “name|uuid”.

Parameters:

string_id (str) – The string representation of the identifier

Returns:

The parsed identifier

Return type:

com.robotraconteur.identifier.Identifier