1.0.5 • Published 2 years ago

nv-buf-bi v1.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

nv-buf-bi

  • pure js, get bigint sign AND data-byte-length
  • for WriteVarInt -> WriteZigZag using
  • normally USELESS, used for encode/decode

refer to v8/src/objects/bigint.cc

    uint32_t BigInt::GetBitfieldForSerialization() const {
        static_assert(kMaxLength * kDigitSize <= LengthBits::kMax);
        int bytelength = length() * kDigitSize;
        return SignBits::encode(sign()) | LengthBits::encode(bytelength);
    } 

install

  • npm install nv-buf-bi

splitted

usage

  const  x  = require("nv-buf-bi");

example

    > x.get_encd_head(2n**(64n*4096n))
    32776
    > x.decd_encd_head(32776)
    { sign: 0, data_blen: 32776 }
    > 32776/8
    4097
    > 

    > var g = x.gen_body_if_pos(2n**64n)
    > g.next()
    { value: 0n, done: false }
    > g.next()
    { value: 1n, done: false }
    > g.next()
    { value: undefined, done: true }
    >

METHODS

APIS

        {
          count_if_pos: [Function: count_if_pos],
          data_byte_length_if_pos: [Function: data_byte_length_if_pos],
          count: [Function: count],
          data_byte_length: [Function: data_byte_length],
          get_encd_head: [Function: get_encd_head],
          decd_encd_head: [Function: decd_encd_head],
          gen_body_if_pos: [Function: gen_body_if_pos],
          gen_body: [Function: gen_body],
          use_with_get_var_int: [Function: use_with_get_var_int]
        }

LICENSE

  • ISC