Repository navigation
Expand file tree
/
Copy pathbinary.d.ts
More file actions
42 lines (36 loc) · 1.82 KB
/
Copy pathbinary.d.ts
File metadata and controls
42 lines (36 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* Hand-written typings for @alexify/protoarray/binary: the same schema on a binary wire. The
* bytes are a `Uint8Array`; both sides need the same schema, or one from `resolve` (see Wire
* Format in the guide).
*/
import type { AnySchema } from './index.js';
type Value<S extends AnySchema> = Parameters<S['encode']>[0];
type Decoded<S extends AnySchema> = ReturnType<S['decode']>;
/**
* The bytes of a value on the binary wire, a `Uint8Array` of their own. Throws `EncodeError` for
* a value with no form (the wrong shape, `null` at the root, a union value outside the union, a
* decimal past the safe integers), `SchemaDefinitionError` `ERR_NO_BINARY_FORM` for a schema
* with interned strings, lists of differences or a flat or columns layout (a schema from
* `resolve` reads and writes its writer's wire).
*/
export function toBinary<S extends AnySchema>(schema: S, value: Value<S>): Uint8Array;
/**
* The value of the bytes `toBinary` of the same schema gave. Throws `DecodeError` for a message
* that is not of the schema (truncated, an index out of range, a required field missing) when
* the schema validates, and for anything but a `Uint8Array`.
*/
export function fromBinary<S extends AnySchema>(schema: S, bytes: Uint8Array): Decoded<S>;
/** Installs `toBinary` and `fromBinary` as methods of Schema. Once per process. */
export function register(): void;
declare module './index.js' {
interface Schema<Output, Input> {
/** `toBinary` of `@alexify/protoarray/binary`, once its `register()` has run. */
toBinary(value: Input): Uint8Array;
/** `fromBinary` of `@alexify/protoarray/binary`, once its `register()` has run. */
fromBinary(bytes: Uint8Array): Output;
}
interface Collection<Output, Input> {
toBinary(value: readonly Input[]): Uint8Array;
fromBinary(bytes: Uint8Array): Output[];
}
}