• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript node-opcua-binary-stream.BinaryStream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中node-opcua-binary-stream.BinaryStream的典型用法代码示例。如果您正苦于以下问题:TypeScript BinaryStream类的具体用法?TypeScript BinaryStream怎么用?TypeScript BinaryStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了BinaryStream类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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


示例4: decodeExtensionObject

export function decodeExtensionObject(stream: BinaryStream): ExtensionObject | null {

    const nodeId = decodeNodeId(stream);
    const encodingType = stream.readUInt8();

    if (encodingType === 0) {
        return null;
    }

    const length = stream.readUInt32();

    /* istanbul ignore next */
    if (nodeId.value === 0 || encodingType === 0) {
        return {} as ExtensionObject;
    }

    // let verify that  decode will use the expected number of bytes
    const streamLengthBefore = stream.length;

    let object: any;
    if (nodeId.namespace !== 0) {
        // this is a extension object define in a other namespace
        // we can only threat it as an opaque object for the time being
        // the caller that may now more about the namespace Array and type
        // definition will be able to turn the opaque object into a meaningful
        // structure
        // lets rewind before the length
        stream.length -= 4;
        object = new OpaqueStructure(nodeId, stream.readByteStream()!);

    } else {
        object = constructEmptyExtensionObject(nodeId);
        /* istanbul ignore next */
        if (object === null) {
            // this object is unknown to us ..
            stream.length += length;
            object = {} as ExtensionObject;
        } else {
            try {
                object.decode(stream);
            } catch (err) {
                debugLog("Cannot decode object ", err.message);
            }
        }
    }

    if (streamLengthBefore + length !== stream.length) {
        // this may happen if the server or client do have a different OPCUA version
        // for instance SubscriptionDiagnostics structure has been changed between OPCUA version 1.01 and 1.04
        // causing 2 extra member to be added.
        debugLog(chalk.bgWhiteBright.red("========================================="));

        // tslint:disable-next-line:no-console
        console.warn("WARNING => Extension object decoding error on ",
          object.constructor.name, " expected size was", length,
          "but only this amount of bytes have been read :", stream.length - streamLengthBefore);
        stream.length = streamLengthBefore + length;
    }
    return object;
}
开发者ID:node-opcua,项目名称:node-opcua,代码行数:60,代码来源:extension_object.ts


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


示例6: readMessageHeader

export function readMessageHeader(stream: BinaryStream): MessageHeader {

    const msgType = String.fromCharCode(stream.readUInt8()) +
        String.fromCharCode(stream.readUInt8()) +
        String.fromCharCode(stream.readUInt8());

    const isFinal = String.fromCharCode(stream.readUInt8());
    const length = stream.readUInt32();
    return {msgType, isFinal, length};
}
开发者ID:node-opcua,项目名称:node-opcua,代码行数:10,代码来源:read_message_header.ts


示例7: write_header

    public write_header(finalC: string, buffer: Buffer, length: number): void {
        assert(buffer.length > 12);
        assert(finalC.length === 1);
        assert(buffer instanceof Buffer);

        const stream = new BinaryStream(buffer);

        // message header --------------------------
        // ---------------------------------------------------------------
        // OPC UA Secure Conversation Message Header : Part 6 page 36
        // MessageType     Byte[3]
        // IsFinal         Byte[1]  C : intermediate, F: Final , A: Final with Error
        // MessageSize     UInt32   The length of the MessageChunk, in bytes. This value includes size of the message header.
        // SecureChannelId UInt32   A unique identifier for the ClientSecureChannelLayer assigned by the server.

        stream.writeUInt8(this.msgType.charCodeAt(0));
        stream.writeUInt8(this.msgType.charCodeAt(1));
        stream.writeUInt8(this.msgType.charCodeAt(2));
        stream.writeUInt8(finalC.charCodeAt(0));

        stream.writeUInt32(length);
        stream.writeUInt32(this.channelId);

        assert(stream.length === 12);

        // write Security Header -----------------
        this.securityHeader.encode(stream);
        assert(stream.length === this.headerSize);
    }
开发者ID:node-opcua,项目名称:node-opcua,代码行数:29,代码来源:secure_message_chunk_manager.ts


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


示例9: _decode_enumeration

 this.decode = options.decode || function _decode_enumeration(stream: BinaryStream): EnumItem {
     const value = stream.readInteger();
     const e = typedEnum.get(value);
     // istanbul ignore next
     if (!e) {
         throw new Error("cannot  coerce value=" + value + " to " + typedEnum.constructor.name);
     }
     return e;
 };
开发者ID:node-opcua,项目名称:node-opcua,代码行数:9,代码来源:factories_enumerations.ts


示例10: encode_array

function encode_array(
  fun_encode_element: (el: any, stream: OutputBinaryStream) => void,
  arr: any[],
  stream: BinaryStream
) {
    stream.writeUInt32(arr.length);
    for (const el of arr) {
        fun_encode_element(el, stream);
    }
}
开发者ID:node-opcua,项目名称:node-opcua,代码行数:10,代码来源:extension_object_array_node.ts



注:本文中的node-opcua-binary-stream.BinaryStream类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap