APIs

Show:
// --------- This code has been automatically generated !!! 2018-09-22T13:24:56.466Z
"use strict";
/**
 * @module opcua.address_space.types
 */
const assert = require("node-opcua-assert").assert;
const util = require("util");
const _  = require("underscore");
const makeNodeId = require("node-opcua-nodeid").makeNodeId;
const schema_helpers =  require("node-opcua-factory/src/factories_schema_helpers");
const extract_all_fields                       = schema_helpers.extract_all_fields;
const resolve_schema_field_types               = schema_helpers.resolve_schema_field_types;
const initialize_field                         = schema_helpers.initialize_field;
const initialize_field_array                   = schema_helpers.initialize_field_array;
const check_options_correctness_against_schema = schema_helpers.check_options_correctness_against_schema;
const _defaultTypeMap = require("node-opcua-factory/src/factories_builtin_types")._defaultTypeMap;
const ec = require("node-opcua-basic-types");
const encodeArray = ec.encodeArray;
const decodeArray = ec.decodeArray;
const makeExpandedNodeId = require("node-opcua-nodeid/src/expanded_nodeid").makeExpandedNodeId;
const generate_new_id = require("node-opcua-factory").generate_new_id;
const _enumerations = require("node-opcua-factory/src/factories_enumerations")._private._enumerations;
const schema = require("../schemas/Variant_schema").Variant_Schema;
const getFactory = require("node-opcua-factory/src/factories_factories").getFactory;
const BaseUAObject = require("node-opcua-factory/src/factories_baseobject").BaseUAObject;

/**
 * 
 * @class Variant
 * @constructor
 * @extends BaseUAObject
 * @param  options {Object}
 */
function Variant(options)
{
    options = options || {};
    /* istanbul ignore next */
    if (schema_helpers.doDebug) { check_options_correctness_against_schema(this,schema,options); }
    const self = this;
    assert(this instanceof BaseUAObject); //  ' keyword "new" is required for constructor call')
    resolve_schema_field_types(schema);

    //construction hook
    options = schema.construct_hook(options); 
    BaseUAObject.call(this,options);
    if (options === null) { 
        BaseUAObject.call(this,options);
        return ;
    }

    /**
      * the variant type.
      * @property dataType
      * @type {DataType}
      * @default  0
      */
    self.setDataType(initialize_field(schema.fields[0], options.dataType));

    /**
      * 
      * @property arrayType
      * @type {VariantArrayType}
      * @default  0
      */
    self.setArrayType(initialize_field(schema.fields[1], options.arrayType));

    /**
      * 
      * @property value
      * @type {Any}
      * @default  null
      */
    self.value = initialize_field(schema.fields[2], options.value);

    /**
      * the matrix dimensions
      * @property dimensions
      * @type {UInt32[]}
      * @default  null
      */
    self.dimensions = initialize_field_array(schema.fields[3], options.dimensions);

   // Object.preventExtensions(self);
}
util.inherits(Variant,BaseUAObject);

//## Define Enumeration setters
Variant.prototype.setDataType = function(value) {
   const coercedValue = _enumerations.DataType.typedEnum.get(value);
   /* istanbul ignore next */
   if (coercedValue === undefined || coercedValue === null) {
      throw new Error("value cannot be coerced to DataType: " + value);
   }
   this.dataType = coercedValue;
};
Variant.prototype.setArrayType = function(value) {
   const coercedValue = _enumerations.VariantArrayType.typedEnum.get(value);
   /* istanbul ignore next */
   if (coercedValue === undefined || coercedValue === null) {
      throw new Error("value cannot be coerced to VariantArrayType: " + value);
   }
   this.arrayType = coercedValue;
};
schema.id = generate_new_id();
Variant.prototype.encodingDefaultBinary = makeExpandedNodeId(schema.id);
Variant.prototype._schema = schema;

const encode_DataType = _enumerations.DataType.encode;
const decode_DataType = _enumerations.DataType.decode;
const encode_VariantArrayType = _enumerations.VariantArrayType.encode;
const decode_VariantArrayType = _enumerations.VariantArrayType.decode;
const encode_Any = _defaultTypeMap.Any.encode;
const decode_Any = _defaultTypeMap.Any.decode;
const encode_UInt32 = _defaultTypeMap.UInt32.encode;
const decode_UInt32 = _defaultTypeMap.UInt32.decode;
Variant.prototype.encode = function(stream,options) {
   schema.encode(this,stream,options); 
};
/**
 * decode the object from a binary stream
 * @method decode
 *
 * @param stream {BinaryStream} 
 */
Variant.prototype.decode = function(stream) {
   schema.decode(this,stream); 
};
Variant.prototype.decode_debug = function(stream,options) {
   schema.decode_debug(this,stream,options); 
};
/**
 *
 * verify that all object attributes values are valid according to schema
 * @method isValid
 * @return {Boolean}
 */
Variant.prototype.isValid = function() { return schema.isValid(this); };
Variant.possibleFields = [
  "dataType",
         "arrayType",
         "value",
         "dimensions"
];


exports.Variant = Variant;
const register_class_definition = require("node-opcua-factory/src/factories_factories").register_class_definition;
register_class_definition("Variant",Variant);