UNPKG

proteus-js-client

Version:

Proteus JavaScript Client

59 lines (48 loc) 1.84 kB
/** * Copyright (c) 2017-present, Netifi Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * */ 'use strict'; /* eslint-disable consistent-return, no-bitwise */ Object.defineProperty(exports, "__esModule", { value: true }); exports.encodeFrameHeader = encodeFrameHeader; exports.getMajorVersion = getMajorVersion; exports.getMinorVersion = getMinorVersion; exports.getFrameType = getFrameType; /** * Protocol Version */ var MAJOR_VERSION = exports.MAJOR_VERSION = 0;var MINOR_VERSION = exports.MINOR_VERSION = 1; var MAJOR_VERSION_SIZE = exports.MAJOR_VERSION_SIZE = 2; var MINOR_VERSION_SIZE = exports.MINOR_VERSION_SIZE = 2; var FRAME_TYPE_SIZE = exports.FRAME_TYPE_SIZE = 2; var FRAME_HEADER_SIZE = exports.FRAME_HEADER_SIZE = MAJOR_VERSION_SIZE + MINOR_VERSION_SIZE + FRAME_TYPE_SIZE; function encodeFrameHeader(buffer, frame) { var offset = buffer.writeUInt16BE(frame.majorVersion || MAJOR_VERSION, 0); offset = buffer.writeUInt16BE(frame.minorVersion || MINOR_VERSION, offset); return buffer.writeUInt16BE(frame.type, offset); } function getMajorVersion(buffer) { return buffer.readUInt16BE(0); } function getMinorVersion(buffer) { return buffer.readUInt16BE(MAJOR_VERSION_SIZE); } function getFrameType(buffer) { return buffer.readUInt16BE(MAJOR_VERSION_SIZE + MINOR_VERSION_SIZE); }