Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assert(value !== undefined);
if (isEnumerationItem(value)) {
// value is a enumeration of some sort
value = value.value;
} else {
value = parseInt(value, 10);
}
/* istanbul ignore next */
if (!_.isFinite(value)) {
// xx console.log("xxx ", value, ttt);
throw new Error("expecting a number " + value);
}
break;
case DataType.UInt64:
value = coerceUInt64(value);
break;
case DataType.Int64:
value = coerceInt64(value);
break;
case DataType.ExtensionObject:
break;
case DataType.DateTime:
assert(value === null || value instanceof Date);
break;
case DataType.String:
assert(typeof value === "string" || value === null);
break;
case DataType.ByteString:
value = (typeof value === "string") ? Buffer.from(value) : value;
// istanbul ignore next
{name: "Int16", encode: ec.encodeInt16, decode: ec.decodeInt16, defaultValue: 0, coerce: ec.coerceInt16},
{name: "UInt16", encode: ec.encodeUInt16, decode: ec.decodeUInt16, defaultValue: 0, coerce: ec.coerceUInt16},
{name: "Int32", encode: ec.encodeInt32, decode: ec.decodeInt32, defaultValue: 0, coerce: ec.coerceInt32},
{name: "UInt32", encode: ec.encodeUInt32, decode: ec.decodeUInt32, defaultValue: 0, coerce: ec.coerceUInt32},
{
name: "Int64",
encode: ec.encodeInt64,
decode: ec.decodeInt64,
defaultValue: ec.coerceInt64(0),
coerce: ec.coerceInt64
},
{
name: "UInt64",
encode: ec.encodeUInt64,
decode: ec.decodeUInt64,
defaultValue: ec.coerceUInt64(0),
coerce: ec.coerceUInt64
},
{name: "Float", encode: ec.encodeFloat, decode: ec.decodeFloat, defaultValue: 0.0, coerce: ec.coerceFloat},
{name: "Double", encode: ec.encodeDouble, decode: ec.decodeDouble, defaultValue: 0.0, coerce: ec.coerceFloat},
{name: "String", encode: ec.encodeString, decode: ec.decodeString, defaultValue: ""},
// OPC Unified Architecture, part 3.0 $8.26 page 67
{
name: "DateTime",
encode: ec.encodeDateTime,
decode: ec.decodeDateTime,
defaultValue: exports.minDate,
coerce: ec.coerceDateTime
},
{name: "Guid", encode: ec.encodeGuid, decode: ec.decodeGuid, defaultValue: emptyGuid},
{
break;
case DataType.Int16:
case DataType.UInt16:
case DataType.Int32:
case DataType.UInt32:
assert(value !== undefined);
if (isEnumerationItem(value)) {
// value is a enumeration of some sort
value = value.value;
} else {
value = parseInt(value, 10);
}
assert(_.isFinite(value), "expecting a number");
break;
case DataType.UInt64:
value = encode_decode.coerceUInt64(value);
break;
case DataType.Int64:
value = encode_decode.coerceInt64(value);
break;
case DataType.ExtensionObject:
break;
case DataType.DateTime:
assert(value === null || value instanceof Date);
break;
case DataType.String:
assert(typeof value === "string" || value === null);
break;
case DataType.ByteString:
value = (typeof value === "string") ? Buffer.from(value): value;
if (!(value === null || value instanceof Buffer)) {
throw new Error("ByteString should be null or a Buffer");
public setValue(value: string | number | Int64): void {
if (typeof value === "string") {
const enumValues = this.enumValues.readValue().value.value;
const selected = enumValues.filter((a: any) => a.displayName.text === value)[0];
if (selected) {
this._setValue(selected.value);
} else {
throw new Error("cannot find enum string " + value + " in " + enumValues.toString());
}
} else {
this._setValue(coerceUInt64(value));
}
}
name: "Int64",
decode: decodeInt64,
encode: encodeInt64,
coerce: coerceInt64,
defaultValue: coerceInt64(0)
},
{
name: "UInt64",
decode: decodeUInt64,
encode: encodeUInt64,
coerce: coerceUInt64,
defaultValue: coerceUInt64(0)
},
{
name: "Float",
decode: decodeFloat,
encode: encodeFloat,
coerce: coerceFloat,
defaultValue: 0.0
},
{
name: "Double",
decode: decodeDouble,
encode: encodeDouble,