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


TypeScript BinaryStream.rewind方法代碼示例

本文整理匯總了TypeScript中node-opcua-binary-stream.BinaryStream.rewind方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript BinaryStream.rewind方法的具體用法?TypeScript BinaryStream.rewind怎麽用?TypeScript BinaryStream.rewind使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在node-opcua-binary-stream.BinaryStream的用法示例。


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

示例1: _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

示例2: encode_decode_round_trip_test

export function encode_decode_round_trip_test(obj: any, options: any, callback_buffer?: any) {

    if (!callback_buffer && _.isFunction(options)) {
        callback_buffer = options;
        options = {};
    }

    callback_buffer = callback_buffer || dump_block_in_debug_mode;

    should.exist(obj);

    const size = obj.binaryStoreSize(options);

    const stream = new BinaryStream(Buffer.alloc(size));

    obj.encode(stream, options);

    callback_buffer(stream.buffer, obj.encodingDefaultBinary, options);

    stream.rewind();

    // reconstruct a object ( some object may not have a default Binary and should be recreated
    const expandedNodeId = obj.encodingDefaultBinary;
    const objReloaded = expandedNodeId ? constructObject(expandedNodeId) : new obj.constructor();

    objReloaded.decode(stream, options);

    redirectToNull(() => analyze_object_binary_encoding(obj));
    compare(objReloaded, obj);
    return objReloaded;
}
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:31,代碼來源:encode_decode_round_trip_test.ts

示例3: randomGuid

export  function randomGuid(): Guid {
    const b = new BinaryStream(20);
    for (let i = 0; i < 20; i++) {
        b.writeUInt8(getRandomInt(0, 255));
    }
    b.rewind();
    const value = decodeGuid(b) as Guid;
    return value;
}
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:9,代碼來源:guid.ts

示例4: it

    it("should encode/decode an ArgumentList (scalar)", () => {

        const definition = [{dataType: DataType.UInt32}];
        const args = [100];

        const size = binaryStoreSize_ArgumentList(definition, args);
        size.should.equal(4, " the size of a single UInt32");

        const stream = new BinaryStream(size);
        encode_ArgumentList(definition, args, stream);

        stream.rewind();
        const args_reloaded = decode_ArgumentList(definition, stream);

        _.isArray(args_reloaded).should.equal(true);
        args_reloaded[0].should.eql(100);

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

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

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


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