@se-puu/qpack
Version:
Quick serializer and de-serializer
148 lines (147 loc) • 5.07 kB
TypeScript
import { AsyncEncoderOption, EncoderOption } from "./encoder-option";
import { Encodeable, EncodeableBinary } from "./handler-map";
import { ExtRegistry } from "../lib/ext-registry";
export declare class QAsyncEncoder {
onData: AsyncEncoderOption["onData"];
onCompleted: AsyncEncoderOption["onCompleted"];
onError: AsyncEncoderOption["onError"];
bufferSize: number;
onDataNeeded: QAsyncEncoder["__onDataNeeded"];
static create(option: AsyncEncoderOption): QAsyncEncoder;
encode(data: unknown): Uint8Array;
__onDataNeeded(): Uint8Array;
}
/**
* Quick Encoder class
* @class
* @classdesc Encoder class
* @since 1.0.0
*/
export declare class QEncoder {
#private;
__encoder: import("util").TextEncoder;
__buffer: Uint8Array;
__bufferOffset: number;
__view: DataView;
__extRegistry: ExtRegistry;
__onRelease?: EncoderOption["onRelease"];
__onExpand?: EncoderOption["onExpand"];
__initSize: number;
static create(option?: EncoderOption): QEncoder;
/**
* change extension handler
* @param handler new extension handler
* @since 1.0.0
*/
changeExtRegistry(handler: ExtRegistry): void;
/**
* expand buffer
* @param minSize minimum required size to expand
* @since 1.0.0
*/
__expand(minSize?: number): void;
/**
* recycle buffer no longer needed
* @since 1.0.0
*/
reset(): void;
/**
* prepare buffer from new buffer or recycled buffer
* @since 1.0.0
*/
private allocate;
/**
* encode data synchronously by exporting into a new buffer as return value
* @param data data to encode
* @returns {Uint8Array|undefined} encoded data
* @since 1.0.0
*/
encode(data: Encodeable): Uint8Array | undefined;
/**
* encode data synchronously and return length of encoded data.
* @param data data to encode
* @returns {number} length of encoded data
* @since 1.0.0
*/
encodeOnly(data: Encodeable): number;
export(): Uint8Array | undefined;
/**
* export encoded data into target buffer
* @param target target buffer
* @returns {boolean} true if encoding is successful
* @since 1.0.0
*/
exportInto(target: Uint8Array): boolean;
/**
* get length of encoded data
* @returns {number} length of encoded data
* @since 1.0.0
*/
get length(): number;
/**
* write data synchronously some data into current encoded data inside extension encoder.
* @param data data to encode
* @returns {boolean} true if encoding is successful
* @since 1.0.0
*/
write: (data: Encodeable) => boolean;
/**
* write array synchronously into current encoded data inside extension encoder.
* @param data array to encode
* @returns {boolean} true if encoding is successful
*/
writeArray: (data: Encodeable[]) => boolean;
/**
* write bigint synchronously into current encoded data inside extension encoder.
* @param data bigint to encode
* @returns {boolean} true if encoding is successful
*/
writeBigInt: (data: bigint) => boolean;
/**
* write binary data synchronously into current encoded data inside extension encoder.
* @param data binary data to encode
* @returns {boolean} true if encoding is successful
*/
writeBinary: (data: EncodeableBinary) => boolean;
/**
* write boolean synchronously into current encoded data inside extension encoder.
* @param data boolean to encode
* @returns {boolean} true if encoding is successful
*/
writeBoolean: (data: boolean) => boolean;
/**
* write map synchronously into current encoded data inside extension encoder.
* @param data map to encode
* @returns {boolean} true if encoding is successful
*/
writeMap: (data: Map<unknown, unknown>) => boolean;
/**
* write null synchronously into current encoded data inside extension encoder.
* @returns {boolean} true if encoding is successful
*/
writeNull: () => boolean;
/**
* write number synchronously into current encoded data inside extension encoder.
* @param data number to encode
* @returns {boolean} true if encoding is successful
*/
writeNumber: (data: number) => boolean;
/**
* write object synchronously into current encoded data inside extension encoder.
* @param data object to encode
* @returns {boolean} true if encoding is successful
*/
writeObject: (data: object) => boolean;
/**
* write string synchronously into current encoded data inside extension encoder.
* @param data string to encode
* @returns {boolean} true if encoding is successful
*/
writeString: (data: string) => boolean;
/**
* write timestamp synchronously into current encoded data inside extension encoder.
* @param data timestamp to encode
* @returns {boolean} true if encoding is successful
*/
writeTimestamp: (data: Date) => boolean;
}