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


TypeScript node-opcua-debug.hexDump函數代碼示例

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


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

示例1: _dump_simple_value

    function _dump_simple_value(self: any, field: StructuredTypeField, data: any, value: any, fieldType: string) {

        let str = "";
        if (value instanceof Buffer) {
            const _hexDump = hexDump(value);
            data.lines.push(fieldNameF + " " + fieldTypeF);
            data.lines.push("BUFFER{" + _hexDump + "}");

        } else {

            if (field.isArray) {
                str = fieldNameF + " " + fieldTypeF + ": " + _arrayEllipsis(value);
            } else {
                if (fieldType === "IntegerId" || fieldType === "UInt32") {
                    value = "" + value + "               0x" + value.toString(16);
                } else if (fieldType === "DateTime" || fieldType === "UtcTime") {
                    value = (value && value.toISOString) ? value.toISOString() : value;
                } else if (typeof value === "object" && value !== null && value !== undefined) {
                    value = value.toString.apply(value, args);
                }
                str = fieldNameF + " " + fieldTypeF + ": "
                  + ((value === null || value === undefined) ? chalk.blue("null") : value.toString());
            }
            data.lines.push(str);
        }
    }
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:26,代碼來源:factories_baseobject.ts

示例2: 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

示例3: switch

            trace: (operation: any, name: any, value: any, start: number, end: number, fieldType: string) => {

                const b = buffer.slice(start, end);
                let _hexDump = "";

                switch (operation) {

                    case "start":
                        padding += 2;
                        display(name.toString());
                        break;

                    case "end":
                        padding -= 2;
                        break;

                    case "start_array":
                        display("." + name + " (length = " + value + ") " + "[", hex_block(start, end, b));
                        padding += 2;
                        break;

                    case "end_array":
                        padding -= 2;
                        display("] // " + name);
                        break;

                    case "start_element":
                        display(" #" + value + " {");
                        padding += 2;
                        break;

                    case "end_element":
                        padding -= 2;
                        display(" } // # " + value);
                        break;

                    case "member":
                        display("." + name + " : " + fieldType);

                        _hexDump = "";
                        if (value instanceof Buffer) {
                            _hexDump = hexDump(value);
                            console.log(_hexDump);
                            value = "<BUFFER>";
                        }

                        if (value && value.encode) {
                            if (fieldType === "ExtensionObject") {
                                display_encodeable(value, buffer, start, end);
                            } else {
                                const str = value.toString() || "<empty>";
                                display(str);
                            }
                        } else {
                            display(" " + value, hex_block(start, end, b));
                        }
                        break;
                }
            },
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:59,代碼來源:packet_analyzer.ts

示例4: toString

 public toString(): string {
     const str =
       "/* OpaqueStructure */ { \n" +
       "nodeId " + this.nodeId.toString() + "\n" +
       "buffer = \n" + hexDump(this.buffer) + "\n" +
       "}";
     return str;
 }
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:8,代碼來源:extension_object.ts

示例5: debugLog

        this._mockTransport.server.on("data", (data: Buffer) => {

            let reply = this._replies[this._counter];
            this._counter++;
            if (reply) {

                if (_.isFunction(reply)) {
                    reply = reply.call(this);
                    // console.log(" interpreting reply as a function" + reply);
                    if (!reply) {
                        return;
                    }
                }

                debugLog("\nFAKE SERVER RECEIVED");
                debugLog(hexDump(data));

                let replies = [];
                if (reply instanceof Buffer) {
                    replies.push(reply);
                } else {
                    replies = reply;
                }
                assert(replies.length >= 1, " expecting at least one reply " + JSON.stringify(reply));
                replies.forEach((reply1: any) => {
                    debugLog("\nFAKE SERVER SEND");
                    debugLog(chalk.red(hexDump(reply1)));
                    this._mockTransport.server.write(reply1);
                });

            } else {
                const msg = " MockServerTransport has no more packets to send to client to" +
                  " emulate server responses.... ";
                console.log(chalk.red.bold(msg));
                console.log(chalk.blue.bold(hexDump(data)));

                display_trace_from_this_projet_only();
                analyseExtensionObject(data, 0, 0, {});

                this.emit("done");
            }
        });
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:42,代碼來源:mock_transport.ts

示例6: _read_headers

    protected _read_headers(binaryStream: BinaryStream): boolean {

        super._read_headers(binaryStream);

        assert(binaryStream.length === 12);

        const msgType = this.messageHeader.msgType;

        if (msgType === "HEL" || msgType === "ACK") {

            this.securityPolicy = SecurityPolicy.None;
        } else if (msgType === "ERR") {

            // extract Error StatusCode and additional message
            binaryStream.length = 8;
            const errorCode = decodeStatusCode(binaryStream);
            const message = decodeString(binaryStream);

            /* istanbul ignore next */
            if (doDebug) {
                debugLog(chalk.red.bold(" ERROR RECEIVED FROM SENDER"), chalk.cyan(errorCode.toString()), message);
                debugLog(hexDump(binaryStream.buffer));
            }
            return true;

        } else {

            this.securityHeader = chooseSecurityHeader(msgType);
            this.securityHeader.decode(binaryStream);

            if (msgType === "OPN") {
                const asymmetricAlgorithmSecurityHeader = this.securityHeader as AsymmetricAlgorithmSecurityHeader;
                this.securityPolicy = fromURI(asymmetricAlgorithmSecurityHeader.securityPolicyUri);
                this.cryptoFactory = getCryptoFactory(this.securityPolicy);
            }

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

            this.sequenceHeader = new SequenceHeader();
            this.sequenceHeader.decode(binaryStream);

            /* istanbul ignore next */
            if (doDebug) {
                debugLog(" Sequence Header", this.sequenceHeader);
            }

            this._validateSequenceNumber(this.sequenceHeader.sequenceNumber);
        }
        return true;
    }
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:52,代碼來源:message_builder.ts

示例7: it

    it("Q3 should encode and decode a method call request", async () => {

        const objectId = makeNodeId(999990, 0);
        const methodId = makeNodeId(999992, 0);

        const obj = addressSpace.findNode(objectId)! as UAObject;
        obj.nodeClass.should.eql(NodeClass.Object);

        const method = obj.getMethodById(methodId)!;
        method.nodeClass.should.eql(NodeClass.Method);
        method.browseName.toString().should.eql("DoStuff");

        const inputArguments = method.getInputArguments();
        inputArguments.should.be.instanceOf(Array);

        const callRequest = new CallRequest({

            methodsToCall: [{
                inputArguments: [{
                    dataType: DataType.UInt32,
                    value: [0xAA, 0xAB, 0xAC]
                }],
                methodId,
                objectId
            }]
        });

        const size = callRequest.binaryStoreSize();

        const stream = new BinaryStream(size);

        callRequest.encode(stream);

        if (doDebug) {
            console.log(hexDump(stream.buffer));
        }

        // now decode
        const callRequest_reloaded = new CallRequest();
        stream.rewind();
        callRequest_reloaded.decode(stream);

    });
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:43,代碼來源:test_method_service.ts

示例8: analyze_object_binary_encoding

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);

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

示例9: _safe_decode_message_body

    private _safe_decode_message_body(fullMessageBody: Buffer, objMessage: any, binaryStream: BinaryStream) {
        try {
            // de-serialize the object from the binary stream
            const options = this.objectFactory;
            objMessage.decode(binaryStream, options);
        } catch (err) {
            console.log(err);
            console.log(err.stack);
            console.log(hexDump(fullMessageBody));
            analyseExtensionObject(fullMessageBody, 0, 0);

            console.log(" ---------------- block");
            let i = 0;
            this.messageChunks.forEach((messageChunk) => {
                console.log(" ---------------- chunk i=", i++);
                console.log(hexDump(messageChunk));
            });
            return false;
        }
        return true;
    }
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:21,代碼來源:message_builder.ts

示例10: _arrayEllipsis

function _arrayEllipsis(value: any[] | null) {

    if (!value) {
        return "null []";
    } else {
        if (value.length === 0) {
            return "[ /* empty*/ ]";
        }
        assert(_.isArray(value));
        const v = [];
        const m = Math.min(_nbElements, value.length);
        for (let i = 0; i < m; i++) {
            let element = value[i];
            if (element instanceof Buffer) {
                element = hexDump(element, 32, 16);
            }
            v.push(!utils.isNullOrUndefined(element) ? element.toString() : null);
        }
        return "[ " + v.join(",") + (value.length > 10 ? " ... " : "") + "] (l=" + value.length + ")";
    }
}
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:21,代碼來源:factories_baseobject.ts


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