writeToSlot method

  1. @override
WasmStringPointer writeToSlot(
  1. int slot,
  2. String text, [
  3. int? bufferSize
])
override

Writes text into slot slot, reallocating if the current capacity is insufficient for the UTF-8 encoded length.

Always null-terminates the written string.

Implementation

@override
WasmStringPointer writeToSlot(int slot, String text, [int? bufferSize]) {
  final requiredBytes = Length(text, bufferSize);

  reallocSlotIfRequired(slot, requiredBytes);

  WasmMemory.stringToUTF8(text, stringSlots[slot].address, requiredBytes);
  return WasmStringPointer(stringSlots[slot].address);
}