format
This commit is contained in:
12
types/ConstArray.d.ts
vendored
12
types/ConstArray.d.ts
vendored
@ -1,8 +1,8 @@
|
||||
import { Type } from ".";
|
||||
import { Type } from '.'
|
||||
|
||||
/**
|
||||
* constructs type of array with constant byte size
|
||||
* @param {number} size number of items
|
||||
* @returns {Type}
|
||||
*/
|
||||
export function ConstArray(size: number): Type;
|
||||
* constructs type of array with constant byte size
|
||||
* @param {number} size number of items
|
||||
* @returns {Type}
|
||||
*/
|
||||
export function ConstArray(size: number): Type
|
||||
|
||||
12
types/ConstDataView.d.ts
vendored
12
types/ConstDataView.d.ts
vendored
@ -1,8 +1,8 @@
|
||||
import { Type } from ".";
|
||||
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;
|
||||
* 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
|
||||
|
||||
12
types/ConstString.d.ts
vendored
12
types/ConstString.d.ts
vendored
@ -1,8 +1,8 @@
|
||||
import { Type } from ".";
|
||||
import { Type } from '.'
|
||||
|
||||
/**
|
||||
* constructs type of utf8-string with constant byte size
|
||||
* @param {number} byte_size max utf8-encoded byte size
|
||||
* @returns {Type}
|
||||
*/
|
||||
export function ConstString(byte_size: number): Type;
|
||||
* constructs type of utf8-string with constant byte size
|
||||
* @param {number} byte_size max utf8-encoded byte size
|
||||
* @returns {Type}
|
||||
*/
|
||||
export function ConstString(byte_size: number): Type
|
||||
|
||||
4
types/Int.d.ts
vendored
4
types/Int.d.ts
vendored
@ -1,3 +1,3 @@
|
||||
import { Type } from ".";
|
||||
import { Type } from '.'
|
||||
|
||||
export function Int(bits: 8 | 16 | 32, sign: 'signed' | 'unsigned'): Type;
|
||||
export function Int(bits: 8 | 16 | 32, sign: 'signed' | 'unsigned'): Type
|
||||
|
||||
12
types/Struct.d.ts
vendored
12
types/Struct.d.ts
vendored
@ -1,7 +1,9 @@
|
||||
import { SerializableType, Type } from "."
|
||||
import { SerializableType, Type } from '.'
|
||||
|
||||
/**
|
||||
* constructs type of c-like structure. if field is headless, inside of structure will be stored u32 offset, outside of structure will be stored value of field
|
||||
* @returns {Type}
|
||||
*/
|
||||
export function Struct(type_obj: Record<string, SerializableType | SerializableType[]>): Type;
|
||||
* constructs type of c-like structure. if field is headless, inside of structure will be stored u32 offset, outside of structure will be stored value of field
|
||||
* @returns {Type}
|
||||
*/
|
||||
export function Struct(
|
||||
type_obj: Record<string, SerializableType | SerializableType[]>,
|
||||
): Type
|
||||
|
||||
105
types/index.d.ts
vendored
105
types/index.d.ts
vendored
@ -1,59 +1,78 @@
|
||||
import { 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 { Struct } from "./Struct";
|
||||
import { 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 { Struct } from './Struct'
|
||||
|
||||
export { memcpy, limits, Type, Int, ConstString, ConstArray, ConstDataView, Struct }
|
||||
export {
|
||||
memcpy,
|
||||
limits,
|
||||
Type,
|
||||
Int,
|
||||
ConstString,
|
||||
ConstArray,
|
||||
ConstDataView,
|
||||
Struct,
|
||||
}
|
||||
|
||||
export type SerializableType = BooleanConstructor | NumberConstructor | StringConstructor | ArrayConstructor | DataViewConstructor | Type
|
||||
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 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;
|
||||
* @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;
|
||||
* 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;
|
||||
* 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 {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;
|
||||
* @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;
|
||||
export function isSerializableType(type: unknown): boolean
|
||||
|
||||
2
types/limits.d.ts
vendored
2
types/limits.d.ts
vendored
@ -29,4 +29,4 @@ export const limits: {
|
||||
bool: IntLimit
|
||||
f32: FloatLimit
|
||||
f64: FloatLimit
|
||||
};
|
||||
}
|
||||
|
||||
6
types/mem.d.ts
vendored
6
types/mem.d.ts
vendored
@ -1,4 +1,4 @@
|
||||
/**
|
||||
* copies max possible number of bytes from src to dest (min of both sizes)
|
||||
*/
|
||||
export function memcpy(dest: DataView, src: DataView): void;
|
||||
* copies max possible number of bytes from src to dest (min of both sizes)
|
||||
*/
|
||||
export function memcpy(dest: DataView, src: DataView): void
|
||||
|
||||
Reference in New Issue
Block a user