All files / ua ExpandedNodeId.js

100% Statements 33/33
98.04% Branches 50/51
100% Functions 8/8
100% Lines 31/31

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  55x 55x   55x 55x 55x         116x 116x 116x 116x 2x   116x 2x       40x 40x 40x 2x   40x 2x   40x     40x 40x 40x 2x   40x 2x   40x     80x     80x     55x 70x     55x      
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const NodeId_1 = require("./NodeId");
const Bucket_1 = __importDefault(require("./Bucket"));
// https://reference.opcfoundation.org/v104/Core/docs/Part6/5.2.2/#5.2.2.10
class ExpandedNodeId {
    constructor(options) {
        var _a, _b, _c, _d, _e, _f, _g, _h;
        this.NodeId = (_b = (_a = options) === null || _a === void 0 ? void 0 : _a.NodeId, (_b !== null && _b !== void 0 ? _b : NodeId_1.NewTwoByteNodeId(0)));
        this.NamespaceUri = (_d = (_c = options) === null || _c === void 0 ? void 0 : _c.NamespaceUri, (_d !== null && _d !== void 0 ? _d : ''));
        this.ServerIndex = (_f = (_e = options) === null || _e === void 0 ? void 0 : _e.ServerIndex, (_f !== null && _f !== void 0 ? _f : 0));
        if ((_g = options) === null || _g === void 0 ? void 0 : _g.NamespaceUri) {
            this.NodeId.setNamespaceUriFlag();
        }
        if ((_h = options) === null || _h === void 0 ? void 0 : _h.ServerIndex) {
            this.NodeId.setServerIndexFlag();
        }
    }
    encode() {
        const bucket = new Bucket_1.default();
        bucket.writeStruct(this.NodeId);
        if (this.hasNamespaceUri()) {
            bucket.writeString(this.NamespaceUri);
        }
        if (this.hasServerIndex()) {
            bucket.writeUint32(this.ServerIndex);
        }
        return bucket.bytes;
    }
    decode(b, position) {
        const bucket = new Bucket_1.default(b, position);
        bucket.readStruct(this.NodeId);
        if (this.hasNamespaceUri()) {
            this.NamespaceUri = bucket.readString();
        }
        if (this.hasServerIndex()) {
            this.ServerIndex = bucket.readUint32();
        }
        return bucket.position;
    }
    hasNamespaceUri() {
        return ((this.NodeId.Type >> 7) & 0x1) === 1;
    }
    hasServerIndex() {
        return ((this.NodeId.Type >> 6) & 0x1) === 1;
    }
}
exports.default = ExpandedNodeId;
exports.NewTwoByteExpandedNodeId = (id) => new ExpandedNodeId({
    NodeId: NodeId_1.NewTwoByteNodeId(id)
});
exports.NewFourByteExpandedNodeId = (ns, id) => new ExpandedNodeId({
    NodeId: NodeId_1.NewFourByteNodeId(ns, id)
});