XdrErrorclassno test imports itclass XdrError extends ErrorThe one error of reading: what was wrong with the bytes.
| Member | Type | What it is |
|---|---|---|
cause? | unknown | |
name | string | |
message | string | |
stack? | string |
XDR (RFC 4506) as far as ONC RPC and NFS version 3 need it: a writer that appends 32 and 64-bit unsigned integers, booleans, fixed and variable opaque data and strings, each padded to four bytes, and a reader that takes them back and refuses everything the standard does not allow (a read past the end, a length that does not fit, padding that is not zero, a boolean that is not 0 or 1, a string that is not UTF-8). The reader throws one error type inside and decode turns it into a Result, so that the code that decodes a call reads straight and no failure escapes.
import { decode, XdrWriter } from "./xdr.ts";
const w = new XdrWriter();
w.u32(7).string("a.txt");
decode(w.bytes(), (r) => [r.u32(), r.string()]); // ok([7, "a.txt"])XdrErrorclassno test imports itclass XdrError extends ErrorThe one error of reading: what was wrong with the bytes.
| Member | Type | What it is |
|---|---|---|
cause? | unknown | |
name | string | |
message | string | |
stack? | string |
XdrWriterclassclass XdrWriterWrites XDR.
| Member | Type | What it is |
|---|---|---|
u32 | (n: number) => XdrWriter | |
u64 | (n: number | bigint) => XdrWriter | An unsigned 64-bit integer from a whole number (or a bigint). |
bool | (b: boolean) => XdrWriter | |
fixed | (bytes: Uint8Array<ArrayBufferLike>) => XdrWriter | Bytes as they are, padded: the length is not written. |
opaque | (bytes: Uint8Array<ArrayBufferLike>) => XdrWriter | Bytes with their length. |
string | (text: string) => XdrWriter | |
bytes | () => Uint8Array<ArrayBufferLike> | What was written so far. |
length | number |
XdrReaderclassclass XdrReaderReads XDR. Every read throws XdrError where the bytes are not what was asked.
| Member | Type | What it is |
|---|---|---|
left | number | |
u32 | () => number | |
u64big | () => bigint | An unsigned 64-bit integer as a bigint. |
u64 | () => number | An unsigned 64-bit integer as a number: refused where it is not a safe integer. |
bool | () => boolean | |
fixed | (length: number) => Uint8Array<ArrayBufferLike> | length bytes and their padding, which must be zero. |
opaque | (max?: number) => Uint8Array<ArrayBufferLike> | Bytes with their length, at most max. |
string | (max?: number) => string | |
rest | () => Uint8Array<ArrayBufferLike> | The rest of the bytes, unread. |
decodefunctionfunction decode<T>(bytes: Uint8Array<ArrayBufferLike>, read: (r: XdrReader) => T): Result<T, string>Reads a value with a function over a reader: the value, or why the bytes are not what it reads.