UNPKG

@iprokit/service

Version:

Powering distributed systems with simplicity and speed.

79 lines (78 loc) 1.91 kB
/** * @iProKit/Service * Copyright (c) 2019-2025 Rutvik Katuri / iProTechs * SPDX-License-Identifier: Apache-2.0 */ /// <reference types="node" /> /// <reference types="node" /> /** * SCP frames implement a stream-based frame delivery system. * * A frame consists of 3 segments: Length, Type, and Payload. * - HEAD: * - Length: Byte length of the frame, using 2 unsigned 16-bit bytes. * - Type: Frame type, using 1 int 8-bit byte. * - TAIL: * - Payload: Optional frame payload, using P raw bytes. */ export default class Frame { /** * Type of the frame. */ readonly type: Type; /** * Payload of the frame. */ readonly payload?: Buffer; /** * Creates an instance of `Frame`. * * @param type type of the frame. * @param payload optional payload of the frame. */ constructor(type: Type, payload?: Buffer); /** * Byte length of the frame. */ get length(): number; /** * Indicates RFI frame. */ static readonly RFI = 1; /** * Indicates data frame. */ static readonly DATA = 2; /** * Indicates signal frame. */ static readonly SIGNAL = 3; /** * Indicates end frame. */ static readonly END = 4; /** * Total frame size in bytes. */ static readonly FRAME_BYTES = 16384; /** * Size of length segment in bytes. */ static readonly LENGTH_BYTES = 2; /** * Size of type segment in bytes. */ static readonly TYPE_BYTES = 1; /** * Total head size in bytes. */ static readonly HEAD_BYTES: number; /** * Size of payload segment in bytes. */ static readonly PAYLOAD_BYTES: number; } /** * Type definitions for a `Frame`. */ export type Type = Pick<typeof Frame, 'RFI' | 'DATA' | 'SIGNAL' | 'END'>[keyof Pick<typeof Frame, 'RFI' | 'DATA' | 'SIGNAL' | 'END'>];