nativeUICommandToDartFFI function

List<UICommand> nativeUICommandToDartFFI(
  1. double contextId
)

Implementation

List<UICommand> nativeUICommandToDartFFI(double contextId) {
  Pointer<UICommandBufferPack> nativeCommandPack = getUICommandItems(getAllocatedPage(contextId)!);
  int commandLength = nativeCommandPack.ref.length;
  Pointer<UICommandItemFFI> commandBuffer = nativeCommandPack.ref.data.cast<UICommandItemFFI>();
  List<UICommand> results = List.generate(commandLength, (int index) {
    UICommand command = UICommand();

    // Access the struct at the current index
    UICommandItemFFI commandItem = commandBuffer[index];

    // Extract type
    command.type = UICommandType.values[commandItem.type];

    if (command.type == UICommandType.setStyleById) {
      command.args = '';
      command.nativePtr = commandItem.nativePtr != 0 ? Pointer.fromAddress(commandItem.nativePtr) : nullptr;
      command.nativePtr2 = commandItem.nativePtr2 != 0 ? Pointer.fromAddress(commandItem.nativePtr2) : nullptr;
      command.stylePropertyId = commandItem.args01Length;
      command.styleValueSlot = commandItem.string_01;
      return command;
    }

    // Extract args string
    if (commandItem.string_01 != 0) {
      Pointer<Uint16> args_01 = Pointer.fromAddress(commandItem.string_01);
      command.args = uint16ToString(args_01, commandItem.args01Length);
      malloc.free(args_01);
    } else {
      command.args = '';
    }

    // Extract native pointers
    command.nativePtr = commandItem.nativePtr != 0 ? Pointer.fromAddress(commandItem.nativePtr) : nullptr;
    command.nativePtr2 = commandItem.nativePtr2 != 0 ? Pointer.fromAddress(commandItem.nativePtr2) : nullptr;

    return command;
  }, growable: false);

  _freeActiveCommandBuffer(nativeCommandPack.ref.head);
  malloc.free(nativeCommandPack);
  return results;
}