Class Shape<I, O>Abstract

Type Parameters

  • in I
  • out O = I

Hierarchy

  • _Shape
    • Shape

Implements

Constructors

  • Type Parameters

    • in I
    • out O = I

    Returns Shape<I, O>

Properties

decoders: [Predicate<any>, Decoder<Shape<any, any>, any, any>][]
encoders: [Predicate<any>, Encoder<Shape<any, any>, any>][]
metadata: Metadata<I, O>

An array with metadata representing the construction of this shape

nativeType?: string
registerDecoder: ((predicate: Predicate<any>, decoder: Decoder<Shape<any, any>, any, any>) => void)
registerEncoder: ((predicate: Predicate<any>, encoder: Encoder<Shape<any, any>, any>) => void)
staticSize: number

A static estimation of the size, which may be an under- or over-estimate

subAssert: ((state: AssertState) => void)

Asserts that the value is valid for this shape

subDecode: ((buffer: DecodeBuffer) => O)

Decodes the value from the supplied buffer

subEncode: ((buffer: EncodeBuffer, value: I) => void)

Encodes the value into the supplied buffer, which should have at least staticSize free byte.

tryDecode: ((input: any) => O)
tryEncode: ((input: any) => Uint8Array)

Methods

  • Requires the shape to have an explicit type annotation; if it doesn't, use $.assert instead.

    Parameters

    • value: unknown

    Returns asserts value is I

  • Decodes a value from the supplied Uint8Array

    Parameters

    • array: Uint8Array

    Returns O

  • Encodes the value into a new Uint8Array (throws if async)

    Parameters

    • value: I

    Returns Uint8Array

  • Asynchronously encodes the value into a new Uint8Array

    Parameters

    • value: I

    Returns Promise<Uint8Array>