UNPKG

diffusion

Version:

Diffusion JavaScript client

81 lines (80 loc) 2.38 kB
"use strict"; /** * @module Services.Timeseries */ Object.defineProperty(exports, "__esModule", { value: true }); exports.write = exports.read = void 0; var point_1 = require("./../../features/time-series/point"); var range_1 = require("./../../features/time-series/range"); var range_query_parameters_1 = require("./../../features/time-series/range-query-parameters"); var Codec = require("./../../io/codec"); var BEES = require("./../../serialisers/byte-encoded-enum-serialiser"); /** * Read a {@link Point} from the stream * * @param bis the input stream * @return the {@link Point} that was read */ function readPoint(bis) { var value = Codec.readInt64(bis); var type = BEES.read(bis, point_1.Types); return new point_1.Point(value, type); } /** * Read a {@link Range} from the stream * * @param bis the input stream * @return the {@link Range} that was read */ function readRange(bis) { var anchor = readPoint(bis); var span = readPoint(bis); return new range_1.Range(anchor, span); } /** * Write a {@link Point} to the stream * * @param bos the output stream * @param value the {@link Point} to be written */ function writePoint(bos, point) { Codec.writeInt64(bos, point.value); BEES.write(bos, point.type); } /** * Write a {@link Range} to the stream * * @param bos the output stream * @param value the {@link Range} to be written */ function writeRange(bos, range) { writePoint(bos, range.anchor); writePoint(bos, range.span); } /** * Read a {@link RangeQueryParameters} object from the stream * * @param bis the input stream * @return the {@link RangeQueryParameters} that were read */ function read(bis) { var queryType = BEES.read(bis, range_query_parameters_1.QueryTypes); var viewRange = readRange(bis); var editRange = readRange(bis); var limit = Codec.readInt64(bis); return new range_query_parameters_1.RangeQueryParameters(queryType, viewRange, editRange, limit); } exports.read = read; /** * Write a {@link RangeQueryParameters} object to the stream * * @param bos the output stream * @param value the {@link RangeQueryParameters} to be written */ function write(bos, value) { BEES.write(bos, value.queryType); writeRange(bos, value.viewRange); writeRange(bos, value.editRange); Codec.writeInt64(bos, value.limit); } exports.write = write;