UUID.Info (UUID v1.4.0) View Source

UUID info

Link to this section Summary

Functions

Inspect a UUID and return tuple with {:ok, result}, where result is information about its 128-bit binary content, type, version and variant.

Inspect a UUID and return information about its 128-bit binary content, type, version and variant.

Identify the UUID variant according to section 4.1.1 of RFC 4122.

Link to this section Types

Specs

t() :: %UUID.Info{
  binary: term(),
  type: type(),
  uuid: binary(),
  variant: variant(),
  version: version()
}

Specs

type() :: :default | :hex | :urn | :raw | :slug

Specs

variant() :: :rfc4122 | :reserved_ncs | :reserved_microsoft | :reserved_future

Specs

version() :: 1 | 3 | 4 | 5 | 6

Link to this section Functions

Specs

new(binary()) :: {:ok, t()} | {:error, String.t()}

Inspect a UUID and return tuple with {:ok, result}, where result is information about its 128-bit binary content, type, version and variant.

Timestamp portion is not checked to see if it's in the future, and therefore not yet assignable. See "Validation mechanism" in section 3 of RFC 4122.

Will return {:error, message} if the given string is not a UUID representation in a format like:

  • "870df8e8-3107-4487-8316-81e089b8c2cf"
  • "8ea1513df8a14dea9bea6b8f4b5b6e73"
  • "urn:uuid:ef1b1a28-ee34-11e3-8813-14109ff1a304"

Examples

iex> UUID.Info.new("870df8e8-3107-4487-8316-81e089b8c2cf")
{:ok, %UUID.Info{
  uuid: "870df8e8-3107-4487-8316-81e089b8c2cf",
  binary: <<135, 13, 248, 232, 49, 7, 68, 135, 131, 22, 129, 224, 137, 184, 194, 207>>,
  type: :default,
  version: 4,
  variant: :rfc4122
}}

iex> UUID.Info.new("8ea1513df8a14dea9bea6b8f4b5b6e73")
{:ok, %UUID.Info{
  uuid: "8ea1513df8a14dea9bea6b8f4b5b6e73",
  binary: <<142, 161, 81, 61, 248, 161, 77, 234, 155,
              234, 107, 143, 75, 91, 110, 115>>,
  type: :hex,
  version: 4,
  variant: :rfc4122
}}

iex> UUID.Info.new("urn:uuid:ef1b1a28-ee34-11e3-8813-14109ff1a304")
{:ok, %UUID.Info{
  uuid: "urn:uuid:ef1b1a28-ee34-11e3-8813-14109ff1a304",
  binary: <<239, 27, 26, 40, 238, 52, 17, 227, 136, 19, 20, 16, 159, 241, 163, 4>>,
  type: :urn,
  version: 1,
  variant: :rfc4122
}}

iex> UUID.Info.new(<<39, 73, 196, 181, 29, 90, 74, 96, 157, 47, 171, 144, 84, 164, 155, 52>>)
{:ok, %UUID.Info{
  uuid: <<39, 73, 196, 181, 29, 90, 74, 96, 157, 47, 171, 144, 84, 164, 155, 52>>,
  binary: <<39, 73, 196, 181, 29, 90, 74, 96, 157, 47, 171, 144, 84, 164, 155, 52>>,
  type: :raw,
  version: 4,
  variant: :rfc4122
}}

iex> UUID.Info.new("12345")
{:error, "Invalid argument; Not a valid UUID: 12345"}

Specs

new!(binary()) :: t()

Inspect a UUID and return information about its 128-bit binary content, type, version and variant.

Timestamp portion is not checked to see if it's in the future, and therefore not yet assignable. See "Validation mechanism" in section 3 of RFC 4122.

Will raise an ArgumentError if the given string is not a UUID representation in a format like:

  • "870df8e8-3107-4487-8316-81e089b8c2cf"
  • "8ea1513df8a14dea9bea6b8f4b5b6e73"
  • "urn:uuid:ef1b1a28-ee34-11e3-8813-14109ff1a304"

Examples

iex> UUID.Info.new!("870df8e8-3107-4487-8316-81e089b8c2cf")
%UUID.Info{
  uuid: "870df8e8-3107-4487-8316-81e089b8c2cf",
  binary: <<135, 13, 248, 232, 49, 7, 68, 135, 131, 22, 129, 224, 137, 184, 194, 207>>,
  type: :default,
  version: 4,
  variant: :rfc4122
}

iex> UUID.Info.new!("8ea1513df8a14dea9bea6b8f4b5b6e73")
%UUID.Info{
  uuid: "8ea1513df8a14dea9bea6b8f4b5b6e73",
  binary: <<142, 161, 81, 61, 248, 161, 77, 234, 155, 234, 107, 143, 75, 91, 110, 115>>,
  type: :hex,
  version: 4,
  variant: :rfc4122
}

iex> UUID.Info.new!("urn:uuid:ef1b1a28-ee34-11e3-8813-14109ff1a304")
%UUID.Info{
  uuid: "urn:uuid:ef1b1a28-ee34-11e3-8813-14109ff1a304",
  binary: <<239, 27, 26, 40, 238, 52, 17, 227, 136, 19, 20, 16, 159, 241, 163, 4>>,
  type: :urn,
  version: 1,
  variant: :rfc4122
}

iex> UUID.Info.new!(<<39, 73, 196, 181, 29, 90, 74, 96, 157, 47, 171, 144, 84, 164, 155, 52>>)
%UUID.Info{
  uuid: <<39, 73, 196, 181, 29, 90, 74, 96, 157, 47, 171, 144, 84, 164, 155, 52>>,
  binary: <<39, 73, 196, 181, 29, 90, 74, 96, 157, 47, 171, 144, 84, 164, 155, 52>>,
  type: :raw,
  version: 4,
  variant: :rfc4122
}

iex> UUID.Info.new!("foobar")
** (ArgumentError) Invalid argument; Not a valid UUID: foobar

Specs

variant(binary()) :: variant()

Identify the UUID variant according to section 4.1.1 of RFC 4122.

Examples

iex> UUID.Info.variant(<<1, 1, 1>>)
:reserved_future

iex> UUID.Info.variant(<<1, 1, 0>>)
:reserved_microsoft

iex> UUID.Info.variant(<<1, 0, 0>>)
:rfc4122

iex> UUID.Info.variant(<<0, 1, 1>>)
:reserved_ncs

iex> UUID.Info.variant(<<1>>)
** (ArgumentError) Invalid argument; Not valid variant bits