/** * @license * Copyright 2022-2026 Matter.js Authors * SPDX-License-Identifier: Apache-2.0 */ import { Bytes, Merge } from "@matter/general"; import { LengthConstraints } from "./TlvArray.js"; import { TlvTag, TlvType, TlvTypeLength } from "./TlvCodec.js"; import { TlvEncodingOptions, TlvReader, TlvSchema, TlvWriter } from "./TlvSchema.js"; export interface FieldType { id: number; schema: TlvSchema; optional?: boolean; repeated?: boolean; fallback?: T; } export interface RepeatedFieldType extends FieldType { repeated: true; minLength?: number; maxLength?: number; } export interface OptionalFieldType extends FieldType { optional: true; } export interface OptionalRepeatedFieldType extends OptionalFieldType { repeated: true; maxLength?: number; } export type TlvFields = { [field: string]: FieldType; }; type MandatoryFieldNames = { [K in keyof F]: F[K] extends OptionalFieldType ? never : K; }[keyof F]; type OptionalFieldNames = { [K in keyof F]: F[K] extends OptionalFieldType ? K : never; }[keyof F]; type TypeFromField> = F extends FieldType ? T : never; type TypeForMandatoryFields = { [K in MF]: TypeFromField; }; type TypeForOptionalFields = { [K in MF]?: TypeFromField; }; export type TypeFromFields = Merge>, TypeForOptionalFields>>; /** * Schema to encode an object in TLV. * * @see {@link MatterSpecification.v10.Core} § A.5.1 and § A.11.4 */ export declare class ObjectSchema extends TlvSchema> { #private; private readonly fieldDefinitions; private readonly type; private readonly allowProtocolSpecificTags; /** When true, list encoding follows caller property order instead of schema order. See {@link TlvTaggedListPreservingOrder}. */ private readonly preserveDataOrdering; readonly isFabricScoped: boolean; private readonly fieldById; constructor(fieldDefinitions: F, type?: TlvType.Structure | TlvType.List, allowProtocolSpecificTags?: boolean, /** When true, list encoding follows caller property order instead of schema order. See {@link TlvTaggedListPreservingOrder}. */ preserveDataOrdering?: boolean); /** @deprecated Part of old ClusterType() compat layer. */ get element(): TlvSchema.Element; encodeTlvInternal(writer: TlvWriter, value: TypeFromFields, tag?: TlvTag, options?: TlvEncodingOptions): void; decodeTlvInternalValue(reader: TlvReader, typeLength: TlvTypeLength): TypeFromFields; validate(value: TypeFromFields): void; injectField(value: TypeFromFields, fieldId: number, fieldValue: any, injectChecker: (fieldValue: any) => boolean): TypeFromFields; removeField(value: TypeFromFields, fieldId: number, removeChecker: (fieldValue: any) => boolean): TypeFromFields; } /** Object TLV schema. */ export declare const TlvObject: (fields: F) => ObjectSchema; export declare class ObjectSchemaWithMaxSize extends ObjectSchema { protected readonly maxSize: number; constructor(fieldDefinitions: F, maxSize: number, type?: TlvType.Structure | TlvType.List, allowProtocolSpecificTags?: boolean); encode(value: TypeFromFields): Bytes; } export declare const TlvObjectWithMaxSize: (fields: F, maxSize: number) => ObjectSchemaWithMaxSize; /** * List TLV schema with all tagged entries. Members are emitted in schema definition order on encode. * List entries that can appear multiple times can be defined using TlvRepeatedField/TlvOptionalRepeatedField and are * represented as Arrays. * * For lists whose wire order must reproduce caller-supplied order, use {@link TlvTaggedListPreservingOrder}. * * TODO: We represent Tlv Lists right now as named object properties. This formally does not match the spec, which * defines a list as a sequence of TLV elements with optional tag where the order matters. That's ok for now * (also with the help of "Repeated Fields") because it not makes any real difference for now for the current * existing data structures. We need to change once this changes. */ export declare const TlvTaggedList: (fields: F, allowProtocolSpecificTags?: boolean) => ObjectSchema; /** * Variant of {@link TlvTaggedList} that preserves caller-supplied member order on encode. Use only when wire-position * is application data that must round-trip bit-identically — e.g. operational-certificate subject/issuer/extensions * sub-lists, whose signed bytes depend on original member order. */ export declare const TlvTaggedListPreservingOrder: (fields: F, allowProtocolSpecificTags?: boolean) => ObjectSchema; /** * Object TLV mandatory field. Optionally provide a fallback value to initialize the field value when devices omit * providing a value against the specifications or in special use cases. Make sure to use a value that is an equivalent * to the value being empty. */ export declare const TlvField: (id: number, schema: TlvSchema, fallback?: T) => FieldType; /** Object TLV optional field. */ export declare const TlvOptionalField: (id: number, schema: TlvSchema) => OptionalFieldType; /** * Object TLV mandatory field that can exist repeated in a TLV List structure. The order is preserved on encoding and * decoding. */ export declare const TlvRepeatedField: (id: number, schema: TlvSchema, lengthOptions?: LengthConstraints) => RepeatedFieldType; /** * Object TLV optional field that can exist repeated in a TLV List structure. The order is preserved on encoding and * decoding. */ export declare const TlvOptionalRepeatedField: (id: number, schema: TlvSchema, lengthOptions?: { maxLength: number; }) => OptionalRepeatedFieldType; export {}; //# sourceMappingURL=TlvObject.d.ts.map