CCC Docs
    Preparing search index...

    Function fixedUnion

    • FixedUnion is a fixed-size union type where all variants must be fixed-size types of identical byte length. The total byteLength is payloadByteLength + 4 (4-byte uint32 ItemId tag).

      Compatibility note: fixedUnion is a CCC extension for scenarios requiring fixed memory layouts (such as embedding inside mol.struct, mol.array, or mol.vector as FixVec). While the standalone wire format (4-byte tag + variant payload) is binary-compatible with a union encoding, composing it into struct, array, or FixVec is not part of the standard upstream Molecule union schema specification.

      Migration guide:

      // Preserve legacy equal-length union fixed container layout (FixVec):
      const Legacy = mol.vector(mol.fixedUnion(layout));

      // Use canonical Molecule union vector (DynVec):
      const Canonical = mol.vector(mol.union(layout));

      Type Parameters

      • T extends Record<string, CodecLike<any, any, any>>

      Parameters

      • codecLayout: T

        an object mapping variant names to fixed-size codecs of identical byteLength

      • Optionalfields: Record<keyof T, number | null | undefined>

        optional mapping from variant names to custom numeric IDs

      Returns Codec<
          UnionEncodable<T, keyof T>
          | { inner: UnionEncodable<T> },
          UnionDecoded<T, keyof T>,
          ChildContext<T>,
      >