How to use the node-opcua-factory.buildStructuredType 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
return new LocalizedText({ locale: null, text: value });
    }
    if (value instanceof LocalizedText) {
        return value;
    }
    if (!value.hasOwnProperty("text")) {
        // tslint:disable:no-console
        console.log("value = ", value);
        throw new Error("cannot coerce to coerceLocalizedText");
    }
    return new LocalizedText(value);
}

// --------------------------------------------------------------------------------------------
// see Part 3 - $8.5 page 63
const schemaLocalizedText = buildStructuredType({
    name: "LocalizedText",

    baseType: "BaseUAObject",

    fields: [
        {
            name: "locale",

            fieldType: "LocaleId"
        },
        {
            name: "text",

            fieldType: "UAString",

            defaultValue: () => null
github node-opcua / node-opcua / packages / node-opcua-schemas / source / tools.ts View on Github external
if ((fieldTypeName === "UAString" || fieldTypeName === "String") && field.name === "IndexRange") {
                        field.fieldType = "NumericRange";
                        // xx console.log(" NumericRange detected here !");
                    } else {
                        field.fieldType = fieldTypeName;
                    }
                    if (!hasBuiltInType(fieldTypeName)) {
                        throw new Error("Unknown basic type " + fieldTypeName);
                    }
                    field.category = FieldCategory.basic;
                    break;
            }
        }
    }

    structuredTypeSchema = buildStructuredType(structuredType as StructuredTypeOptions);
    typeDictionary.structuredTypes[name] = structuredTypeSchema;
    return structuredTypeSchema;

}
github node-opcua / node-opcua / packages / node-opcua-chunkmanager / source / SequenceHeader.ts View on Github external
/***
 * @module node-opcua-chunkmanager
 */
import { decodeUInt32, encodeUInt32, UInt32 } from "node-opcua-basic-types";
import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
import {
    BaseUAObject,
    buildStructuredType,
    check_options_correctness_against_schema, initialize_field,
    parameters, StructuredTypeSchema,
} from "node-opcua-factory";

const schemaSequenceHeader: StructuredTypeSchema = buildStructuredType({
    baseType: "BaseUAObject",
    fields: [
        // A monotonically increasing sequence number assigned by the sender to each
        // MessageChunk sent over the ClientSecureChannelLayer.
        {name: "sequenceNumber", fieldType: "UInt32"},
        // An identifier assigned by the client to OPC UA request Message. All MessageChunks for
        // the request and the associated response use the same identifier.
        {name: "requestId", fieldType: "UInt32"},
    ],
    name: "SequenceHeader",
});

export class SequenceHeader extends BaseUAObject {

    public static possibleFields: string[] = ["sequenceNumber", "requestId"];
    public static schema = schemaSequenceHeader;
github node-opcua / node-opcua / packages / node-opcua-service-secure-channel / source / AsymmetricAlgorithmSecurityHeader.ts View on Github external
import {
    ByteString,
    decodeByteString,
    decodeString,
    encodeByteString,
    encodeString,
    UAString
} from "node-opcua-basic-types";
import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
import {
    BaseUAObject,
    buildStructuredType, check_options_correctness_against_schema,
    initialize_field, parameters, StructuredTypeSchema
} from "node-opcua-factory";

const schemaAsymmetricAlgorithmSecurityHeader: StructuredTypeSchema = buildStructuredType({
    name: "AsymmetricAlgorithmSecurityHeader",

    baseType: "BaseUAObject",

    fields: [
        // length shall not exceed 256
        // The URI of the security policy used to secure the message.
        // This field is encoded as a UTF8 string without a null terminator
        { name: "securityPolicyUri", fieldType: "String" },

        // The X509v3 certificate assigned to the sending application instance.
        // This is a DER encoded blob.
        // This indicates what private key was used to sign the MessageChunk.
        // This field shall be null if the message is not signed.
        // The structure of an X509 Certificate is defined in X509.
        // The DER format for a Certificate is defined in X690
github node-opcua / node-opcua / packages / node-opcua-variant / source / variant.ts View on Github external
findBuiltInType,
  initialize_field,
  initialize_field_array,
  registerSpecialVariantEncoder,
  StructuredTypeSchema
} from "node-opcua-factory";

import * as utils from "node-opcua-utils";

import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
import { ExtensionObject } from "node-opcua-extension-object";
import { _enumerationDataType, DataType } from "./DataType_enum";
import { _enumerationVariantArrayType, VariantArrayType } from "./VariantArrayType_enum";
// tslint:disable:no-bitwise

const schemaVariant: StructuredTypeSchema = buildStructuredType({
  baseType: "BaseUAObject",
  fields: [{
    defaultValue: () => DataType.Null,
    documentation: "the variant type.",
    fieldType: "DataType",
    name: "dataType",
  }, {
    defaultValue: VariantArrayType.Scalar,
    fieldType: "VariantArrayType",
    name: "arrayType",
  }, {
    defaultValue: null,
    fieldType: "Any",
    name: "value",
  }, {
    defaultValue: null,
github node-opcua / node-opcua / packages / node-opcua-data-value / source / datavalue.ts View on Github external
function isValidDataValue(self: DataValue): boolean {

  if (_.isObject(self.value)) {
    assert(self.value);
    return self.value.isValid();
  } else {
    assert(!self.value);
    // in this case StatusCode shall not be Good
    assert(self.statusCode !== StatusCodes.Good);
  }
  return true;
}

// OPC-UA part 4 -  $7.7
const schemaDataValue: StructuredTypeSchema = buildStructuredType({
  baseType: "BaseUAObject",
  name: "DataValue",

  fields: [
    { name: "value", fieldType: "Variant", defaultValue: null },
    { name: "statusCode", fieldType: "StatusCode", defaultValue: StatusCodes.Good },
    { name: "sourceTimestamp", fieldType: "DateTime", defaultValue: null },
    { name: "sourcePicoseconds", fieldType: "UInt16", defaultValue: 0 },
    { name: "serverTimestamp", fieldType: "DateTime", defaultValue: null },
    { name: "serverPicoseconds", fieldType: "UInt16", defaultValue: 0 }
  ]
});

export interface DataValueOptions {
  value?: VariantOptions;
  statusCode?: StatusCode;
github node-opcua / node-opcua / packages / node-opcua-service-secure-channel / source / SymmetricAlgorithmSecurityHeader.ts View on Github external
/**
 * @module node-opcua-service-secure-channel
 */
// Symmetric algorithms are used to secure all messages other than the OpenSecureChannel messages
// OPC UA Secure Conversation Message Header Release 1.02 Part 6 page 39
import { decodeUInt32, encodeUInt32, UInt32 } from "node-opcua-basic-types";
import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
import {
    BaseUAObject,
    buildStructuredType,
    initialize_field, StructuredTypeSchema
} from "node-opcua-factory";

const schemaSymmetricAlgorithmSecurityHeader: StructuredTypeSchema = buildStructuredType({
    name: "SymmetricAlgorithmSecurityHeader",

    baseType: "BaseUAObject",

    fields: [
        // A unique identifier for the ClientSecureChannelLayer token used to secure the message
        // This identifier is returned by the server in an OpenSecureChannel response message. If a
        // Server receives a TokenId which it does not recognize it shall return an appropriate
        // transport layer error.
        {name: "tokenId", fieldType: "UInt32", defaultValue: 0xDEADBEEF}
    ]
});

export class SymmetricAlgorithmSecurityHeader extends BaseUAObject {

    public static possibleFields: string[] = ["tokenId"];
github node-opcua / node-opcua / packages / node-opcua-data-model / source / diagnostic_info.ts View on Github external
import {
    decodeByte,
    decodeInt32,
    decodeStatusCode, decodeString,
    encodeByte, encodeInt32,
    encodeStatusCode, encodeString,
    Int32, UAString
} from "node-opcua-basic-types";
import {
    check_options_correctness_against_schema,
    initialize_field
} from "node-opcua-factory";

// --------------------------------------------------------------------------------------------
export const schemaDiagnosticInfo: StructuredTypeSchema = buildStructuredType({
    name: "DiagnosticInfo",

    baseType: "BaseUAObject",

    fields: [
        {
            name: "namespaceUri",

            fieldType: "Int32",

            defaultValue: -1,
            documentation: "The symbolicId is defined within the context of a namespace."
        },
        {
            name: "symbolicId",
github node-opcua / node-opcua / packages / node-opcua-data-model / source / qualified_name.ts View on Github external
registerSpecialVariantEncoder,
    StructuredTypeSchema
} from "node-opcua-factory";

import * as _ from "underscore";

import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
import { ExpandedNodeId, makeExpandedNodeId } from "node-opcua-nodeid";

import {
    decodeUAString, decodeUInt16, encodeUAString,
    encodeUInt16, Int32,
    UAString, UInt16
} from "node-opcua-basic-types";

export const schemaQualifiedName = buildStructuredType({
    baseType: "BaseUAObject",
    name: "QualifiedName",

    fields: [
        {
            name: "namespaceIndex",

            fieldType: "UInt16"
        },
        {
            name: "name",

            fieldType: "UAString",

            defaultValue: () => null
        }