How to use the node-opcua-factory.FieldCategory.enumeration 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-schemas / source / tools.ts View on Github external
structuredType.baseType = structuredType.baseType ? structuredType.baseType : "BaseUAObject";

    for (const field of structuredType.fields) {
        const fieldType = field.fieldType;
        if (!field.schema) {

            const prefix = getNamespacePart(fieldType);
            const fieldTypeName = adjustFieldTypeName(removeNamespacePart(fieldType)!);

            switch (prefix) {
                case "tns":

                    field.fieldType = fieldTypeName;
                    const enumeratedType = typeDictionary.enumeratedTypes[fieldTypeName];
                    if (enumeratedType) {
                        field.category = FieldCategory.enumeration;
                        field.schema = enumeratedType;

                    } else {
                        // must be a structure then ....
                        field.category = FieldCategory.complex;
                        field.schema = getOrCreateStructuredTypeSchema(fieldTypeName, typeDictionary);
                        if (!field.schema) {
                            // tslint:disable-next-line:no-console
                            console.log("cannot find schema for ", fieldTypeName);
                        }
                    }
                    break;
                case "ua":
                    field.fieldType = fieldTypeName;
                    if (hasBuiltInType(fieldTypeName)) {
                        field.category = FieldCategory.basic;
github node-opcua / node-opcua / packages / node-opcua-generator / source / generate_extension_object_code.ts View on Github external
function processStructuredType(structuredType: StructuredTypeSchema): void {
            if (alreadyDone[structuredType.name]) {
                return;
            }
            alreadyDone[structuredType.name] = structuredType;
            // make sure
            if (typeDictionary.structuredTypes[structuredType.baseType]) {
                processStructuredType(typeDictionary.structuredTypes[structuredType.baseType]);
            }

            for (const field of structuredType.fields) {
                if (field.category === FieldCategory.complex) {
                    const fieldSchema = typeDictionary.structuredTypes[field.fieldType];
                    processStructuredType(fieldSchema);
                }
                if (field.category === FieldCategory.enumeration) {
                    const fieldSchema = typeDictionary.enumeratedTypes[field.fieldType];
                    processEnumeratedType(fieldSchema);
                }
            }
            writeStructuredTypeWithSchema(structuredType);
        }
github node-opcua / node-opcua / packages / node-opcua-address-space / src / extension_object_array_node.ts View on Github external
field.$$initialize$$ = initialize_array.bind(null, field.$$initialize$$);
            field.$$func_encode$$ = encode_array.bind(null, field.$$func_encode$$);
            field.$$func_decode$$ = decode_array.bind(null, field.$$func_decode$$);
        }
    }

    // reconstruct _schema form
    const fields = [];
    for (const field of dataType.definition) {
        const data: any = {
            fieldType: field.$$dataType$$.browseName.name,
            isArray: (field.valueRank === 1),
            name: field.$$name$$
        };
        if (field.$$isEnum$$) {
            data.category = FieldCategory.enumeration;
        } else if (field.$$isStructure$$) {
            data.category = FieldCategory.complex;
            data.fieldTypeConstructor = field.$$Constructor$$;
        } else {
            data.category = FieldCategory.basic;
        }
        fields.push(data);
    }

    Constructor.prototype.schema = {
        fields,
        id: -1,
        name: className
    };
    return Constructor;
}
github node-opcua / node-opcua / packages / node-opcua-schemas / source / dynamic_extension_object.ts View on Github external
// write
        stream.writeUInt32(bitField);
    }

    for (const field of schema.fields) {

        // ignore
        if (field.switchBit !== undefined && (thisAny)[field.name] === undefined) {
            continue;
        }

        switch (field.category) {
            case FieldCategory.complex:
                encodeArrayOrElement(field, thisAny, stream);
                break;
            case FieldCategory.enumeration:
            case FieldCategory.basic:
                encodeArrayOrElement(field, thisAny, stream, field.schema.encode);
                break;
            default:
                /* istanbul ignore next*/
                throw new Error("Invalid category " + field.category + " " + FieldCategory[field.category]);
        }
    }

}
function decodeFields(
github node-opcua / node-opcua / packages / node-opcua-generator / source / factory_code_generator.ts View on Github external
write("     * encode the object into a binary stream");
            write("     * @method encode");
            write("     *");
            write("     * @param stream {BinaryStream}");
            write("     */");
        }
        write("     public encode(stream: OutputBinaryStream): void {");
        write("        super.encode(stream);");

        const n = schema.fields.length;
        for (let i = 0; i < n; i++) {
            const field = schema.fields[i];
            const member = field.name;

            switch (field.category) {
                case FieldCategory.enumeration:
                case FieldCategory.basic:
                    if (field.isArray) {
                        write(`        encodeArray(this.${member}, stream, encode${field.fieldType});`);
                    } else {
                        write(`        encode${field.fieldType}(this.${member}, stream);`);
                    }
                    break;
                case FieldCategory.complex:
                    if (field.isArray) {
                        write(
                          `        encodeArray(this.${member}, stream, (obj, stream1) => { obj.encode(stream1); });`);
                    } else {
                        write(`        this.${member}.encode(stream);`);
                    }
                    break;
            }
github node-opcua / node-opcua / packages / node-opcua-generator / source / factory_code_generator.ts View on Github external
function write_class_constructor_options(write: WriteFunc, schema: StructuredTypeSchema): void {

    const n = schema.fields.length;
    for (let i = 0; i < n; i++) {
        const field = schema.fields[i];
        const member = field.name;

        const arrayOpt = field.isArray ? "[] | null" : "";

        switch (field.category) {
            case FieldCategory.enumeration: {
                write(`    ${member}?: ${field.fieldType}${arrayOpt};`);
                break;
            }
            case FieldCategory.basic: {
                if (field.fieldType === "ExtensionObject") {
                    write(`    ${member}?: (${field.fieldType} | null)${arrayOpt};`);
                } else if (
                    field.fieldType === "Variant" || 
                    field.fieldType === "DataValue" || 
                    field.fieldType === "NodeId" || 
                    field.fieldType === "QualifiedName" || 
                    field.fieldType === "LocalizedText"
                ) {
                    write(`    ${member}?: (${field.fieldType}Like | null)${arrayOpt};`);
                } else {
                    write(`    ${member}?: ${field.fieldType} ${arrayOpt};`);