Grounds
    Preparing search index...

    Function Struct

    • Creates a struct Relish value.

      A struct is a heterogeneous collection of named fields, each with a numeric field ID (0-127) and a RelishValue. Fields are encoded in ascending ID order.

      Parameters

      • fields: ReadonlyMap<number, RelishValue>

        Map of field ID to RelishValue for each field

      Returns RelishStruct

      RelishStruct value

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

      const person = Struct(new Map([
      [0, String_('Alice')], // field 0: name
      [1, U32(30)] // field 1: age
      ]));
      encode(person).match(
      (bytes) => console.log('Struct encoded:', bytes),
      (error) => console.error(error)
      );

      Fields must be in ascending ID order during encoding. The Encoder enforces this constraint and returns an error if violations occur. Field IDs must be in range 0-127 (bit 7 must be clear).

      • Array_ for homogeneous ordered collections
      • Map_ for homogeneous key-value collections
      • Enum for tagged unions