* Allocate a byte array for a string and return the offset of the byte array. * @param data The string to allocate. * @returns The offset of the byte array.
(data: string)
| 444 | * @returns The offset of the byte array. |
| 445 | */ |
| 446 | allocByteArrayForString(data: string): PtrOffset { |
| 447 | const dataUint8: Uint8Array = StringToUint8Array(data); |
| 448 | // Note: size of size_t equals sizeof ptr. |
| 449 | const headerOffset = this.allocRawBytes(this.memory.sizeofPtr() * 2); |
| 450 | const dataOffset = this.allocRawBytes(dataUint8.length); |
| 451 | this.storeUSize(headerOffset + this.memory.sizeofPtr(), data.length); |
| 452 | this.storeRawBytes(dataOffset, dataUint8); |
| 453 | this.addressToSetTargetValue.push([headerOffset, dataOffset]); |
| 454 | return headerOffset; |
| 455 | } |
| 456 | /** |
| 457 | * Allocate then set C-String pointer to the offset. |
| 458 | * This function will call into allocBytes to allocate necessary data. |
no test coverage detected