struct Minion::UUID

Overview

This struct wraps up a UUID that encodes a timestamp measured as seconds from the epoch (0001-01-01 00:00:00.0 UTC) observed at the location where the timestamp was generated, plus nanoseconds in the current second, plus 6 bytes for unique identification of the source -- this could be an IPV4 address with two null bytes, a MAC address, or some other sequence that will fit in 6 bytes.

Nanoseconds will fit in an Int32 (4 bytes), but seconds since the epoch will not. The current number of seconds leaks a short distance into a 5th byte, meaning that in this class, it has to be represented by an Int64. This is problematic because a UID allows for 16 bytes, so the use of 8 for seconds and 4 for nanoseconds leaves only 4 four system identification. It also leaves three bytes in the UUID as zeros.

One solution is to combine the seconds and the nanoseconds into a single Int64 number. This requires math operations to do efficiently: (seconds * 1000000000) + nanoseconds and then more math to extract the original numbers in order to reconstruct the original timestamp. This leaves 8 bytes for identification or other uniqueness information.

The other options is to truncate 2 bytes off of the seconds, storing 6 bytes of seconds data. This leaves 6 bytes for identification.

The current implementation chose option #2, as it is less work to generate a UUID if math is not involved.

+-------------+-----------------+------------+ | nanoseconds | seconds | identifier | | 0..3 | 4..10 | 11..15 | +-------------+-----------------+------------+

Defined in:

minion/uuid.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(seconds : Int64, nanoseconds : Int32, identifier : Slice(UInt8) | String | Nil = nil) #

[View source]
def self.new(uuid : String) #

[View source]
def self.new(uuid : UUID) #

[View source]
def self.new(timestamp : Time, identifier : Slice(UInt8) | String | Nil = nil) #

[View source]
def self.new(identifier : Slice(UInt8) | String | Nil = nil) #

[View source]

Class Method Detail

def self.extra #

[View source]
def self.extra=(extra) #

[View source]
def self.identifier #

[View source]
def self.identifier=(identifier) #

[View source]

Instance Method Detail

def initialize_impl(seconds : Int64, nanoseconds : Int32, identifier : Slice(UInt8) | String | Nil) #

[View source]
def seconds_and_nanoseconds : Tuple(Int64, Int32) #

[View source]
def timestamp #

[View source]
def to_s #
Description copied from class Object

Returns a nicely readable and concise string representation of this object, typically intended for users.

This method should usually not be overridden. It delegates to #to_s(IO) which can be overridden for custom implementations.

Also see #inspect.


[View source]
def utc #

[View source]