Class SHeadArray<HeadType, ItemSchema, ItemType>

this behaves just like regular SArray, but has its array length stored in the head (beginning) bytes in the provided head_type byte format.

Type Parameters

  • HeadType extends NumericType | VarNumericType

  • ItemSchema extends SchemaChildNode<any, string>

  • ItemType = NonNullable<ItemSchema["value"]>

Hierarchy

  • SArray<ItemSchema, ItemType>
    • SHeadArray

Properties

value?: ItemType[]

the value held by this schema node. used as a storage for interceptors to interact and read decoded value
it can also used as a means for storing default values for the encoder to utilize.
but besides those two scenarios, it should typically be left unassigned.
this also comes in handy when annotating types both for the encoder or decoder

name?: string

name of the node, used for object property key naming by parent SchemaRecordNode

doc?: string | true

an optional doc string for this schema node, that should be cleared when MINIFY is true
to achive that, you would want to write your doc strings as follows:

declare const [DEBUG, MINIFY, BUNDLE]: [boolean, boolean, boolean]
const my_schema_node: SPrimitive<number> {
type: "u4l",
doc: MINIFY || "a stupid description of this 32-bit unsinged little piece of endian."
}
children: [item_schema: ItemSchema]

there must be only a single child element that specifies the schema of the kind of items held by this array

args: [index_start: number, index_end: number] | [len?: number]

there are two possible syntaxes, and the one that gets chosen is based on the length of this.args

  • if args.length == 1, then: args[0] must specify the length of the array when decoding
  • if args.length == 2, then: args[0] must specify the starting index, and args[1] must specify the ending index
type: "head_array"

a mandatory kind descriptior of the primitive kind

head_type: HeadType
head_schema: SPrimitive<number, HeadType>

Methods

  • manually set this schema's type to the provided type_name, and also register the new type_name to global type_registery if register = true.
    this is the only easy way to register type_names of sub-sub-classes of abstract SchemaNode.
    check out SHeadArray to see how it extends SArray, but registers its own type_name = "headarray" that's different from its parent class's type_name = "array"

    Type Parameters

    • NewTypeName extends string

    Parameters

    • type_name: NewTypeName
    • register: boolean = true

    Returns SHeadArray<HeadType, ItemSchema, ItemType> & {
        type: NewTypeName;
    }

  • Type Parameters

    • Name extends string

    Parameters

    • name: Name

    Returns SHeadArray<HeadType, ItemSchema, ItemType> & {
        name: Name;
    }

  • Parameters

    • Rest ...children: [item_schema: ItemSchema]

    Returns Require<SHeadArray<HeadType, ItemSchema, ItemType>, "children">

  • Parameters

    • value: ItemType[]

    Returns Require<SHeadArray<HeadType, ItemSchema, ItemType>, "value">

  • Parameters

    • Rest ...args: NonNullable<[index_start: number, index_end: number] | [len?: number]>

    Returns SHeadArray<HeadType, ItemSchema, ItemType>

  • Parameters

    • Rest ...args: NonNullable<[index_start: number, index_end: number] | [len?: number]>

    Returns SHeadArray<HeadType, ItemSchema, ItemType>

  • decode one item

    Parameters

    • buf: Uint8Array
    • offset: number
    • Rest ...args: never[]

    Returns Decoded<ItemType, number>

  • an abstract static method that creates an instance of this schema class, using a regular javascript object

    Parameters

    • schema_obj: ClassFieldsOf<SHeadArray<any, any, any>>

    Returns SHeadArray<any, SchemaNode<unknown, string>, {}>

  • describe how an instance of this schema node should be encoded into bytes

    Parameters

    • value: ItemType[]

    Returns Uint8Array

  • describe bytes from a buffer should decode a value for this schema node

    Parameters

    • buf: Uint8Array
    • offset: number

    Returns Decoded<ItemType[], number>

Constructors

  • Type Parameters

    • HeadType extends NumericType | VarNumericType

    • ItemSchema extends SchemaChildNode<any, string, ItemSchema>

    • ItemType = NonNullable<ItemSchema["value"]>

    Parameters

    • head_type: HeadType
    • Optional child: ItemSchema

    Returns SHeadArray<HeadType, ItemSchema, ItemType>

Generated using TypeDoc