UNPKG

diffusion

Version:

Diffusion JavaScript client

63 lines (62 loc) 2.2 kB
"use strict"; /** * @module Util.MessageEncoding * * @brief Utility functions for encoding messages */ Object.defineProperty(exports, "__esModule", { value: true }); exports.EncodingType = exports.MessageEncoding = void 0; /** * Bitmask for the message type */ var MESSAGE_TYPE_MASK = 0xA7D8C0; /** * A flag indicating a zlib compressed message */ var ZLIB_TYPE_FLAGS = 0x80; /** * The _message type flags_ allow a subset of MessageEncodings to be encoded * in the upper two bits of the message type byte. Only NO_ENCODING and * ZLIB are supported. */ var MessageEncoding = /** @class */ (function () { /** * Create a new message encoding object * * @param encodingByte the encoding byte * @param messageTypeFlags bit flags */ function MessageEncoding(encodingByte, messageTypeFlags) { this.encodingByte = encodingByte; this.messageTypeFlags = messageTypeFlags; } /** * Decode the message type from a byte combining the message type and flags. * * @param typeAndEncoding the encoding byte and message type flags * @return the message type flags */ MessageEncoding.extractMessageType = function (typeAndEncoding) { /* eslint-disable-next-line no-bitwise */ return typeAndEncoding & ~MESSAGE_TYPE_MASK; }; /** * Decode the message encoding from a byte combining the message type and flags. * * @param typeAndEncoding the encoding byte and message type flags * @return the message encoding */ MessageEncoding.extractMessageEncoding = function (typeAndEncoding) { /* eslint-disable-next-line no-bitwise */ var encoding = typeAndEncoding & MESSAGE_TYPE_MASK; /* tslint:disable-next-line:no-use-before-declare */ return (encoding === ZLIB_TYPE_FLAGS) ? exports.EncodingType.ZLIB : exports.EncodingType.NO_ENCODING; }; return MessageEncoding; }()); exports.MessageEncoding = MessageEncoding; /* eslint-disable-next-line @typescript-eslint/naming-convention */ exports.EncodingType = { NO_ENCODING: new MessageEncoding(0x00, 0x00), ZLIB: new MessageEncoding(0x12, 0x01) };