UNPKG

mastercache

Version:

Multi-tier cache module for Node.js. Redis, Upstash, CloudfareKV, File, in-memory and others drivers

42 lines (39 loc) 1.43 kB
import { TransportEncoder } from '@boringnode/bus/types/main'; import { CacheBusMessageType } from '../../types/bus.cjs'; import '../../types/helpers.cjs'; import 'typescript-log'; /** * A Binary Encoder that encodes and decodes CacheBusMessage * * The encoding is as follows: * - The bus ID is encoded as a UTF8 string and directly appended to the resulting buffer. * Note that the length of the bus ID should be specified in the constructor. * * - The message type is encoded as a single byte, with 0x01 for 'Set' message, and 0x02 for a 'Delete' message * * - The keys are encoded as follows: * - A 4-byte big-endian integer representing the length of the key in bytes * - The key itself * * - These components are concatenated together in the order busId -> type -> keys * */ declare class BinaryEncoder implements TransportEncoder { #private; /** * We assume the bus ID is a string of length 24 by default. * Because this is the default length of a cuid */ constructor(busIdLength?: number); protected busMessageTypeToNum(type: CacheBusMessageType): number; protected numToBusMessageType(num: number): CacheBusMessageType; /** * Encode the given message into a Buffer */ encode(message: any): string | Buffer; /** * Decode the given Buffer into a CacheBusMessage */ decode(data: string | Buffer): any; } export { BinaryEncoder };