/** * The nbt module provides nbt {@link serialize} and {@link deserialize} functions. * * @packageDocumentation * @module @xmcl/nbt */ import { ByteBuffer } from '@xmcl/bytebuffer'; type Constructor = new (...args: any) => T; export declare const kNBTPrototype: unique symbol; export declare const kNBTConstructor: unique symbol; export type TagType = TagTypePrimitive | typeof TagType.List | typeof TagType.Compound; export type TagTypePrimitive = typeof TagType.End | typeof TagType.Byte | typeof TagType.Short | typeof TagType.Int | typeof TagType.Long | typeof TagType.Float | typeof TagType.Double | typeof TagType.ByteArray | typeof TagType.String | typeof TagType.IntArray | typeof TagType.LongArray; /** * Annotate the type of a field */ export declare function TagType(type: TagType | Constructor | Schema): (clzPrototype: any, key: string) => void; /** * Get NBT schema for this object or a class. * * If the param is a object, any modifications on this prototype will only affact this object. * If the param is a class, any modifications on this prototype will affact all object under this class * * @param object The object or class */ export declare function getPrototypeOf(object: object | ((...p: any[]) => any)): NBTPrototype | undefined; /** * Set and change the NBT prototype of this object or class * @param object A object or a class function * @param nbtPrototype The nbt prototype */ export declare function setPrototypeOf(object: object | ((...p: any[]) => any), nbtPrototype: NBTPrototype): void; export declare namespace TagType { const End: 0; const Byte: 1; const Short: 2; const Int: 3; const Long: 4; const Float: 5; const Double: 6; const ByteArray: 7; const String: 8; const List: 9; const Compound: 10; const IntArray: 11; const LongArray: 12; function getName(tagType: TagType): string; } export type Schema = ListSchema | CompoundSchema | Constructor; export type ListSchema = [TagType | Schema]; export type CompoundSchema = { [key: string]: TagType | Schema; }; export interface NBTPrototype extends CompoundSchema { [kNBTConstructor]: () => any; } export interface TagCoder { write(buf: ByteBuffer, context: ReadContext): any; read(buf: ByteBuffer, value: any, context: WriteContext): void; } export interface SerializationOption { compressed?: true | 'deflate' | 'gzip'; /** * IO override for serialization */ io?: { [tagType: number]: TagCoder; }; /** * Used for serialize function. Assign the filename for it. */ filename?: string; } export interface DeserializationOption { compressed?: true | 'deflate' | 'gzip'; /** * IO override for serialization */ io?: { [tagType: number]: TagCoder; }; type?: Constructor; } /** * Serialzie an nbt typed json object into NBT binary * @param object The json * @param compressed Should we compress it */ export declare function serialize(object: object, option?: SerializationOption): Promise; /** * Deserialize the nbt binary into json * @param fileData The nbt binary */ export declare function deserialize(fileData: Uint8Array, option?: DeserializationOption): Promise; /** * Serialzie an nbt typed json object into NBT binary * @param object The json */ export declare function serializeSync(object: object, option?: SerializationOption): Uint8Array; /** * Deserialize the nbt binary into json * @param fileData The nbt binary * @param compressed Should we compress it */ export declare function deserializeSync(fileData: Uint8Array, option?: DeserializationOption): T; export declare class ReadContext { #private; schema: Schema | undefined; tagType: TagType; inspect: Schema | undefined; constructor(schema: Schema | undefined, tagType: TagType); get decoder(): TextDecoder; fork(schemaOrTagType: TagType | Schema): ReadContext; } export declare class WriteContext { #private; readonly schema: Schema | undefined; readonly tagType: TagType; constructor(schema: Schema | undefined, tagType: TagType); get encoder(): TextEncoder; fork(schemaOrTagType: TagType | Schema): WriteContext; } export {}; //# sourceMappingURL=index.d.ts.map