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


TypeScript BinaryStream.readByteStream方法代碼示例

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


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

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

示例2: decodeByteString

export function decodeByteString(stream: BinaryStream): ByteString {
    return stream.readByteStream() as ByteString;
}
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:3,代碼來源:byte_string.ts


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