struct KSUID
- KSUID
- Struct
- Value
- Object
Included Modules
- Comparable(KSUID)
Defined in:
ksuid.crksuid/base62.cr
ksuid/error.cr
ksuid/utils.cr
Constant Summary
-
EPOCH =
14e8.to_u32 -
KSUID's epoch starts more recently so that the 32-bit number space gives a significantly higher useful lifetime of around 136 years from May 2014. This number (
14e8) was picked to be easy to remember. -
MAX =
from(StaticArray(UInt8, TOTAL_SIZE).new(255_u8)) -
KSUIDwith maximum valid value (aWgEPTl1tmebfsQzFP4bxwgy80V). -
MIN =
from(StaticArray(UInt8, TOTAL_SIZE).new(0_u8)) -
KSUIDwith minimum valid value (000000000000000000000000000). -
PAYLOAD_SIZE =
16 -
Payload is 16 bytes.
-
STRING_ENCODED_SIZE =
27 -
The length of a
KSUIDwhen string (base62) encoded. -
TIMESTAMP_SIZE =
4 -
Timestamp is an
UInt32. -
TOTAL_SIZE =
TIMESTAMP_SIZE + PAYLOAD_SIZE -
KSUIDs are 20 bytes:- 00-03 byte:
UInt32BE UTC#timestampwith custom epoch - 04-19 byte: random
#payload
- 00-03 byte:
-
VERSION =
"0.2.0"
Constructors
-
.from(string : String) : KSUID
Converts a base62-encoded
Stringinto aKSUID. -
.from(bytes : Bytes) : KSUID
Converts
Bytesinto aKSUID. -
.from(array : StaticArray(UInt8, TOTAL_SIZE)) : KSUID
Converts
StaticArrayinto aKSUID. -
.new(time : Time, payload : Bytes)
Generates a new
KSUIDwith given time and payload. -
.new(timestamp : Int, payload : Bytes)
Generates a new
KSUIDwith given timestamp and payload. - .new(time : Time = Time.now)
Instance Method Summary
-
#<=>(other : KSUID)
Compares the
KSUIDagainst other. - #==(other : self)
-
#hash(hasher)
See
Object#hash(hasher) -
#inspect(io : IO) : Nil
Appends this struct's name and instance variables names and values to the given IO.
-
#payload : StaticArray(UInt8, PAYLOAD_SIZE)
The 16-byte random payload without the timestamp.
-
#raw : String
Returns the
KSUIDas a hex-encodedString. - #timestamp : UInt32
-
#to_s(io : IO) : Nil
Writes the
KSUIDas a base62-encodedStringto io. -
#to_slice : Bytes
Returns the
KSUIDasBytes. -
#to_time : Time
Returns the timestamp portion of the
KSUIDas aTimeobject.
Constructor Detail
Converts a base62-encoded String into a KSUID.
Converts StaticArray into a KSUID.
Generates a new KSUID with given timestamp and payload.
Instance Method Detail
Appends this struct's name and instance variables names and values to the given IO.
struct Point
def initialize(@x : Int32, @y : Int32)
end
end
p1 = Point.new 1, 2
p1.to_s # "Point(@x=1, @y=2)"
p1.inspect # "Point(@x=1, @y=2)"