How to use the node-opcua-binary-stream.BinaryStream function in node-opcua-binary-stream

To help you get started, we’ve selected a few node-opcua-binary-stream 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-client-dynamic-extension-object / source / resolve_dynamic_extension_object.ts View on Github external
function resolveDynamicExtensionObjectV(
    opaque: OpaqueStructure,
    extraDataType: ExtraDataTypeManager
): ExtensionObject {

    try {
        const namespaceUri = extraDataType.namespaceArray[opaque.nodeId.namespace];
        const expandedNodeId = ExpandedNodeId.fromNodeId(opaque.nodeId, namespaceUri);

        const typeDictionary = extraDataType.getTypeDictionaryForNamespace(opaque.nodeId.namespace);

        const Constructor = extraDataType.getExtensionObjectConstructorFromBinaryEncoding(opaque.nodeId);
        const object = new Constructor();
        const stream = new BinaryStream(opaque.buffer);
        object.decode(stream);
        return object;
    } catch (err) {
        // tslint:disable-next-line:no-console
        console.log("resolveDynamicExtensionObjectV err = ", err);
        return opaque;
    }
}
github node-opcua / node-opcua / packages / node-opcua-transport / source / tools.ts View on Github external
export function writeTCPMessageHeader(msgType: string, chunkType: string, totalLength: number, stream: OutputBinaryStream) {

    if (stream instanceof Buffer) {
        stream = new BinaryStream(stream);
    }
    assert(is_valid_msg_type(msgType));
    assert(["A", "F", "C"].indexOf(chunkType) !== -1);

    stream.writeUInt8(msgType.charCodeAt(0));
    stream.writeUInt8(msgType.charCodeAt(1));
    stream.writeUInt8(msgType.charCodeAt(2));
    // Chunk type
    stream.writeUInt8(chunkType.charCodeAt(0)); // reserved

    stream.writeUInt32(totalLength);
}
github node-opcua / node-opcua / packages / node-opcua-transport / source / message_builder_base.ts View on Github external
private _append(chunk: Buffer): boolean {

        if (this._hasReceivedError) {
            // the message builder is in error mode and further message chunks should be discarded.
            return false;
        }

        this.messageChunks.push(chunk);
        this.totalMessageSize += chunk.length;

        const binaryStream = new BinaryStream(chunk);

        if (!this._read_headers(binaryStream)) {
            return false;
        }

        assert(binaryStream.length >= 12);

        // verify message chunk length
        if (this.messageHeader.length !== chunk.length) {
            // tslint:disable:max-line-length
            return this._report_error(
                `Invalid messageChunk size: the provided chunk is ${chunk.length} bytes long but header specifies ${this.messageHeader.length}`);
        }

        // the start of the message body block
        const offsetBodyStart = binaryStream.length;
github node-opcua / node-opcua / packages / node-opcua-secure-channel / source / message_chunker.ts View on Github external
public chunkSecureMessage(
        msgType: string,
        options: ChunkMessageOptions,
        message: BaseUAObject,
        messageChunkCallback: MessageCallbackFunc) {

        assert(_.isFunction(messageChunkCallback));

        // calculate message size ( with its  encodingDefaultBinary)
        const binSize = message.binaryStoreSize() + 4;

        const stream = new BinaryStream(binSize);
        this._stream = stream;

        encodeExpandedNodeId(message.schema.encodingDefaultBinary!, stream);
        message.encode(stream);

        let securityHeader;
        if (msgType === "OPN") {
            securityHeader = this.securityHeader;
        } else {
            securityHeader = new SymmetricAlgorithmSecurityHeader({tokenId: options.tokenId});
        }

        const chunkManager = new SecureMessageChunkManager(
            msgType, options, securityHeader, this.sequenceNumberGenerator
        );
github node-opcua / node-opcua / packages / node-opcua-secure-channel / source / secure_message_chunk_manager.ts View on Github external
public writeSequenceHeader(buffer: Buffer) {
        const stream = new BinaryStream(buffer);
        // write Sequence Header -----------------
        this.sequenceHeader.sequenceNumber = this.sequenceNumberGenerator.next();
        this.sequenceHeader.encode(stream);
        assert(stream.length === 8);
    }
github node-opcua / node-opcua / packages / node-opcua-transport / src / message_builder_base.js View on Github external
MessageBuilderBase.prototype._append = function (message_chunk) {

    if (this.status_error) {
        // the message builder is in error mode and further message chunks should be discarded.
        return false;
    }

    this.message_chunks.push(message_chunk);
    this.total_message_size += message_chunk.length;

    const binaryStream = new BinaryStream(message_chunk);

    if (!this._read_headers(binaryStream)) {
        return false;
    }
    assert(binaryStream.length >= 12);

    // verify message chunk length
    if (this.messageHeader.length !== message_chunk.length) {
        return this._report_error("Invalid messageChunk size: " +
            "the provided chunk is " + message_chunk.length + " bytes long " +
            "but header specifies " + this.messageHeader.length);
    }

    // the start of the message body block
    const offsetBodyStart = binaryStream.length;
github node-opcua / node-opcua / packages / node-opcua-packet-analyzer / test_helpers / compare_obj_by_encoding.ts View on Github external
function encoded(obj: BaseUAObject) {
        const stream = new BinaryStream(obj.binaryStoreSize());
        obj.encode(stream);
        return stream.buffer.toString("hex");
    }
    encoded(obj1).should.eql(encoded(obj2));
github node-opcua / node-opcua / packages / node-opcua-packet-analyzer / source / packet_analyzer / packet_analyzer.ts View on Github external
export function analyze_object_binary_encoding(obj: BaseUAObject) {

    assert(obj);

    const size = obj.binaryStoreSize();
    console.log("-------------------------------------------------");
    console.log(" size = ", size);
    const stream = new BinaryStream(size);
    obj.encode(stream);

    stream.rewind();
    console.log("-------------------------------------------------");
    if (stream.buffer.length < 256) {
        console.log(hexDump(stream.buffer));
        console.log("-------------------------------------------------");
    }

    const reloadedObject = new (obj.constructor as any)();
    analyzePacket(stream.buffer, reloadedObject, 0);

}
github node-opcua / node-opcua / packages / node-opcua-chunkmanager / src / chunk_manager.js View on Github external
function verify_message_chunk(message_chunk) {
    assert(message_chunk);
    assert(message_chunk instanceof Buffer);
    const header = readMessageHeader(new BinaryStream(message_chunk));
    if (message_chunk.length !== header.length) {
        throw new Error(" chunk length = " + message_chunk.length + " message  length " + header.length);
    }
}
github node-opcua / node-opcua / packages / node-opcua-packet-analyzer / source / packet_analyzer / packet_analyzer.ts View on Github external
export function analyzePacket(buffer: Buffer, objMessage: any, padding: number, offset?: number, customOptions?: AnalyzePacketOptions) {
    const stream = new BinaryStream(buffer);
    _internalAnalyzePacket(buffer, stream, objMessage, padding, customOptions, offset);
}

node-opcua-binary-stream

pure nodejs OPCUA SDK - module binary-stream

MIT
Latest version published 2 months ago

Package Health Score

79 / 100
Full package analysis