diffusion
Version:
Diffusion JavaScript client
129 lines (128 loc) • 4.38 kB
JavaScript
;
/**
* @module Services.SessionFetchQuery
*/
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 __());
};
})();
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SessionFetchQuerySerialiser = exports.SessionFetchQuerySerialiserClass = void 0;
var Codec = require("./../../io/codec");
var serialiser_1 = require("./../../serialisers/serialiser");
var math_1 = require("./../../util/math");
/**
* Write an optional range limit to the stream
*
* @param bos the output stream
* @param value the limit to be written
*/
function writeRangeLimit(bos, limit) {
if (limit === undefined) {
Codec.writeByte(bos, 0);
}
else {
Codec.writeByte(bos, 1);
Codec.writeInt64(bos, limit);
}
}
/**
* Write a {@link SessionFetchRange} to the stream
*
* @param bos the output stream
* @param value the {@link SessionFetchRange} to be written
*/
function writeRange(bos, range) {
writeRangeLimit(bos, range.from);
writeRangeLimit(bos, range.to);
}
/**
* Write the result limit to the stream, if required
* @param bos the output stream
* @param limit the result limit
*/
function writeLimit(bos, limit) {
if (limit === math_1.MAX_INT32) {
Codec.writeByte(bos, 0);
}
else {
Codec.writeByte(bos, 1);
Codec.writeInt32(bos, limit);
}
}
/**
* Write the list of requested session properties
*
* @param bos the output stream
* @param properties the session properties set to include
*/
function writeProperties(bos, properties) {
if (properties === null) {
Codec.writeByte(bos, 0);
}
else {
Codec.writeByte(bos, 1);
Codec.writeCollection(bos, __spreadArray([], __read(properties)), Codec.writeString);
}
}
/**
* Serialiser for {@link SessionFetchQuery}
*/
var SessionFetchQuerySerialiserClass = /** @class */ (function (_super) {
__extends(SessionFetchQuerySerialiserClass, _super);
function SessionFetchQuerySerialiserClass() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Write a {@link SessionFetchQuery} to the stream
*
* @param bos the output stream
* @param value the {@link SessionFetchQuery} to be written
*/
SessionFetchQuerySerialiserClass.prototype.write = function (bos, value) {
Codec.writeString(bos, value.filter);
writeProperties(bos, value.withProperties);
writeRange(bos, value.range);
writeLimit(bos, value.limit);
Codec.writeInt32(bos, value.maximumResultSize);
Codec.writeBoolean(bos, value.requiresStartTime);
};
return SessionFetchQuerySerialiserClass;
}(serialiser_1.AbstractSerialiser));
exports.SessionFetchQuerySerialiserClass = SessionFetchQuerySerialiserClass;
/**
* The {@link SessionFetchQuerySerialiser} singleton
*/ // eslint-disable-next-line @typescript-eslint/naming-convention
exports.SessionFetchQuerySerialiser = new SessionFetchQuerySerialiserClass();