Platform-specific TypeScript declarations for NativeScript for accessing native objects
84
Build a utility that performs low-level memory operations on binary data buffers using pointer arithmetic. The utility should allocate native memory buffers, perform byte-level operations using pointers, and manage memory safely.
Create a module that provides the following functionality:
Buffer Allocation: Allocate a native memory buffer of a specified size in bytes and return an object containing the pointer and size information.
Byte Writing: Write a sequence of byte values to a buffer starting at a given offset. The function should use pointer arithmetic to navigate to the correct memory location.
Byte Reading: Read a sequence of bytes from a buffer starting at a given offset and return them as a JavaScript array. Use pointer arithmetic to access the correct memory locations.
Buffer Copy: Copy data from one buffer to another using pointer arithmetic. The function should take source and destination buffers with their offsets and copy a specified number of bytes.
/**
* Information about an allocated buffer
*/
export interface BufferInfo {
pointer: any; // interop.AdoptedPointer
size: number;
}
/**
* Allocate a native memory buffer
* @param size - Size in bytes to allocate
* @returns Buffer information with pointer and size
*/
export function allocateBuffer(size: number): BufferInfo;
/**
* Write bytes to a buffer at the specified offset
* @param buffer - Buffer information
* @param offset - Byte offset to start writing
* @param bytes - Array of byte values (0-255) to write
*/
export function writeBytes(buffer: BufferInfo, offset: number, bytes: number[]): void;
/**
* Read bytes from a buffer at the specified offset
* @param buffer - Buffer information
* @param offset - Byte offset to start reading
* @param count - Number of bytes to read
* @returns Array of byte values read
*/
export function readBytes(buffer: BufferInfo, offset: number, count: number): number[];
/**
* Copy bytes from source buffer to destination buffer
* @param srcBuffer - Source buffer information
* @param srcOffset - Offset in source buffer
* @param dstBuffer - Destination buffer information
* @param dstOffset - Offset in destination buffer
* @param count - Number of bytes to copy
*/
export function copyBytes(
srcBuffer: BufferInfo,
srcOffset: number,
dstBuffer: BufferInfo,
dstOffset: number,
count: number
): void;@generates
Provides native interop capabilities for memory allocation and pointer operations.
Install with Tessl CLI
npx tessl i tessl/npm-tns-platform-declarationsevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10