feat(DataView, ConstDataView)

This commit is contained in:
2025-08-04 15:33:12 +03:00
parent 72f6102f0c
commit 504bfbeae8
11 changed files with 179 additions and 37 deletions

8
types/ConstDataView.d.ts vendored Normal file
View File

@ -0,0 +1,8 @@
import { Type } from ".";
/**
* constructs type of data view with constant byte size
* @param {number} byte_size max byte size
* @returns {Type}
*/
export function ConstDataView(byte_size: number): Type;

11
types/index.d.ts vendored
View File

@ -3,19 +3,20 @@ import { limits } from "./limits";
import { Type } from "./Type"
import { ConstString } from "./ConstString"
import { ConstArray } from "./ConstArray";
import { ConstDataView } from "./ConstDataView";
import { Struct } from "./Struct";
export { memcpy, limits, Type, ConstString, ConstArray, Struct }
export { memcpy, limits, Type, ConstString, ConstArray, ConstDataView, Struct }
export type SerializableType = NumberConstructor | StringConstructor | ArrayConstructor | Type
export type Serializable = number | string | array
export type SerializableType = NumberConstructor | StringConstructor | ArrayConstructor | DataViewConstructor | Type
export type Serializable = number | string | array | DataView
/**
* @param {DataView} dv destination memory
* @param {Serializable} src source object
* @param {SerializableType[]} ...types primary and inner types. eg: Array, Number
* @throws {Error} if too small buffer
* @throws {Error} if array|string size is higher than limits.u32.MAX_VALUE
* @throws {Error} if array|string|DataView size is higher than limits.u32.MAX_VALUE
*/
export function serialize(dv: DataView, src: Serializable, ...types: SerializableType[]): void;
@ -66,6 +67,6 @@ export function sizeof(obj: Serializable, ...types: SerializableType[]): number;
/**
* @param {SerializableType[]} ...types primary and inner types. eg: Array, Number
* @returns {number}
* @throws {Error} if passed Array or String type (unknown sizeof)
* @throws {Error} if passed Array, String, DataView type (unknown sizeof)
*/
export function sizeof(...types: SerializableType[]): number;