Grounds
    Preparing search index...

    Function Array_

    • Creates a homogeneous array Relish value.

      The name has an underscore suffix to avoid shadowing the global Array object. All elements must be the same type specified by elementType. For primitive element types, elements are raw JS values. For composite types (Array, Map, Struct, Enum), elements are RelishValue objects.

      Type Parameters

      Parameters

      • elementType: T

        TypeCode specifying the type of all array elements

      • elements: readonly TypeCodeToJsType<T>[]

        Array of elements matching the elementType

      Returns RelishArray<T>

      RelishArray value

      Error if any element does not match the expected type

      import { Array_, U32, encode } from '@grounds/core';

      // Array of unsigned 32-bit integers
      const numbers = Array_(0x04, [10, 20, 30]); // TypeCode.U32 = 0x04
      encode(numbers).match(
      (bytes) => console.log('Array encoded:', bytes),
      (error) => console.error(error)
      );

      Named Array_ (with trailing underscore) to avoid shadowing the global Array type. Type validation is performed at runtime to catch mismatches early.

      • Map_ for heterogeneous key-value collections
      • Struct for fixed fields with different types