// --------- This code has been automatically generated !!! 2017-12-15T21:15:14.599Z
"use strict";
/**
* @module opcua.address_space.types
*/
var assert = require("node-opcua-assert");
var util = require("util");
var _ = require("underscore");
var makeNodeId = require("node-opcua-nodeid").makeNodeId;
var schema_helpers = require("node-opcua-factory/src/factories_schema_helpers");
var extract_all_fields = schema_helpers.extract_all_fields;
var resolve_schema_field_types = schema_helpers.resolve_schema_field_types;
var initialize_field = schema_helpers.initialize_field;
var initialize_field_array = schema_helpers.initialize_field_array;
var check_options_correctness_against_schema = schema_helpers.check_options_correctness_against_schema;
var _defaultTypeMap = require("node-opcua-factory/src/factories_builtin_types")._defaultTypeMap;
var ec = require("node-opcua-basic-types");
var encodeArray = ec.encodeArray;
var decodeArray = ec.decodeArray;
var makeExpandedNodeId = require("node-opcua-nodeid/src/expanded_nodeid").makeExpandedNodeId;
var generate_new_id = require("node-opcua-factory").generate_new_id;
var _enumerations = require("node-opcua-factory/src/factories_enumerations")._private._enumerations;
var schema = require("../test/test_factories").Shape_Schema;
var getFactory = require("node-opcua-factory/src/factories_factories").getFactory;
var BaseUAObject = require("node-opcua-factory/src/factories_baseobject").BaseUAObject;
/**
*
* @class Shape
* @constructor
* @extends BaseUAObject
* @param options {Object}
* @param [options.name = my shape] {String}
* @param [options.shapeType] {EnumShapeType}
* @param [options.color = 300] {EnumColor}
* @param [options.inner_color = 200] {EnumColor}
*/
function Shape(options)
{
options = options || {};
/* istanbul ignore next */
if (schema_helpers.doDebug) { check_options_correctness_against_schema(this,schema,options); }
var self = this;
assert(this instanceof BaseUAObject); // ' keyword "new" is required for constructor call')
resolve_schema_field_types(schema);
BaseUAObject.call(this,options);
/**
*
* @property name
* @type {String}
* @default function () {
return "my shape";
}
*/
self.name = initialize_field(schema.fields[0], options.name);
/**
*
* @property shapeType
* @type {EnumShapeType}
*/
self.setShapeType(initialize_field(schema.fields[1], options.shapeType));
/**
*
* @property color
* @type {EnumColor}
* @default 300
*/
self.setColor(initialize_field(schema.fields[2], options.color));
/**
*
* @property inner_color
* @type {EnumColor}
* @default function () {
return Color.BLUE;
}
*/
self.setInner_color(initialize_field(schema.fields[3], options.inner_color));
// Object.preventExtensions(self);
}
util.inherits(Shape,BaseUAObject);
//## Define Enumeration setters
Shape.prototype.setShapeType = function(value) {
var coercedValue = _enumerations.EnumShapeType.typedEnum.get(value);
/* istanbul ignore next */
if (coercedValue === undefined || coercedValue === null) {
throw new Error("value cannot be coerced to EnumShapeType: " + value);
}
this.shapeType = coercedValue;
};
Shape.prototype.setColor = function(value) {
var coercedValue = _enumerations.EnumColor.typedEnum.get(value);
/* istanbul ignore next */
if (coercedValue === undefined || coercedValue === null) {
throw new Error("value cannot be coerced to EnumColor: " + value);
}
this.color = coercedValue;
};
Shape.prototype.setInner_color = function(value) {
var coercedValue = _enumerations.EnumColor.typedEnum.get(value);
/* istanbul ignore next */
if (coercedValue === undefined || coercedValue === null) {
throw new Error("value cannot be coerced to EnumColor: " + value);
}
this.inner_color = coercedValue;
};
schema.id = generate_new_id();
Shape.prototype.encodingDefaultBinary = makeExpandedNodeId(schema.id);
Shape.prototype._schema = schema;
var encode_String = _defaultTypeMap.String.encode;
var decode_String = _defaultTypeMap.String.decode;
var encode_EnumShapeType = _enumerations.EnumShapeType.encode;
var decode_EnumShapeType = _enumerations.EnumShapeType.decode;
var encode_EnumColor = _enumerations.EnumColor.encode;
var decode_EnumColor = _enumerations.EnumColor.decode;
/**
* encode the object into a binary stream
* @method encode
*
* @param stream {BinaryStream}
*/
Shape.prototype.encode = function(stream,options) {
// call base class implementation first
BaseUAObject.prototype.encode.call(this,stream,options);
encode_String(this.name,stream);
encode_EnumShapeType(this.shapeType,stream);
encode_EnumColor(this.color,stream);
encode_EnumColor(this.inner_color,stream);
};
/**
* decode the object from a binary stream
* @method decode
*
* @param stream {BinaryStream}
* @param [option] {object}
*/
Shape.prototype.decode = function(stream,options) {
// call base class implementation first
BaseUAObject.prototype.decode.call(this,stream,options);
this.name = decode_String(stream,options);
this.shapeType = decode_EnumShapeType(stream,options);
this.color = decode_EnumColor(stream,options);
this.inner_color = decode_EnumColor(stream,options);
};
Shape.possibleFields = [
"name",
"shapeType",
"color",
"inner_color"
];
exports.Shape = Shape;
var register_class_definition = require("node-opcua-factory/src/factories_factories").register_class_definition;
register_class_definition("Shape",Shape);