All files / ua DiagnosticInfo.js

100% Statements 57/57
98.99% Branches 98/99
100% Functions 5/5
100% Lines 57/57

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  56x 56x   56x 56x 56x 56x 56x 56x 56x 56x 56x 56x         60x 60x 60x 60x 60x 60x 60x 60x     30x 30x 30x 4x   30x 2x   30x 2x   30x 2x   30x 2x   30x 2x   30x 2x 2x   30x     30x 30x 30x 4x   30x 2x   30x 2x   30x 2x   30x 2x   30x 2x   30x 2x   30x     420x     56x  
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Bucket_1 = __importDefault(require("./Bucket"));
const StatusCode_1 = require("./StatusCode");
exports.SymbolicId = 0x1;
exports.NamespaceUri = 0x2;
exports.LocalizedText = 0x4;
exports.Locale = 0x8;
exports.AdditionalInfo = 0x10;
exports.InnerStatusCode = 0x20;
exports.InnerDiagnosticInfo = 0x40;
// https://reference.opcfoundation.org/v104/Core/docs/Part6/5.2.2/#5.2.2.12
class DiagnosticInfo {
    constructor(options) {
        var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
        this.EncodingMask = (_b = (_a = options) === null || _a === void 0 ? void 0 : _a.EncodingMask, (_b !== null && _b !== void 0 ? _b : 0x00));
        this.SymbolicId = (_d = (_c = options) === null || _c === void 0 ? void 0 : _c.SymbolicId, (_d !== null && _d !== void 0 ? _d : 0));
        this.NamespaceUri = (_f = (_e = options) === null || _e === void 0 ? void 0 : _e.NamespaceUri, (_f !== null && _f !== void 0 ? _f : 0));
        this.Locale = (_h = (_g = options) === null || _g === void 0 ? void 0 : _g.Locale, (_h !== null && _h !== void 0 ? _h : 0));
        this.LocalizedText = (_k = (_j = options) === null || _j === void 0 ? void 0 : _j.LocalizedText, (_k !== null && _k !== void 0 ? _k : 0));
        this.AdditionalInfo = (_m = (_l = options) === null || _l === void 0 ? void 0 : _l.AdditionalInfo, (_m !== null && _m !== void 0 ? _m : ''));
        this.InnerStatusCode = (_p = (_o = options) === null || _o === void 0 ? void 0 : _o.InnerStatusCode, (_p !== null && _p !== void 0 ? _p : StatusCode_1.StatusCodeOK));
        this.InnerDiagnosticInfo = (_r = (_q = options) === null || _q === void 0 ? void 0 : _q.InnerDiagnosticInfo, (_r !== null && _r !== void 0 ? _r : null));
    }
    decode(b, position) {
        const bucket = new Bucket_1.default(b, position);
        this.EncodingMask = bucket.readUint8();
        if (this.has(exports.SymbolicId)) {
            this.SymbolicId = bucket.readInt32();
        }
        if (this.has(exports.NamespaceUri)) {
            this.NamespaceUri = bucket.readInt32();
        }
        if (this.has(exports.Locale)) {
            this.Locale = bucket.readInt32();
        }
        if (this.has(exports.LocalizedText)) {
            this.LocalizedText = bucket.readInt32();
        }
        if (this.has(exports.AdditionalInfo)) {
            this.AdditionalInfo = bucket.readString();
        }
        if (this.has(exports.InnerStatusCode)) {
            this.InnerStatusCode = bucket.readUint32();
        }
        if (this.has(exports.InnerDiagnosticInfo)) {
            this.InnerDiagnosticInfo = new DiagnosticInfo();
            bucket.readStruct(this.InnerDiagnosticInfo);
        }
        return bucket.position;
    }
    encode() {
        const bucket = new Bucket_1.default();
        bucket.writeUint8(this.EncodingMask);
        if (this.has(exports.SymbolicId)) {
            bucket.writeInt32(this.SymbolicId);
        }
        if (this.has(exports.NamespaceUri)) {
            bucket.writeInt32(this.NamespaceUri);
        }
        if (this.has(exports.Locale)) {
            bucket.writeInt32(this.Locale);
        }
        if (this.has(exports.LocalizedText)) {
            bucket.writeInt32(this.LocalizedText);
        }
        if (this.has(exports.AdditionalInfo)) {
            bucket.writeString(this.AdditionalInfo);
        }
        if (this.has(exports.InnerStatusCode)) {
            bucket.writeUint32(this.InnerStatusCode);
        }
        if (this.has(exports.InnerDiagnosticInfo)) {
            bucket.writeStruct(this.InnerDiagnosticInfo);
        }
        return bucket.bytes;
    }
    has(mask) {
        return (this.EncodingMask & mask) === mask;
    }
}
exports.default = DiagnosticInfo;