當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript node-opcua-chunkmanager.readMessageHeader函數代碼示例

本文整理匯總了TypeScript中node-opcua-chunkmanager.readMessageHeader函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript readMessageHeader函數的具體用法?TypeScript readMessageHeader怎麽用?TypeScript readMessageHeader使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了readMessageHeader函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: messageHeaderToString

export function messageHeaderToString(messageChunk: Buffer): string {

    const stream = new BinaryStream(messageChunk);

    const messageHeader = readMessageHeader(stream);
    if (messageHeader.msgType === "ERR" || messageHeader.msgType === "HEL") {
        return messageHeader.msgType + " " + messageHeader.isFinal + " length   = " + messageHeader.length;
    }

    const securityHeader = chooseSecurityHeader(messageHeader.msgType);

    const sequenceHeader = new SequenceHeader();
    assert(stream.length === 8);

    const channelId = stream.readUInt32();
    securityHeader.decode(stream);
    sequenceHeader.decode(stream);

    const slice = messageChunk.slice(0, stream.length);

    return messageHeader.msgType + " " +
        messageHeader.isFinal +
        " length   = " + messageHeader.length +
        " channel  = " + channelId +
        " seqNum   = " + sequenceHeader.sequenceNumber +
        " req ID   = " + sequenceHeader.requestId +
        " security   = " + securityHeader.toString() +
        "\n\n" + hexDump(slice);
}
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:29,代碼來源:message_header_to_string.ts

示例2: _handle_ACK_response

    private _handle_ACK_response(messageChunk: Buffer, callback: ErrorCallback) {

        const _stream = new BinaryStream(messageChunk);
        const messageHeader = readMessageHeader(_stream);
        let err;
        if (messageHeader.isFinal !== "F") {
            err = new Error(" invalid ACK message");
            return callback(err);
        }

        let responseClass;
        let response;

        if (messageHeader.msgType === "ERR") {
            responseClass = TCPErrorMessage;
            _stream.rewind();
            response = decodeMessage(_stream, responseClass) as TCPErrorMessage;

            err = new Error("ACK: ERR received " + response.statusCode.toString() + " : " + response.reason);
            (err as any).statusCode = response.statusCode;
            callback(err);

        } else {
            responseClass = AcknowledgeMessage;
            _stream.rewind();
            response = decodeMessage(_stream, responseClass);
            this.parameters = response;
            callback();
        }

    }
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:31,代碼來源:client_tcp_transport.ts

示例3: readRawMessageHeader

export function readRawMessageHeader(data: Buffer): PacketInfo {
    const messageHeader = readMessageHeader(new BinaryStream(data));
    return {
        extra: "",
        length: messageHeader.length,
        messageHeader
    };
}
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:8,代碼來源:message_builder_base.ts

示例4: _read_headers

    protected _read_headers(binaryStream: BinaryStream): boolean {

        this.messageHeader = readMessageHeader(binaryStream);
        assert(binaryStream.length === 8, "expecting message header to be 8 bytes");

        this.channelId = binaryStream.readUInt32();
        assert(binaryStream.length === 12);

        // verifying secure ChannelId
        if (this._expectedChannelId && this.channelId !== this._expectedChannelId) {
            return this._report_error("Invalid secure channel Id");
        }
        return true;
    }
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:14,代碼來源:message_builder_base.ts

示例5: _feed_messageChunk

    private _feed_messageChunk(chunk: Buffer) {
        assert(chunk);
        const messageHeader = readMessageHeader(new BinaryStream(chunk));
        /**
         * notify the observers that new message chunk has been received
         * @event chunk
         * @param messageChunk the raw message chunk
         */
        this.emit("chunk", chunk);

        if (messageHeader.isFinal === "F") {

            // last message
            this._append(chunk);
            if (this._hasReceivedError) {
                return false;
            }

            const fullMessageBody: Buffer = this.blocks.length === 1 ? this.blocks[0] : Buffer.concat(this.blocks);

            if (doPerfMonitoring) {
                // record tick 1: when a complete message has been received ( all chunks assembled)
                this._tick1 = get_clock_tick();
            }
            /**
             * notify the observers that a full message has been received
             * @event full_message_body
             * @param full_message_body the full message body made of all concatenated chunks.
             */
            this.emit("full_message_body", fullMessageBody);

            this._decodeMessageBody(fullMessageBody);

            // be ready for next block
            this._init_new();
            return true;

        } else if (messageHeader.isFinal === "A") {
            return this._report_error("received and Abort Message");

        } else if (messageHeader.isFinal === "C") {
            return this._append(chunk);
        }
        return false;
    }
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:45,代碼來源:message_builder_base.ts

示例6: decodeMessage

export function decodeMessage(stream: BinaryStream, classNameConstructor: ConstructorFunc): BaseUAObject {

    assert(stream instanceof BinaryStream);
    assert(classNameConstructor instanceof Function, " expecting a function for " + classNameConstructor);

    const header = readMessageHeader(stream);
    assert(stream.length === 8);

    let obj;
    if (header.msgType === "ERR") {
        obj = new TCPErrorMessage();
        obj.decode(stream);
        return obj;
    } else {
        obj = new classNameConstructor();
        obj.decode(stream);
        return obj;
    }
}
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:19,代碼來源:tools.ts


注:本文中的node-opcua-chunkmanager.readMessageHeader函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。