Source Edit

Nim OID support. An OID is a global ID that consists of a timestamp, a unique counter and a random value. This combination should suffice to produce a globally distributed unique ID.

This implementation calls initRand() for the first call of genOid.

Imports

hashes, times, endians, random, decode_helpers

Types

  1. Oid = object

An OID. Source Edit

Procs

  1. proc `$`(oid: Oid): string {....raises: [], tags: [], forbids: [].}

Converts an OID to a string. Source Edit

  1. proc `==`(oid1: Oid; oid2: Oid): bool {.inline, ...raises: [], tags: [],
  2. forbids: [].}

Compares two OIDs for equality. Source Edit

  1. proc generatedTime(oid: Oid): Time {....raises: [], tags: [], forbids: [].}

Returns the generated timestamp of the OID. Source Edit

  1. proc genOid(): Oid {....raises: [], tags: [TimeEffect], forbids: [].}

Generates a new OID.

Example:

  1. doAssert ($genOid()).len == 24

Example: cmd: -r:off

  1. echo $genOid() # for example, "5fc7f546ddbbc84800006aaf"

Source Edit

  1. proc hash(oid: Oid): Hash {....raises: [], tags: [], forbids: [].}

Generates the hash of an OID for use in hashtables. Source Edit

  1. proc hexbyte(hex: char): int {.inline, ...raises: [], tags: [], forbids: [].}

Source Edit

  1. proc parseOid(str: cstring): Oid {....raises: [], tags: [], forbids: [].}

Parses an OID. Source Edit