/** * The `Helper` module definition defines different decorator that combines * decorators from differents categories. * * @module Helper */ import { RelationParameters } from './primitive.ts'; import { Context, DecoratorType } from '../types.ts'; import { ControllerOptions } from './controller.ts'; import { NumberOrRecursiveKey } from './common.ts'; /** * `@Char` defines the decorated as an unsigned 8 bit integer and transform * each of those read integer into a character by applying ascii encoding. * * @typeParam This The type of the class the decorator is applied to. * @typeParam Value The type of the decorated property. * * @category Decorators */ export declare function Char(_: undefined, context: Context): void; /** * `@Ascii` defines the decorated as an unsigned 8 bit integer and transform * each of those read integer into a character by applying ascii encoding * (see {@link Char}). * After the controller (if any) has been executed the resulting value will * be joined into a string. * * @remarks * * This function differ from {@link Char} by joining the resulting value after * the controller has been executed into a string. * During the write phase the string will be splitted into an array. * * @typeParam This The type of the class the decorator is applied to. * @typeParam Value The type of the decorated property. * * @category Decorators */ export declare function Ascii(_: undefined, context: Context): void; /** * `@NullTerminated` decorator is made to be used with the `@Utf{8,16,32}` * decorators to read the string until a `0` is encountered. * Because decoding an array of utf{8,16,32} character will drop this `0` * this decorator make sure to add it again to the array when writing an utf * encoded string. * * @example * * ```typescript * class Protocol { * @Utf8 * @NullTerminated // Should be closer to the property than `Utf8` * name: string * * @Until(EOF) * @Utf16 * @NullTerminated * name: string[] // Create an array of null terminated utf16 strings * } * ``` * * @remarks * * You can't use this decorator with `@Ascii` decorator. Use * `@NullTerminatedString` instead. * * @category Decorators */ export declare function NullTerminated(_: undefined, context: Context): void; /** * `@NullTerminatedString` decorator reads a string from a binary stream until * the null-terminator (`\0`) character is encountered and exclude that * character from the final value. * * @example * * In the following example, the `@NullTerminatedString` decorator is used * in conjunction of the `@Until` decorator to read Null terminated strings * until the end of the file. * * ```typescript * class Protocol { * @Until(EOF) * @NullTerminatedString() * data: string[] * } * ``` * * @typeParam This The type of the class the decorator is applied to. * @typeParam Value The type of the decorated property. * * @param {Partial} [opt] Optional configuration. * @returns {DecoratorType} The property decorator function. * * @category Decorators */ export declare function NullTerminatedString(opt?: Partial): DecoratorType; /** * `@Utf8` defines the decorated property as an unsigned 8 bit integer encoded * as an utf-8 string. * * @example * * Here in the following example the `@Until` controller is associated with the * the `@Utf8` decorator. * * ```typescript * class Protocol { * @Until(EOF) * @Utf8 * foo: string * } * ``` * * The typical use-case would be to have a generic space of a pre-defined size with a * an utf encoded string. * * ```typescript * class Protocol { * @Size(64) * @Utf8 * foo: string * } * ``` * * @remarks * * This decorator is supposed to be used in conjunction of a controller. * * @typeParam This The type of the class the decorator is applied to. * @typeParam Value The type of the decorated property. * * @category Decorators */ export declare function Utf8(_: undefined, context: Context): void; /** * `@Utf16` defines the decorated property as an unsigned 16 bit integer encoded * as an utf-16 string. * * @example * * The typical use-case would be to have a generic space of a pre-defined size with a * an utf encoded string. * * ```typescript * class Protocol { * @Size(64) * @Utf16 * foo: string * } * ``` * * @remarks * * This decorator is supposed to be used in conjunction of a controller. * * @typeParam This The type of the class the decorator is applied to. * @typeParam Value The type of the decorated property. * * @category Decorators */ export declare function Utf16(_: undefined, context: Context): void; /** * `@Utf32` defines the decorated property as an unsigned 32 bit integer encoded * as an utf-32 string. * * @example * * The typical use-case would be to have a generic space of a pre-defined size with a * an utf encoded string. * * ```typescript * class Protocol { * @Size(64) * @Utf32 * foo: string * } * ``` * * @remarks * * This decorator is supposed to be used in conjunction of a controller. * * @typeParam This The type of the class the decorator is applied to. * @typeParam Value The type of the decorated property. * * @category Decorators */ export declare function Utf32(_: undefined, context: Context): void; /** * `@Flatten` decorator defines a relation and extract a single property from * the nested relation. * The decorator 'flatten' the structure during the reading phase and * reconstruct it during the writing phase. * * @example * * In the following example `@Flatten` is used to create array of string while * also applying operation to that inner in string in the `ProtocolString` * definition. * The `ProtocolString` parse null terminated strings but ensure the size of * a string block is always of 64 bytes. * * ```typescript * class ProtocolString { * @EnsureSize(64) * @NullTerminatedString() * data: string * } * * class Protocol { * @Until(EOF) * @Flatten(ProtocolString, 'data') * strings: string[] * } * ``` * * @typeParam This The type of the class the decorator is applied to. * @typeParam Relation The relation class type. * @typeParam Value The type of the decorated property. * * @param {new () => Relation} relation The relation type that contains the * nested property. * @param {keyof Relation} property The property inside the relation that * should be extracted when reading and re-encapsulated when writing. * @returns {DecoratorType} The property decorator function. * * @category Decorators */ export declare function Flatten(relation: new (args?: any) => Relation, property: keyof Relation, args?: RelationParameters): DecoratorType; /** * `@Matrix` decorator creates a two-dimensional array based on the specified * width and height arguments. * * @typeParam This The type of the class the decorator is applied to. * @typeParam Value The type of the decorated property. * * @param {NumberOrRecursiveKey} width The width of the matrix, which can be a numeric value or a computed key. * @param {NumberOrRecursiveKey} height The height of the matrix, determining the number of elements. * @param {number} padding Optional padding value applied to each row of the matrix. * @returns {DecoratorType} The property decorator function. * * @category Decorators */ export declare function Matrix(width: NumberOrRecursiveKey, height: NumberOrRecursiveKey, padding?: number): DecoratorType;