feat(serialize, parse): Number, String, Array, ConstString, ConstArray
This commit is contained in:
67
types/index.d.ts
vendored
Normal file
67
types/index.d.ts
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
import { memcpy } from "./mem";
|
||||
import { limits } from "./limits";
|
||||
import { ConstString, ConstArray } from "./type";
|
||||
|
||||
export { memcpy, limits, ConstString, ConstArray }
|
||||
|
||||
import { Type } from "./type";
|
||||
|
||||
export type SerializableType = NumberConstructor | StringConstructor | ArrayConstructor | Type
|
||||
export type Serializable = number | string | array
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
export function serialize(dv: DataView, src: Serializable, ...types: SerializableType[]): void;
|
||||
|
||||
/**
|
||||
* @param {DataView} dv source memory
|
||||
* @param {SerializableType[]} ...types primary and inner types. eg: Array, Number
|
||||
* @returns {Serializable} parsed object
|
||||
*/
|
||||
export function parse(dv: DataView, ...types: SerializableType[]): Serializable;
|
||||
|
||||
/**
|
||||
* some types, like Array, String, has no fixed size. So in Structure they are stored as u32 offset, which points to their beginning
|
||||
* @param {Serializable} obj to check
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isHeadless(obj: Serializable): boolean;
|
||||
|
||||
/**
|
||||
* some types, like Array, String, has no fixed size. So in Structure they are stored as u32 offset, which points to their beginning
|
||||
* @param {SerializableType[]} ...args primary and inner types. eg: Array, Number
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isHeadless(...types: SerializableType[]): boolean;
|
||||
|
||||
/**
|
||||
* if obj has no fixed size, return 4 (sizeof u32 offset)
|
||||
* @param {Serializable} obj to check
|
||||
* @returns {number}
|
||||
*/
|
||||
export function sizeofHead(obj: Serializable): number;
|
||||
|
||||
/**
|
||||
* if obj has no fixed size, return 4 (sizeof u32 offset)
|
||||
* @param {SerializableType[]} ...args primary and inner types. eg: Array, Number
|
||||
* @returns {number}
|
||||
*/
|
||||
export function sizeofHead(...types: SerializableType[]): number;
|
||||
|
||||
/**
|
||||
* @param {Serializable} obj to check
|
||||
* @returns {number}
|
||||
*/
|
||||
export function sizeof(obj: Serializable): number;
|
||||
|
||||
/**
|
||||
* @param {SerializableType[]} ...args primary and inner types. eg: Array, Number
|
||||
* @returns {number}
|
||||
* @throws {Error} if passed Array or String type (unknown sizeof)
|
||||
*/
|
||||
export function sizeof(...types: SerializableType[]): number;
|
||||
Reference in New Issue
Block a user