oids

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 was extracted from the Mongodb interface and it thus binary compatible with a Mongo OID.

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

Types

Oid = object
  time: int32
  fuzz: int32
  count: int32
An OID.   Source Edit

Procs

proc `==`(oid1: Oid; oid2: Oid): bool {...}{.raises: [], tags: [].}
Compares two Mongo Object IDs for equality.   Source Edit
proc hash(oid: Oid): Hash {...}{.raises: [], tags: [].}
Generates hash of Oid for use in hashtables.   Source Edit
proc hexbyte(hex: char): int {...}{.raises: [], tags: [].}
  Source Edit
proc parseOid(str: cstring): Oid {...}{.raises: [], tags: [].}
Parses an OID.   Source Edit
proc oidToString(oid: Oid; str: cstring) {...}{.raises: [], tags: [].}
Converts an oid to str which must have space allocated for 25 elements.   Source Edit
proc `$`(oid: Oid): string {...}{.raises: [], tags: [].}
Converts an oid to string.   Source Edit
proc genOid(): Oid {...}{.raises: [], tags: [TimeEffect].}
Generates a new OID.

Examples:

doAssert ($genOid()).len == 24
if false:
  doAssert $genOid() == "5fc7f546ddbbc84800006aaf"
  Source Edit
proc generatedTime(oid: Oid): Time {...}{.raises: [], tags: [].}
Returns the generated timestamp of the OID.   Source Edit