Class Codec<T, TParseInput>Abstract

Type Parameters

  • T

  • TParseInput = T

Hierarchy (view full)

Constructors

Properties

name: string

Name of this codec used to export .mol file.

Methods

  • Create a new codec which shares the same underlying molecule type but with different JavaScript type.

    This is useful to create a different view wrapper.

    Type Parameters

    • TOutter

    • TOutterParseInput

    Parameters

    Returns Codec<TOutter, TOutterParseInput>

    Example

    import { mol } from "@ckb-cobuild/molecule";
    const ByteOpt = mol.option("ByteOpt", mol.byte);
    const BooleanOpt = ByteOpt.around({
    safeParse: (input: boolean | null) => mol.parseSuccess(input),
    willPack: (input: boolean | null) =>
    input !== null ? (input ? 1 : 0) : null,
    didUnpack: (value: number | null) => (value !== null ? value !== 0 : null),
    });
  • Internal

    Parameters

    • minimalByteLength: number
    • buffer: Uint8Array

    Returns void

  • Export the schema of this codec and all the dependencies into the map.

    The order of the map is guaranteed that the dependency is always exported before the dependent.

    Parameters

    • exported: Map<string, string>

    Returns Map<string, string>

  • Pack the value and append the buffer to the provided writer.

    Take the advantage of writer and append the buffer as blocks. The writer can concatenate all blocks into one buffer for the final result.

    Parameters

    Returns void

  • Unpack the value from the molecule buffer.

    Parameters

    • buffer: Uint8Array
    • Optional strict: boolean

      whehter to allow unknown fields in the buffer. True to enable. It is off by default.

    Returns T

    Throws

    CodecError

Generated using TypeDoc