How to use the node-opcua-factory.registerSpecialVariantEncoder function in node-opcua-factory

To help you get started, we’ve selected a few node-opcua-factory examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-opcua / node-opcua / packages / node-opcua-data-model / source / localized_text.ts View on Github external
const encodingMask = decodeByte(stream);
        if ((encodingMask & 0x01) === 0x01) {
            this.locale = decodeString(stream);
        } else {
            this.locale = null;
        }
        if ((encodingMask & 0x02) === 0x02) {
            this.text = decodeString(stream);
        } else {
            this.text = null;
        }
    }
}

// not an extension object registerClassDefinition("LocalizedText", LocalizedText);
registerSpecialVariantEncoder(LocalizedText);

export type LocalizedTextLike = LocalizedTextOptions | LocalizedText | string;

function getLocalizeText_EncodingByte(localizedText: LocalizedText): number {
    let encodingMask = 0;
    if (localizedText.locale) {
        encodingMask |= 0x01;
    }
    if (localizedText.text) {
        encodingMask |= 0x02;
    }
    return encodingMask;
}

const emptyLocalizedText = new LocalizedText({});
github node-opcua / node-opcua / packages / node-opcua-variant / source / variant.ts View on Github external
}
  }
  if (v1.arrayType === VariantArrayType.Array) {
    return __check_same_array(v1.value, v2.value);

  } else if (v1.arrayType === VariantArrayType.Matrix) {
    if (!__check_same_array(v1.dimensions, v2.dimensions)) {
      return false;
    }
    return __check_same_array(v1.value, v2.value);
  }
  return false;
}

// ---------------------------------------------------------------------------------------------------------
registerSpecialVariantEncoder(Variant);

export interface VariantOptionsT extends VariantOptions {
  dataType: DT;
  arrayType?: VariantArrayType | string;
  value: T;
  dimensions?: number[] | null;
}

export interface VariantT extends Variant {
  value: T;
  dataType: DT;
}
export declare type VariantByteString = VariantT;
export declare type VariantDouble = VariantT;
github node-opcua / node-opcua / packages / node-opcua-data-model / source / diagnostic_info.ts View on Github external
value.encode(stream);
    }
}

export function decodeDiagnosticInfo(stream: BinaryStream): DiagnosticInfo {
    const value = new DiagnosticInfo({});
    value.decode(stream);
    return value;
}

// Note:
// the SymbolicId, NamespaceURI, LocalizedText and Locale fields are indexes in a string table which is returned
// in the response header. Only the index of the corresponding string in the string table is encoded. An index
// of −1 indicates that there is no value for the string.
//
registerSpecialVariantEncoder(DiagnosticInfo);
github node-opcua / node-opcua / packages / node-opcua-data-value / src / datavalue.js View on Github external
const assert = require("node-opcua-assert").assert;
const _ = require("underscore");


const DataValue = exports.DataValue = require("../_generated_/_auto_generated_DataValue").DataValue;

const DataType = require("node-opcua-variant").DataType;
const VariantArrayType = require("node-opcua-variant").VariantArrayType;


const TimestampsToReturn = require("../schemas/TimestampsToReturn_enum").TimestampsToReturn;


const registerSpecialVariantEncoder = require("node-opcua-factory").registerSpecialVariantEncoder;
registerSpecialVariantEncoder(exports.DataValue);

const getCurrentClock = require("node-opcua-date-time").getCurrentClock;

const Variant = require("node-opcua-variant").Variant;
const sameVariant = require("node-opcua-variant/src/variant_tools").sameVariant;

function w(n){
    return ("0000"+n).substr(-3);
}
DataValue.prototype.toString = function () {


    function toMicroNanoPico(picoseconds) {
        //xx picoseconds = 123456789;
        return ""
            + w((picoseconds / 1000000 )>>0)
github node-opcua / node-opcua / packages / node-opcua-data-model / src / qualified_name.js View on Github external
if (!value) {
        return null;
    } else if (value instanceof QualifiedName) {
        return value;
    } else if (_.isString(value)) {
        return stringToQualifiedName(value);
    } else {
        assert(value.hasOwnProperty("namespaceIndex"));
        assert(value.hasOwnProperty("name"));
        return new exports.QualifiedName(value);
    }
}
exports.coerceQualifyName = coerceQualifyName;

const factory = require("node-opcua-factory");
factory.registerSpecialVariantEncoder(exports.QualifiedName);
github node-opcua / node-opcua / packages / node-opcua-data-model / src / diagnostic_info.js View on Github external
"use strict";

exports.DiagnosticInfo = require("../_generated_/_auto_generated_DiagnosticInfo").DiagnosticInfo;


const factory = require("node-opcua-factory");
factory.registerSpecialVariantEncoder(exports.DiagnosticInfo);
github node-opcua / node-opcua / packages / node-opcua-data-value / source / datavalue.ts View on Github external
}

  public clone() {
    return new DataValue({
      serverPicoseconds: this.serverPicoseconds,
      serverTimestamp: this.serverTimestamp,
      sourcePicoseconds: this.sourcePicoseconds,
      sourceTimestamp: this.sourceTimestamp,
      statusCode: this.statusCode,
      value: this.value ? this.value.clone() : undefined
    });
  }
}

DataValue.prototype.schema = DataValue.schema;
registerSpecialVariantEncoder(DataValue);

export type DataValueLike = DataValueOptions | DataValue;

function w(n: number): string {
  return ("0000" + n).substr(-3);
}

function _partial_clone(dataValue: DataValue): DataValue {
  const cloneDataValue = new DataValue();
  cloneDataValue.value = dataValue.value;
  cloneDataValue.statusCode = dataValue.statusCode;
  return cloneDataValue;
}

export function apply_timestamps(
  dataValue: DataValue,
github node-opcua / node-opcua / packages / node-opcua-variant / src / variant.js View on Github external
}
Variant.coerce = _coerceVariant;

/**
 * @method clone
 *   deep clone a variant
 *
 * @return {exports.Variant}
 */
Variant.prototype.clone = function () {
    return new this.constructor(this);
};


const factory = require("node-opcua-factory");
factory.registerSpecialVariantEncoder(Variant);
github node-opcua / node-opcua / packages / node-opcua-data-model / source / qualified_name.ts View on Github external
export function coerceQualifiedName(value: any): QualifiedName | null {

    if (!value) {
        return null;
    } else if (value instanceof QualifiedName) {
        return value;
    } else if (_.isString(value)) {
        return stringToQualifiedName(value);
    } else {
        assert(value.hasOwnProperty("namespaceIndex"));
        assert(value.hasOwnProperty("name"));
        return new exports.QualifiedName(value);
    }
}

registerSpecialVariantEncoder(QualifiedName);

export function encodeQualifiedName(value: QualifiedName, stream: OutputBinaryStream): void {
    value.encode(stream);
}

export function decodeQualifiedName(stream: BinaryStream): QualifiedName {
    const value = new QualifiedName({});
    value.decode(stream);
    return value;
}
github node-opcua / node-opcua / packages / node-opcua-data-model / src / localized_text.js View on Github external
}
    if (typeof value === "string") {
        return new LocalizedText({locale: null, text: value});
    }
    if (value instanceof LocalizedText) {
        return value;
    }
    assert(value.hasOwnProperty("locale"));
    assert(value.hasOwnProperty("text"));
    return new LocalizedText(value);
}
LocalizedText.coerce = coerceLocalizedText;
exports.coerceLocalizedText = coerceLocalizedText;

const factory = require("node-opcua-factory");
factory.registerSpecialVariantEncoder(exports.LocalizedText);