All files / ua DataValue.js

88.24% Statements 45/51
64% Branches 48/75
100% Functions 5/5
88.24% Lines 45/51

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87  56x 112x   56x 56x 56x 56x 56x 56x 56x 56x 56x       4x 4x 4x     4x     4x     4x     4x         2x 2x 2x 2x   2x     2x 1x   2x     2x 1x   2x     2x     2x 2x 2x 2x 2x   2x     2x 1x   2x     2x 1x   2x     2x     48x     56x  
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Variant_1 = __importDefault(require("./Variant"));
const Bucket_1 = __importDefault(require("./Bucket"));
exports.DataValueValue = 0x1;
exports.DataValueStatusCode = 0x2;
exports.DataValueSourceTimestamp = 0x4;
exports.DataValueServerTimestamp = 0x8;
exports.DataValueSourcePicoseconds = 0x10;
exports.DataValueServerPicoseconds = 0x20;
class DataValue {
    constructor(options) {
        var _a, _b, _c, _d, _e, _f, _g, _h;
        this.EncodingMask = (_b = (_a = options) === null || _a === void 0 ? void 0 : _a.EncodingMask, (_b !== null && _b !== void 0 ? _b : 0));
        this.Value = this.has(exports.DataValueValue) ? (_c = options) === null || _c === void 0 ? void 0 : _c.Value : null;
        this.Status = this.has(exports.DataValueStatusCode)
            ? (_d = options) === null || _d === void 0 ? void 0 : _d.Status
            : null;
        this.SourceTimestamp = this.has(exports.DataValueSourceTimestamp)
            ? (_e = options) === null || _e === void 0 ? void 0 : _e.SourceTimestamp
            : null;
        this.SourcePicoSeconds = this.has(exports.DataValueSourcePicoseconds)
            ? (_f = options) === null || _f === void 0 ? void 0 : _f.SourcePicoSeconds
            : null;
        this.ServerTimestamp = this.has(exports.DataValueServerTimestamp)
            ? (_g = options) === null || _g === void 0 ? void 0 : _g.ServerTimestamp
            : null;
        this.ServerPicoSeconds = this.has(exports.DataValueServerPicoseconds)
            ? (_h = options) === null || _h === void 0 ? void 0 : _h.ServerPicoSeconds
            : null;
    }
    encode() {
        const bucket = new Bucket_1.default();
        bucket.writeUint8(this.EncodingMask);
        Eif (this.has(exports.DataValueValue)) {
            bucket.writeStruct(this.Value);
        }
        Iif (this.has(exports.DataValueStatusCode)) {
            bucket.writeUint32(this.Status);
        }
        if (this.has(exports.DataValueSourceTimestamp)) {
            bucket.writeDate(this.SourceTimestamp);
        }
        Iif (this.has(exports.DataValueSourcePicoseconds)) {
            bucket.writeUint16(this.SourcePicoSeconds);
        }
        if (this.has(exports.DataValueServerTimestamp)) {
            bucket.writeDate(this.ServerTimestamp);
        }
        Iif (this.has(exports.DataValueServerPicoseconds)) {
            bucket.writeUint16(this.ServerPicoSeconds);
        }
        return bucket.bytes;
    }
    decode(b, position) {
        const bucket = new Bucket_1.default(b, position);
        this.EncodingMask = bucket.readUint8();
        Eif (this.has(exports.DataValueValue)) {
            this.Value = new Variant_1.default();
            bucket.readStruct(this.Value);
        }
        Iif (this.has(exports.DataValueStatusCode)) {
            this.Status = bucket.readUint32();
        }
        if (this.has(exports.DataValueSourceTimestamp)) {
            this.SourceTimestamp = bucket.readDate();
        }
        Iif (this.has(exports.DataValueSourcePicoseconds)) {
            this.SourcePicoSeconds = bucket.readUint16();
        }
        if (this.has(exports.DataValueServerTimestamp)) {
            this.ServerTimestamp = bucket.readDate();
        }
        Iif (this.has(exports.DataValueServerPicoseconds)) {
            this.ServerPicoSeconds = bucket.readUint16();
        }
        return bucket.position;
    }
    has(mask) {
        return (this.EncodingMask & mask) === mask;
    }
}
exports.default = DataValue;