getLinearMessagePackerInstructionPlan

function getLinearMessagePackerInstructionPlan(
    __namedParameters,
): MessagePackerInstructionPlan;

Creates a MessagePackerInstructionPlan that packs instructions such that each instruction consumes as many bytes as possible from the given totalLength while still being able to fit into the given transaction messages.

This is particularly useful for instructions that write data to accounts and must span multiple transactions due to their size limit.

This message packer will first call getInstruction with a length of zero to determine the base size of the instruction before figuring out how many additional bytes can be packed into the transaction message. That remaining space will then be used to call getInstruction again with the appropriate length.

Parameters

ParameterType
__namedParameters{ getInstruction: (offset, length) => Instruction; totalLength: number; }
__namedParameters.getInstruction(offset, length) => Instruction
__namedParameters.totalLengthnumber

Returns

MessagePackerInstructionPlan

Example

const plan = getLinearMessagePackerInstructionPlan({
  totalLength: dataToWrite.length,
  getInstruction: (offset, length) =>
    getWriteInstruction({
      offset,
      data: dataToWrite.slice(offset, offset + length),
    }),
});
plan satisfies MessagePackerInstructionPlan;

See

MessagePackerInstructionPlan

On this page