AnkiIO 1.0.2
Build, validate, import, and export Anki-compatible decks from .NET
Loading...
Searching...
No Matches
AnkiIO.AnkiId Class Reference

Creates positive 64-bit identifiers for new objects or repeatable external imports. More...

Static Public Member Functions

static long New ()
 Creates a positive, process-unique identifier for a new deck, note type, note, or card.
static long FromStableValue (string scope, string value)
 Derives a deterministic positive identifier from a caller-controlled namespace and stable value.

Detailed Description

Creates positive 64-bit identifiers for new objects or repeatable external imports.

Decks, note types, notes, and cards occupy a shared validation namespace in an AnkiIO object graph. Use New for fresh objects and FromStableValue when the same external record must receive the same ID on every run. Neither method reserves IDs in another process, examines caller-supplied IDs, or queries an installed Anki profile; always validate the complete graph before output.

Definition at line 14 of file AnkiId.cs.

Member Function Documentation

◆ FromStableValue()

long AnkiIO.AnkiId.FromStableValue ( string scope,
string value )
inlinestatic

Derives a deterministic positive identifier from a caller-controlled namespace and stable value.

Parameters
scopeA non-empty namespace, such as "external-note", separating unrelated identity domains.
valueA non-empty stable source identifier whose exact ordinal text is significant.
Returns
A non-zero positive 63-bit identifier.

The UTF-8 encoding of scope , a null separator, and value is hashed with SHA-256. The low eight hash bytes are interpreted consistently as little-endian, with the sign bit cleared. Equal ordinal inputs—including case and whitespace—always produce equal IDs across supported platforms.

Use different scopes for different object kinds (for example deck, note, and card) so equal source keys do not collide across the shared graph namespace. The 63-bit projection has a small but non-zero collision probability; validation is still required, especially for adversarial or very large imports. This method maps identity only—it does not create a stable Anki note GUID; pass that separately to AnkiNote.

Exceptions
ArgumentNullExceptionscope or value is null.
ArgumentExceptionscope or value is empty or whitespace.
var noteId = AnkiId.FromStableValue("external-note", sourceRecord.Id);
var cardId = AnkiId.FromStableValue("external-card", sourceRecord.Id);
Creates positive 64-bit identifiers for new objects or repeatable external imports.
Definition AnkiId.cs:15
static long FromStableValue(string scope, string value)
Derives a deterministic positive identifier from a caller-controlled namespace and stable value.
Definition AnkiId.cs:57

Definition at line 57 of file AnkiId.cs.

◆ New()

long AnkiIO.AnkiId.New ( )
inlinestatic

Creates a positive, process-unique identifier for a new deck, note type, note, or card.

Returns
A value greater than zero that has not previously been returned by this process.

The method is thread-safe and combines a millisecond timestamp-shaped starting point with an atomic counter. Its guarantee is process-local: another process, an explicit imported ID, or an existing Anki collection could use the same number. It is also deliberately not repeatable across runs. Use FromStableValue for deterministic imports and let AnkiValidator detect collisions within the graph being written.

var deck = new AnkiDeck("Imported", id: AnkiId.New());
Builds one named deck hierarchy and acts as the root for validation and export.
Definition AnkiDeck.cs:31
static long New()
Creates a positive, process-unique identifier for a new deck, note type, note, or card.
Definition AnkiId.cs:31

Definition at line 31 of file AnkiId.cs.


The documentation for this class was generated from the following file: