/** * This code was AUTOGENERATED using the Codama library. * Please DO NOT EDIT THIS FILE, instead use visitors * to add features, then rerun Codama to update it. * * @see https://github.com/codama-idl/codama */ import { addDecoderSizePrefix, addEncoderSizePrefix, combineCodec, getBooleanDecoder, getBooleanEncoder, getBytesDecoder, getBytesEncoder, getDiscriminatedUnionDecoder, getDiscriminatedUnionEncoder, getStructDecoder, getStructEncoder, getU32Decoder, getU32Encoder, type Codec, type Decoder, type Encoder, type GetDiscriminatedUnionVariant, type GetDiscriminatedUnionVariantContent, type ReadonlyUint8Array, } from "@solana/kit"; /** Versioned arguments for the `writeToBuffer` instruction. */ export type WriteToBufferArgs = { __kind: "V1"; /** The chunk of serialized RuleSet data to append. */ serializedRuleSet: ReadonlyUint8Array; /** Whether to overwrite the buffer from the start instead of appending. */ overwrite: boolean; }; export type WriteToBufferArgsArgs = WriteToBufferArgs; export function getWriteToBufferArgsEncoder(): Encoder { return getDiscriminatedUnionEncoder([ [ "V1", getStructEncoder([ [ "serializedRuleSet", addEncoderSizePrefix(getBytesEncoder(), getU32Encoder()), ], ["overwrite", getBooleanEncoder()], ]), ], ]); } export function getWriteToBufferArgsDecoder(): Decoder { return getDiscriminatedUnionDecoder([ [ "V1", getStructDecoder([ [ "serializedRuleSet", addDecoderSizePrefix(getBytesDecoder(), getU32Decoder()), ], ["overwrite", getBooleanDecoder()], ]), ], ]); } export function getWriteToBufferArgsCodec(): Codec< WriteToBufferArgsArgs, WriteToBufferArgs > { return combineCodec( getWriteToBufferArgsEncoder(), getWriteToBufferArgsDecoder(), ); } // Data Enum Helpers. export function writeToBufferArgs( kind: "V1", data: GetDiscriminatedUnionVariantContent< WriteToBufferArgsArgs, "__kind", "V1" >, ): GetDiscriminatedUnionVariant; export function writeToBufferArgs< K extends WriteToBufferArgsArgs["__kind"], Data, >(kind: K, data?: Data) { return Array.isArray(data) ? { __kind: kind, fields: data } : { __kind: kind, ...(data ?? {}) }; } export function isWriteToBufferArgs( kind: K, value: WriteToBufferArgs, ): value is WriteToBufferArgs & { __kind: K } { return value.__kind === kind; }