Files
serialize-js/types/index.d.ts

83 lines
2.4 KiB
TypeScript

import { sizedDataView, filledDataView, memcpy } from './mem'
import { limits } from './limits'
import { Type } from './Type'
import { Int } from './Int'
import { ConstString } from './ConstString'
import { ConstArray } from './ConstArray'
import { ConstDataView } from './ConstDataView'
import { Sequence } from './Sequence'
import { Struct } from './Struct'
export {
sizedDataView,
filledDataView,
memcpy,
limits,
Type,
Int,
ConstString,
ConstArray,
ConstDataView,
Sequence,
Struct,
}
export type SerializableType =
| BooleanConstructor
| NumberConstructor
| StringConstructor
| ArrayConstructor
| DataViewConstructor
| Type
export type Serializable = unknown
/**
* @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|DataView 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 {SerializableType[]} ...types 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 {SerializableType[]} ...types primary and inner types. eg: Array, Number
* @returns {number}
*/
export function sizeofHead(...types: SerializableType[]): number
/**
* @param {Serializable} obj to check
* @param {SerializableType[]} ...types primary and inner types. eg: Array, Number
* @returns {number}
*/
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, String, DataView type (unknown sizeof)
*/
export function sizeof(...types: SerializableType[]): number
export function isSerializableType(type: unknown): boolean