/**
 * Alternative Serialization Formats (API-14)
 *
 * Pluggable serialization system supporting JSON, MessagePack, and CBOR.
 * Provides format negotiation, backward compatibility, and performance benchmarks.
 *
 * @module serialization
 */
import type { Result } from '@private.me/shared';
/**
 * Supported serialization formats.
 */
export type SerializationFormat = 'json' | 'msgpack' | 'cbor';
/**
 * Serialization options for format negotiation.
 */
export interface SerializationOptions {
    /**
     * Preferred format for serialization.
     * @default 'json'
     */
    format?: SerializationFormat;
    /**
     * List of acceptable formats for deserialization (in preference order).
     * Used for format negotiation with peers.
     * @default ['json', 'msgpack', 'cbor']
     */
    acceptFormats?: SerializationFormat[];
    /**
     * Enable pretty-printing for JSON format (debugging only).
     * @default false
     */
    pretty?: boolean;
    /**
     * Enable performance metrics collection.
     * @default false
     */
    collectMetrics?: boolean;
}
/**
 * Serialization result with format metadata.
 */
export interface SerializedData {
    /** Serialized bytes */
    readonly data: Uint8Array;
    /** Format used for serialization */
    readonly format: SerializationFormat;
    /** Size in bytes */
    readonly size: number;
    /** Content-Type header value */
    readonly contentType: string;
    /** Performance metrics (if collectMetrics enabled) */
    readonly metrics?: SerializationMetrics;
}
/**
 * Performance metrics for serialization operations.
 */
export interface SerializationMetrics {
    /** Serialization duration in milliseconds */
    readonly serializeDuration: number;
    /** Size in bytes */
    readonly size: number;
    /** Format used */
    readonly format: SerializationFormat;
    /** Timestamp */
    readonly timestamp: number;
}
/**
 * Deserialization result with format detection.
 */
export interface DeserializedData<T = unknown> {
    /** Deserialized value */
    readonly value: T;
    /** Detected format */
    readonly format: SerializationFormat;
    /** Performance metrics (if collectMetrics enabled) */
    readonly metrics?: SerializationMetrics;
}
/**
 * Error types for serialization operations.
 */
export type SerializationError = {
    code: 'UNSUPPORTED_FORMAT';
    format: string;
} | {
    code: 'SERIALIZATION_FAILED';
    reason: string;
    format: SerializationFormat;
} | {
    code: 'DESERIALIZATION_FAILED';
    reason: string;
} | {
    code: 'FORMAT_DETECTION_FAILED';
    reason: string;
} | {
    code: 'INVALID_DATA';
    reason: string;
};
/**
 * Serializer interface for pluggable format implementations.
 */
export interface Serializer {
    /** Format identifier */
    readonly format: SerializationFormat;
    /** Content-Type header value */
    readonly contentType: string;
    /** Serialize value to bytes */
    serialize(value: unknown, options?: SerializationOptions): Result<Uint8Array, SerializationError>;
    /** Deserialize bytes to value */
    deserialize<T = unknown>(data: Uint8Array): Result<T, SerializationError>;
    /** Detect if data is in this format */
    detect(data: Uint8Array): boolean;
}
declare class MessagePackSerializer implements Serializer {
    readonly format: SerializationFormat;
    readonly contentType = "application/msgpack";
    serialize(value: unknown, _options?: SerializationOptions): Result<Uint8Array, SerializationError>;
    deserialize<T = unknown>(data: Uint8Array): Result<T, SerializationError>;
    detect(data: Uint8Array): boolean;
    private encode;
    private encodeValue;
    private encodeNumber;
    private encodeString;
    private encodeBinary;
    private encodeArray;
    private encodeObject;
    private decode;
    private decodeValue;
    private decodeString;
    private decodeBinary;
    private decodeArray;
    private decodeMap;
    private readUint16;
    private readUint32;
    private readInt8;
    private readInt16;
    private readInt32;
    private readFloat32;
    private readFloat64;
}
export { MessagePackSerializer };
/**
 * Serialize a value using the specified format.
 *
 * @param value - Value to serialize
 * @param options - Serialization options
 * @returns Serialized data with metadata
 *
 * @example
 * ```typescript
 * const data = { message: 'Hello', timestamp: Date.now() };
 *
 * // JSON (default, human-readable)
 * const json = serialize(data);
 *
 * // MessagePack (compact binary)
 * const msgpack = serialize(data, { format: 'msgpack' });
 *
 * // CBOR (standard binary)
 * const cbor = serialize(data, { format: 'cbor' });
 *
 * console.log('JSON:', json.value.size, 'bytes');
 * console.log('MessagePack:', msgpack.value.size, 'bytes');
 * console.log('CBOR:', cbor.value.size, 'bytes');
 * ```
 */
export declare function serialize(value: unknown, options?: SerializationOptions): Result<SerializedData, SerializationError>;
/**
 * Deserialize bytes using format auto-detection or explicit format.
 *
 * @param data - Serialized bytes
 * @param options - Deserialization options
 * @returns Deserialized value with format metadata
 *
 * @example
 * ```typescript
 * // Auto-detect format
 * const result = deserialize(bytes);
 * if (result.ok) {
 *   console.log('Format:', result.value.format);
 *   console.log('Data:', result.value.value);
 * }
 *
 * // Explicit format (faster, skips detection)
 * const json = deserialize(bytes, { format: 'json' });
 * ```
 */
export declare function deserialize<T = unknown>(data: Uint8Array, options?: SerializationOptions): Result<DeserializedData<T>, SerializationError>;
/**
 * Detect serialization format from bytes.
 *
 * @param data - Serialized bytes
 * @returns Detected format
 *
 * @example
 * ```typescript
 * const format = detectFormat(bytes);
 * if (format.ok) {
 *   console.log('Detected format:', format.value); // 'json' | 'msgpack' | 'cbor'
 * }
 * ```
 */
export declare function detectFormat(data: Uint8Array): Result<SerializationFormat, SerializationError>;
/**
 * Negotiate format between client and server.
 *
 * @param clientFormats - Formats accepted by client (in preference order)
 * @param serverFormats - Formats supported by server
 * @returns Best matching format
 *
 * @example
 * ```typescript
 * const client = ['msgpack', 'cbor', 'json'];
 * const server = ['json', 'cbor'];
 * const format = negotiateFormat(client, server);
 * console.log(format.value); // 'cbor' (first match)
 * ```
 */
export declare function negotiateFormat(clientFormats: SerializationFormat[], serverFormats: SerializationFormat[]): Result<SerializationFormat, SerializationError>;
/**
 * Compare serialization performance across formats.
 *
 * @param value - Value to benchmark
 * @param formats - Formats to compare
 * @returns Performance comparison
 *
 * @example
 * ```typescript
 * const data = { message: 'Hello', items: [1, 2, 3, 4, 5] };
 * const comparison = compareFormats(data);
 *
 * if (comparison.ok) {
 *   for (const result of comparison.value) {
 *     console.log(`${result.format}: ${result.size} bytes, ${result.duration}ms`);
 *   }
 * }
 * ```
 */
export declare function compareFormats(value: unknown, formats?: SerializationFormat[]): Result<Array<{
    format: SerializationFormat;
    size: number;
    duration: number;
}>, SerializationError>;
/**
 * Get Content-Type header for a serialization format.
 *
 * @param format - Serialization format
 * @returns Content-Type header value
 *
 * @example
 * ```typescript
 * const contentType = getContentType('msgpack');
 * console.log(contentType); // 'application/msgpack'
 * ```
 */
export declare function getContentType(format: SerializationFormat): string;
/**
 * Parse Content-Type header to serialization format.
 *
 * @param contentType - Content-Type header value
 * @returns Serialization format or undefined
 *
 * @example
 * ```typescript
 * const format = parseContentType('application/json');
 * console.log(format); // 'json'
 *
 * const format2 = parseContentType('application/msgpack');
 * console.log(format2); // 'msgpack'
 * ```
 */
export declare function parseContentType(contentType: string): SerializationFormat | undefined;
