UNPKG

diffusion

Version:

Diffusion JavaScript client

81 lines (80 loc) 3.39 kB
"use strict"; /** * @module Services.FetchJMXValues */ var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.JMXFetchResponseSerialiser = exports.JMXFetchResponseSerialiserClass = void 0; var Codec = require("./../../io/codec"); var serialiser_1 = require("./../../serialisers/serialiser"); var error_reason_serialiser_1 = require("../error-reason-serialiser"); var mbean_values_serialiser_1 = require("./mbean-values-serialiser"); /** * Serialiser for {@link JMXFetchResponse} */ var JMXFetchResponseSerialiserClass = /** @class */ (function (_super) { __extends(JMXFetchResponseSerialiserClass, _super); function JMXFetchResponseSerialiserClass() { return _super !== null && _super.apply(this, arguments) || this; } /** * Read a {@link JMXFetchResponse} from the stream * * @param bis the input stream * @return the {@link JMXFetchResponse} that was read */ JMXFetchResponseSerialiserClass.prototype.read = function (bis) { return Codec.readDictionary(bis, this.readWrapper.bind(this)); }; /** * Write a {@link JMXFetchResponse} to the stream * * @param bos the output stream * @param value the {@link JMXFetchResponse} to be written */ JMXFetchResponseSerialiserClass.prototype.write = function (bos, value) { Codec.writeDictionary(bos, value, this.writeWrapper.bind(this)); }; JMXFetchResponseSerialiserClass.prototype.readWrapper = function (bis) { switch (Codec.readByte(bis)) { case 0: return mbean_values_serialiser_1.MBeanValuesSerialiser.read(bis); default: case 1: return error_reason_serialiser_1.ErrorReasonSerialiser.read(bis); } }; JMXFetchResponseSerialiserClass.prototype.writeWrapper = function (bos, value) { if (this.isErrorReason(value)) { Codec.writeByte(bos, 1); error_reason_serialiser_1.ErrorReasonSerialiser.write(bos, value); } else { Codec.writeByte(bos, 0); mbean_values_serialiser_1.MBeanValuesSerialiser.write(bos, value); } }; JMXFetchResponseSerialiserClass.prototype.isErrorReason = function (input) { return 'reason' in input; }; return JMXFetchResponseSerialiserClass; }(serialiser_1.AbstractSerialiser)); exports.JMXFetchResponseSerialiserClass = JMXFetchResponseSerialiserClass; /** * The singleton */ // eslint-disable-next-line @typescript-eslint/naming-convention exports.JMXFetchResponseSerialiser = new JMXFetchResponseSerialiserClass();