u64(endianness?: Endianness): Coder<bigint>
Creates a coder for 64-bit unsigned integers.
This function creates a coder that can encode/decode 64-bit unsigned integers (range 0-18,446,744,073,709,551,615). The endianness parameter determines the byte order used. Note that 64-bit integers are returned as bigint to handle the full range.
Example 1
Example 1
import { assertEquals } from "@std/assert"; import { u64 } from "@hertzg/binstruct/numeric"; // Create big-endian and little-endian coders const u64be = u64("be"); const u64le = u64("le"); // Test data const testValue = 18446744073709551615n; // Encode and decode with big-endian const bufferBE = new Uint8Array(8); const bytesWrittenBE = u64be.encode(testValue, bufferBE); const [decodedBE, bytesReadBE] = u64be.decode(bufferBE); assertEquals(decodedBE, testValue); assertEquals(bytesWrittenBE, 8); assertEquals(bytesReadBE, 8); // Encode and decode with little-endian const bufferLE = new Uint8Array(8); const bytesWrittenLE = u64le.encode(testValue, bufferLE); const [decodedLE, bytesReadLE] = u64le.decode(bufferLE); assertEquals(decodedLE, testValue); assertEquals(bytesWrittenLE, 8); assertEquals(bytesReadLE, 8);
optional
endianness: Endianness = be
The byte order to use ("be" for big-endian, "le" for little-endian), defaults to "be"
Coder<bigint>
A Coder<bigint> for 64-bit unsigned integers