当前位置: 首页>>代码示例>>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;未经允许,请勿转载。