leque / Gauche-ulid

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Gauche-ulid

An ULID implementation in Gauche.

Requirement

  • Gauche 0.9.7 or later

API

Record Type: <ulid>

ULID type.

Procedure: make-ulid :optional (timestamp #f) (random #f) → ulid

Creates an <ulid> instance.

TIMESTAMP is a timestamp component of ULID. It should be a non-negative integer representing Unix time in milliseconds. Its default value is (ulid:current-time).

RANDOM should be an integer or a procedure. If RANDOM is an integer, it is used as a random component of ULID. If RANDOM is a procedure, it is called with two arguments, a byte-size and a timestamp, and should return a random component of ULID, a non-negative integer that fits in the given byte-size. RANDOM procedure may use the timestamp argument to ensure monotonicity. If RANDOM is not specified, a random intger generated with ulid:urand-read-integer or ulid:random-integer is used.

Procedure: ulid-timestamp ulid → integer

Extracts the timestamp component of ULID.

Procedure: ulid-time ulid → time-utc

Extracts the timestamp component of ULID as a SRFI-19 <time>.

Procedure: ulid-random ulid → integer

Extracts the random component of ULID.

Procedure: ulid->string ulid → string

Converts ULID into a string representation.

Procedure: string->ulid str → ulid

Parses STR as an ULID.

Procedure: ulid->bytevector ulid → u8vector

Converts ULID into a binary representation.

Procedure: bytevector->ulid bytevector → ulid

Parses BYTEVECTOR as an ULID.

Procedure: ulid:current-time → integer

Returns the current time in Unix time milliseconds.

Procedure: ulid:urand-read-integer byte-size timestamp → integer

Reads a BYTE-SIZE bytes non-negative integer from /dev/urandom. If /dev/urandom is not available, this procedure returns false. This procedure does not use TIMESTAMP argument.

Procedure: ulid:random-integer byte-size timestamp → integer

Generates a BYTE-SIZE bytes non-negative integer by using SRFI-27 random-intger procedure. This procedure does not use TIMESTAMP argument.

Note: this procedure may not be cryptographically secure.

About

License:MIT License


Languages

Language:Scheme 86.6%Language:Makefile 13.4%