UNPKG

diffusion

Version:

Diffusion JavaScript client

101 lines (100 loc) 4.13 kB
"use strict"; /** * @module Services.FetchQuery */ 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.FetchQueryResultSerialiser = exports.FetchQueryResultSerialiserClass = void 0; var Codec = require("./../../io/codec"); var BEES = require("./../../serialisers/byte-encoded-enum-serialiser"); var serialiser_1 = require("./../../serialisers/serialiser"); var fetch_topic_result_1 = require("./../../services/fetch-query/fetch-topic-result"); var Long = require("long"); var topic_type_1 = require("../../../topics/topic-type"); var fetch_query_result_1 = require("./fetch-query-result"); var fetch_topic_size_info_1 = require("./fetch-topic-size-info"); /** * Read a property map from the stream * * @param bis the input stream * @return the property map that was read */ function readProperties(bis) { return Codec.readDictionary(bis, Codec.readString); } function readSizeInfo(bis) { var infoType = BEES.read(bis, fetch_topic_size_info_1.FetchTopicSizeType); if (infoType === fetch_topic_size_info_1.FetchTopicSizeType.SIMPLE_SIZE_INFO) { var size = Codec.readInt32(bis); return { infoType: infoType, valueSize: size, valueCount: 1, valueTotalSize: new Long(size) }; } else if (infoType === fetch_topic_size_info_1.FetchTopicSizeType.TIME_SERIES_SIZE_INFO) { return { infoType: infoType, valueSize: Codec.readInt32(bis), valueCount: Codec.readInt32(bis), valueTotalSize: Codec.readInt64(bis) }; } return fetch_topic_size_info_1.NO_TOPIC_SIZE_INFO; } /** * Read a {@link FetchTopicResult} from the stream * * @param bis the input stream * @return the {@link FetchTopicResult} that was read */ function readFetchTopicResult(bis) { var path = Codec.readString(bis); var type = BEES.read(bis, topic_type_1.TopicType); var value = Codec.readOptional(bis, Codec.readBytes); var propertiesIndex = Codec.readInt32(bis); var sizeInfo = readSizeInfo(bis); return new fetch_topic_result_1.FetchTopicResult(path, type, propertiesIndex, sizeInfo, value); } /** * Serialiser for {@link FetchQueryResult} */ var FetchQueryResultSerialiserClass = /** @class */ (function (_super) { __extends(FetchQueryResultSerialiserClass, _super); function FetchQueryResultSerialiserClass() { return _super !== null && _super.apply(this, arguments) || this; } /** * Read a {@link FetchQueryResult} from the stream * * @param bis the input stream * @return the {@link FetchQueryResult} that was read */ FetchQueryResultSerialiserClass.prototype.read = function (bis) { var properties = Codec.readCollection(bis, readProperties); var results = Codec.readCollection(bis, readFetchTopicResult); var hasMore = Codec.readBoolean(bis); return new fetch_query_result_1.FetchQueryResult(properties, results, hasMore); }; return FetchQueryResultSerialiserClass; }(serialiser_1.AbstractSerialiser)); exports.FetchQueryResultSerialiserClass = FetchQueryResultSerialiserClass; /** * The {@link FetchQueryResultSerialiser} singleton */ // eslint-disable-next-line @typescript-eslint/naming-convention exports.FetchQueryResultSerialiser = new FetchQueryResultSerialiserClass();