@iprokit/service
Version:
Powering distributed systems with simplicity and speed.
90 lines • 2.14 kB
JavaScript
"use strict";
/**
* @iProKit/Service
* Copyright (c) 2019-2025 Rutvik Katuri / iProTechs
* SPDX-License-Identifier: Apache-2.0
*/
Object.defineProperty(exports, "__esModule", { value: true });
/**
* 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.
*/
class Frame {
/**
* Type of the frame.
*/
type;
/**
* Payload of the frame.
*/
payload;
/**
* Creates an instance of `Frame`.
*
* @param type type of the frame.
* @param payload optional payload of the frame.
*/
constructor(type, payload) {
this.type = type;
this.payload = payload;
}
//////////////////////////////
//////// Gets/Sets
//////////////////////////////
/**
* Byte length of the frame.
*/
get length() {
return Frame.HEAD_BYTES + (this.payload?.length ?? 0);
}
//////////////////////////////
//////// Type Definitions
//////////////////////////////
/**
* Indicates RFI frame.
*/
static RFI = 1;
/**
* Indicates data frame.
*/
static DATA = 2;
/**
* Indicates signal frame.
*/
static SIGNAL = 3;
/**
* Indicates end frame.
*/
static END = 4;
//////////////////////////////
//////// Segment Definitions
//////////////////////////////
/**
* Total frame size in bytes.
*/
static FRAME_BYTES = 16384;
/**
* Size of length segment in bytes.
*/
static LENGTH_BYTES = 2;
/**
* Size of type segment in bytes.
*/
static TYPE_BYTES = 1;
/**
* Total head size in bytes.
*/
static HEAD_BYTES = Frame.LENGTH_BYTES + Frame.TYPE_BYTES;
/**
* Size of payload segment in bytes.
*/
static PAYLOAD_BYTES = Frame.FRAME_BYTES - Frame.HEAD_BYTES;
}
exports.default = Frame;
//# sourceMappingURL=frame.js.map