UNPKG

diffusion

Version:

Diffusion JavaScript client

85 lines (84 loc) 3.4 kB
"use strict"; 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.MetricsResultSerialiser = exports.MetricsResultSerialiserClass = void 0; var metrics_1 = require("./../../../features/metrics"); var Codec = require("./../../io/codec"); var BEES = require("./../../serialisers/byte-encoded-enum-serialiser"); var serialiser_1 = require("./../../serialisers/serialiser"); var metrics_result_1 = require("./metrics-result"); function readDouble(bis) { var long = Codec.readInt64(bis); var dataView = new DataView(new ArrayBuffer(8)); dataView.setUint32(0, long.getLowBits(), true); dataView.setUint32(4, long.getHighBits(), true); return dataView.getFloat64(0, true); } function readMetricSample(bis) { var value = readDouble(bis); var timestamp = Codec.readInt64(bis); var name = Codec.readString(bis); var labelNames = Codec.readCollection(bis, Codec.readString); var labelValues = Codec.readCollection(bis, Codec.readString); return { name: name, labelNames: labelNames, labelValues: labelValues, timestamp: timestamp.equals(-1) ? undefined : timestamp, value: value }; } function readMetricSampleCollection(bis) { var name = Codec.readString(bis); var unit = Codec.readString(bis); var metricType = BEES.read(bis, metrics_1.MetricType); var samples = Codec.readCollection(bis, readMetricSample); return { name: name, unit: unit, type: metricType, samples: samples }; } function readMetricSampleCollections(bis) { return Codec.readCollection(bis, readMetricSampleCollection); } /** * Serialiser for metric results. */ var MetricsResultSerialiserClass = /** @class */ (function (_super) { __extends(MetricsResultSerialiserClass, _super); function MetricsResultSerialiserClass() { return _super !== null && _super.apply(this, arguments) || this; } /** * Read a metric result from the stream * * @param bis the input stream * @return the metrics result that was read */ MetricsResultSerialiserClass.prototype.read = function (bis) { var sampleCollections = Codec.readDictionary(bis, readMetricSampleCollections); return new metrics_result_1.MetricsResultImpl(sampleCollections); }; return MetricsResultSerialiserClass; }(serialiser_1.AbstractSerialiser)); exports.MetricsResultSerialiserClass = MetricsResultSerialiserClass; /** * The singleton */ // eslint-disable-next-line @typescript-eslint/naming-convention exports.MetricsResultSerialiser = new MetricsResultSerialiserClass();