Skip to content

Commit

Permalink
fix: reset offset
Browse files Browse the repository at this point in the history
  • Loading branch information
broofa committed Jul 18, 2024
1 parent 11b7f02 commit 050a7cf
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/v7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import rng from './rng.js';
import { unsafeStringify } from './stringify.js';

type V7State = {
msecs: number;
seq: number;
msecs: number; // time, milliseconds
seq: number; // sequence number (32-bits)
};

const _state: V7State = {
msecs: -Infinity, // time, milliseconds
seq: 0, // sequence number (32-bits)
msecs: -Infinity,
seq: 0,
};

function v7(options?: Version7Options, buf?: undefined, offset?: number): string;
Expand Down Expand Up @@ -61,13 +61,12 @@ export function updateV7State(state: V7State, now: number, rnds: Uint8Array) {
return state;
}

function v7Bytes(
rnds: Uint8Array,
msecs: number | undefined,
seq: number | undefined,
buf = new Uint8Array(16),
offset = 0
) {
function v7Bytes(rnds: Uint8Array, msecs?: number, seq?: number, buf?: Uint8Array, offset = 0) {
if (!buf) {
buf = new Uint8Array(16);
offset = 0;
}

// Defaults
msecs ??= Date.now();
seq ??= ((rnds[6] * 0x7f) << 24) | (rnds[7] << 16) | (rnds[8] << 8) | rnds[9];
Expand Down

0 comments on commit 050a7cf

Please sign in to comment.