繁体   English   中英

javascript bigint到byte数组

[英]javascript bigint to byte array

新的JavaScript原生BigInt实现描述了一个抽象方法NumberToRawBytes提出了一种通过显式字节序创建字节数组的便捷方法:

https://tc39.github.io/proposal-bigint/#sec-typedarrays-and-dataview

js API中已经可以使用它吗? 例如,JavaScript是否具有一些实现该接口的“数组”接口?

在/ lib下的Typescript中查看lib.esnext.bigint.d.ts文件,我在底部的“接口DataView”中找到了。

我认为这就是您和我想要的!

interface DataView {
    /**
      * Gets the BigInt64 value at the specified byte offset from the start of the view. There is
      * no alignment constraint; multi-byte values may be fetched from any offset.
      * @param byteOffset The place in the buffer at which the value should be retrieved.
      */
    getBigInt64(byteOffset: number, littleEndian?: boolean): bigint;

    /**
      * Gets the BigUint64 value at the specified byte offset from the start of the view. There is
      * no alignment constraint; multi-byte values may be fetched from any offset.
      * @param byteOffset The place in the buffer at which the value should be retrieved.
      */
    getBigUint64(byteOffset: number, littleEndian?: boolean): bigint;

    /**
      * Stores a BigInt64 value at the specified byte offset from the start of the view.
      * @param byteOffset The place in the buffer at which the value should be set.
      * @param value The value to set.
      * @param littleEndian If false or undefined, a big-endian value should be written,
      * otherwise a little-endian value should be written.
      */
    setBigInt64(byteOffset: number, value: bigint, littleEndian?: boolean): void;

    /**
      * Stores a BigUint64 value at the specified byte offset from the start of the view.
      * @param byteOffset The place in the buffer at which the value should be set.
      * @param value The value to set.
      * @param littleEndian If false or undefined, a big-endian value should be written,
      * otherwise a little-endian value should be written.
      */
    setBigUint64(byteOffset: number, value: bigint, littleEndian?: boolean): void;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM