/** * Binary Protocol Codec using MessagePack + Gzip Compression * * Provides highly efficient binary encoding/decoding for WebSocket messages. * Performance improvements over JSON: * - MessagePack: 60-70% size reduction * - MessagePack + Gzip: 85-95% size reduction * - 2-3x faster processing * - Better security (binary is not human-readable) * * Example: A 100KB JSON message becomes: * - MessagePack only: ~35KB (65% reduction) * - MessagePack + Gzip: ~8KB (92% reduction) */ import type { Downstream } from './down.ts'; import type { Upstream } from './up.ts'; /** * Binary encoding format */ export type BinaryFormat = 'msgpack' | 'json'; /** * Compression settings */ export declare const COMPRESSION_ENABLED = true; export declare const COMPRESSION_LEVEL = 6; /** * Binary codec for efficient message serialization */ export declare const BinaryCodec: { /** * Encode message to binary format (MessagePack + Gzip Compression) * * @param data - Message to encode * @returns Binary ArrayBuffer (compressed if enabled) */ encode(data: Upstream | Downstream): ArrayBuffer; /** * Decode binary message (Gzip + MessagePack) * * @param buffer - Binary data to decode (possibly compressed) * @returns Decoded message */ decode(buffer: ArrayBuffer | Uint8Array): Upstream | Downstream; /** * Check if data is binary format * * @param data - Data to check * @returns True if data is binary (ArrayBuffer or Uint8Array) */ isBinary(data: unknown): data is ArrayBuffer | Uint8Array | Blob; /** * Get message size in bytes * * @param data - Message to measure * @param format - Encoding format * @returns Size in bytes */ getSize(data: Upstream | Downstream, format?: BinaryFormat): number; /** * Compare JSON vs MessagePack vs Compressed sizes * * @param data - Message to compare * @returns Size comparison with compression stats */ compareSize(data: Upstream | Downstream): { json: number; msgpack: number; compressed: number; msgpackReduction: number; msgpackReductionPercent: string; totalReduction: number; totalReductionPercent: string; }; }; /** * Legacy JSON codec (for backward compatibility) */ export declare const JsonCodec: { /** * Encode message to JSON string */ encode(data: Upstream): string; /** * Decode JSON string */ decode(data: string): Downstream; /** * Check if data is JSON string */ isJson(data: unknown): data is string; }; /** * Protocol version constants */ export declare const PROTOCOL_SUPPORT: { /** Supports binary encoding */ readonly BINARY: number; /** Supports compression */ readonly COMPRESSION: number; /** Supports both */ readonly BINARY_COMPRESSED: number; }; /** * Check protocol capabilities */ export declare function supportsFeature(features: number, feature: number): boolean; //# sourceMappingURL=binary-codec.d.ts.map