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

TypeScript node-opcua-buffer-utils.createFastUninitializedBuffer函数代码示例 ...

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

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



在下文中一共展示了createFastUninitializedBuffer函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: constructor

 constructor(data: undefined | Buffer | number) {
     if (data === undefined) {
         this.buffer = createFastUninitializedBuffer(1024);
     } else if (typeof data === "number") {
         this.buffer = createFastUninitializedBuffer(data);
     } else {
         assert(data instanceof Buffer);
         this.buffer = data;
     }
     this.length = 0;
 }
开发者ID:node-opcua,项目名称:node-opcua,代码行数:11,代码来源:binaryStream.ts


示例2: randomByteString

export function randomByteString(value: any, len: number): ByteString {
    len = len || getRandomInt(1, 200);
    const b = createFastUninitializedBuffer(len);
    for (let i = 0; i < len; i++) {
        b.writeUInt8(getRandomInt(0, 255), i);
    }
    return b;
}
开发者ID:node-opcua,项目名称:node-opcua,代码行数:8,代码来源:byte_string.ts


示例3: packTcpMessage

export function packTcpMessage(msgType: string, encodableObject: BaseUAObject): Buffer {

    assert(is_valid_msg_type(msgType));

    const messageChunk = createFastUninitializedBuffer(encodableObject.binaryStoreSize() + 8);
    // encode encodeableObject in a packet
    const stream = new BinaryStream(messageChunk);
    encodeMessage(msgType, encodableObject, stream);

    return messageChunk;

}
开发者ID:node-opcua,项目名称:node-opcua,代码行数:12,代码来源:tools.ts


示例4: createChunk

    /**
     * ```createChunk``` is used to construct a pre-allocated chunk to store up to ```length``` bytes of data.
     * The created chunk includes a prepended header for ```chunk_type``` of size ```self.headerSize```.
     *
     * @method createChunk
     * @param msgType
     * @param chunkType {String} chunk type. should be 'F' 'C' or 'A'
     * @param length
     * @return {Buffer} a buffer object with the required length representing the chunk.
     *
     * Note:
     *  - only one chunk can be created at a time.
     *  - a created chunk should be committed using the ```write``` method before an other one is created.
     */
    public createChunk(msgType: string, chunkType: string, length: number): Buffer {

        assert(msgType === "MSG");
        assert(this._pendingBuffer === undefined, "createChunk has already been called ( use write first)");

        const totalLength = length + this.headerSize;
        const buffer = createFastUninitializedBuffer(totalLength);
        writeTCPMessageHeader("MSG", chunkType, totalLength, buffer);

        this._pendingBuffer = buffer;

        return buffer;
    }
开发者ID:node-opcua,项目名称:node-opcua,代码行数:27,代码来源:tcp_transport.ts


示例5: _append

    /**
     * append a message chunk
     * @method _append
     * @param chunk
     * @private
     */
    private _append(chunk: Buffer): boolean {

        if (this._hasReceivedError) {
            // the message builder is in error mode and further message chunks should be discarded.
            return false;
        }

        this.messageChunks.push(chunk);
        this.totalMessageSize += chunk.length;

        const binaryStream = new BinaryStream(chunk);

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

        assert(binaryStream.length >= 12);

        // verify message chunk length
        if (this.messageHeader.length !== chunk.length) {
            // tslint:disable:max-line-length
            return this._report_error(
              `Invalid messageChunk size: the provided chunk is ${chunk.length} bytes long but header specifies ${this.messageHeader.length}`);
        }

        // the start of the message body block
        const offsetBodyStart = binaryStream.length;

        // the end of the message body block
        const offsetBodyEnd = binaryStream.buffer.length;

        this.totalBodySize += (offsetBodyEnd - offsetBodyStart);
        this.offsetBodyStart = offsetBodyStart;

        // add message body to a queue
        // note : Buffer.slice create a shared memory !
        //        use Buffer.clone
        const sharedBuffer = chunk.slice(offsetBodyStart, offsetBodyEnd);
        const clonedBuffer = createFastUninitializedBuffer(sharedBuffer.length);

        sharedBuffer.copy(clonedBuffer, 0, 0);
        this.blocks.push(clonedBuffer);

        return true;
    }
开发者ID:node-opcua,项目名称:node-opcua,代码行数:51,代码来源:message_builder_base.ts


示例6: write

    public write(buffer: Buffer, length?: number) {

        length = length || buffer.length;
        assert(buffer instanceof Buffer || (buffer === null));
        assert(length > 0);

        let l = length;
        let inputCursor = 0;

        while (l > 0) {
            assert(length - inputCursor !== 0);

            if (this.cursor === 0) {
                this._push_pending_chunk(false);
            }

            // space left in current chunk
            const spaceLeft = this.maxBodySize - this.cursor;

            const nbToWrite = Math.min(length - inputCursor, spaceLeft);

            this.chunk = this.chunk || createFastUninitializedBuffer(this.chunkSize);

            if (buffer) {
                buffer.copy(this.chunk!, this.cursor + this.dataOffset, inputCursor, inputCursor + nbToWrite);
            }

            inputCursor += nbToWrite;
            this.cursor += nbToWrite;

            if (this.cursor >= this.maxBodySize) {
                this._post_process_current_chunk();
            }
            l -= nbToWrite;
        }
    }
开发者ID:node-opcua,项目名称:node-opcua,代码行数:36,代码来源:chunk_manager.ts


示例7: calculateByteLength

        this.length += bufLen;
        return str;
    }
}

/**
 * @function calculateByteLength
 * calculate the size in bytes of a utf8 string
 * @param str {String}
 * @internal
 */
export function calculateByteLength(str: string) {
    // returns the byte length of an utf8 string
    let s = str.length;
    for (let i = str.length - 1; i >= 0; i--) {
        const code = str.charCodeAt(i);
        if (code > 0x7f && code <= 0x7ff) {
            s++;
        } else if (code > 0x7ff && code <= 0xffff) {
            s += 2;
        }
        if (code >= 0xdc00 && code <= 0xdfff) {
            // trail surrogate
            i--;
        }
    }
    return s;
}

const zeroLengthBuffer = createFastUninitializedBuffer(0);
开发者ID:node-opcua,项目名称:node-opcua,代码行数:30,代码来源:binaryStream.ts


示例8: createUserNameIdentityToken

function createUserNameIdentityToken(
  session: ClientSessionImpl,
  userName: string | null,
  password: string | null
): UserNameIdentityToken {

    // assert(endpoint instanceof EndpointDescription);
    assert(userName === null || typeof userName === "string");
    assert(password === null || typeof password === "string");
    const endpoint = session.endpoint;
    assert(endpoint instanceof EndpointDescription);

    /**
     * OPC Unified Architecture 1.0.4:  Part 4 155
     * Each UserIdentityToken allowed by an Endpoint shall have a UserTokenPolicy specified in the
     * EndpointDescription. The UserTokenPolicy specifies what SecurityPolicy to use when encrypting
     * or signing. If this SecurityPolicy is omitted then the Client uses the SecurityPolicy in the
     * EndpointDescription. If the matching SecurityPolicy is set to None then no encryption or signature
     * is required.
     *
     */
    const userTokenPolicy = findUserTokenPolicy(endpoint, UserTokenType.UserName);

    // istanbul ignore next
    if (!userTokenPolicy) {
        throw new Error("Cannot find USERNAME user token policy in end point description");
    }

    let securityPolicy = fromURI(userTokenPolicy.securityPolicyUri);

    // if the security policy is not specified we use the session security policy
    if (securityPolicy === SecurityPolicy.Invalid) {
        securityPolicy = session._client._secureChannel.securityPolicy;
    }

    let identityToken;
    let serverCertificate: Buffer | string | null = session.serverCertificate;
    // if server does not provide certificate use unencrypted password
    if (!serverCertificate) {
        identityToken = new UserNameIdentityToken({
            encryptionAlgorithm: null,
            password: Buffer.from(password as string, "utf-8"),
            policyId: userTokenPolicy ? userTokenPolicy!.policyId : null,
            userName
        });
        return identityToken;
    }

    assert(serverCertificate instanceof Buffer);
    serverCertificate = toPem(serverCertificate, "CERTIFICATE");
    const publicKey = extractPublicKeyFromCertificateSync(serverCertificate);

    const serverNonce: Nonce = session.serverNonce || Buffer.alloc(0);
    assert(serverNonce instanceof Buffer);

    // If None is specified for the UserTokenPolicy and SecurityPolicy is None
    // then the password only contains the UTF-8 encoded password.
    // note: this means that password is sent in clear text to the server
    // note: OPCUA specification discourages use of unencrypted password
    //       but some old OPCUA server may only provide this policy and we
    //       still have to support in the client?
    if (securityPolicy === SecurityPolicy.None) {
        identityToken = new UserNameIdentityToken({
            encryptionAlgorithm: null,
            password: Buffer.from(password!, "utf-8"),
            policyId: userTokenPolicy.policyId,
            userName
        });
        return identityToken;
    }

    // see Release 1.02 155 OPC Unified Architecture, Part 4
    const cryptoFactory = getCryptoFactory(securityPolicy);

    // istanbul ignore next
    if (!cryptoFactory) {
        throw new Error(" Unsupported security Policy");
    }

    identityToken = new UserNameIdentityToken({
        encryptionAlgorithm: cryptoFactory.asymmetricEncryptionAlgorithm,
        password: Buffer.from(password as string, "utf-8"),
        policyId: userTokenPolicy.policyId,
        userName
    });

    // now encrypt password as requested
    const lenBuf = createFastUninitializedBuffer(4);
    lenBuf.writeUInt32LE(identityToken.password.length + serverNonce.length, 0);
    const block = Buffer.concat([lenBuf, identityToken.password, serverNonce]);
    identityToken.password = cryptoFactory.asymmetricEncrypt(block, publicKey);

    return identityToken;
}
开发者ID:node-opcua,项目名称:node-opcua,代码行数:94,代码来源:opcua_client_impl.ts



注:本文中的node-opcua-buffer-utils.createFastUninitializedBuffer函数示例由纯净天空整理自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