class Uuidx::Version8

UUID Version 8 defined by the RFC 4122 BIS-01 Draft.

Since UUID v8 is entirely custom to your application, first create a generator definition class.

class MyGeneratorDefinition
  def custom_a
    1
  end

  def custom_b
    2
  end

  def custom_c
    3
  end
end

The requirements for each method are:

Then create a UUID v8 generator by passing in the class, and call generate.

g = Uuidx::Version8.new(MyGeneratorDefinition)
g.generate # => "00000000-0001-8002-8000-000000000003"

The implementation will truncate the results of each generator module method so that they abide by the bit lengths of the UUID specification. The thread safety of UUID v8 depends entirely on your implementation.

There is no default implementation of UUID v8.

Public Class Methods

new(definition_class) click to toggle source

Construct a UUID v8 generator.

# File lib/uuidx/version8.rb, line 45
def initialize(definition_class)
  @definition = definition_class.new
end

Public Instance Methods

generate() click to toggle source

Construct a UUID v8 value.

# File lib/uuidx/version8.rb, line 50
def generate
  a = @definition.custom_a & CUSTOM_A_MASK
  b = @definition.custom_b & CUSTOM_B_MASK
  high = (a << A_SHIFT) | b
  c = @definition.custom_c & CUSTOM_C_MASK

  Uuidx.format(VERSION_VARIANT | (high << HIGH_SHIFT) | c)
end