Grounds
    Preparing search index...

    Function Enum

    • Creates an enum Relish value (tagged union).

      Enums represent one of several variants, each with a numeric ID (0-127) and an associated value. The variant ID and value are encoded together.

      Parameters

      • variantId: number

        Numeric ID (0-127) identifying which variant is active

      • value: RelishValue

        RelishValue for the active variant

      Returns RelishEnum

      RelishEnum value

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

      // Success variant with message
      const success = Enum(0, String_('operation completed'));
      encode(success).match(
      (bytes) => console.log('Success encoded:', bytes),
      (error) => console.error(error)
      );

      // Error variant with code
      const error_ = Enum(1, U32(404));
      encode(error_).match(
      (bytes) => console.log('Error encoded:', bytes),
      (error) => console.error(error)
      );

      Variant IDs must be in range 0-127 (bit 7 must be clear).

      Struct for heterogeneous fixed fields