binarystream 1.2.0

Binarystream is a simple package designed to simplify streaming of binary data in Javascript, while being written in Rust.
Documentation
use napi_derive::napi;
use crate::binary::BinaryStream;
use crate::types::VarInt;

#[napi]
/**

 * **ZigZag**
 * 
 * Represents a 32 bit ( 4 bytes ) zigzag encoded signed variable length integer. ( -2147483648 to 2147483647 )
*/
pub struct ZigZag {}

#[napi]
impl ZigZag {
  #[napi]
  /**

   * **read**
   * 
   * Reads a 32 bit ( 4 bytes ) zigzag encoded signed variable length integer from the stream. ( -2147483648 to 2147483647 )
  */
  pub fn read(stream: &mut BinaryStream) -> i32 {
    let value = VarInt::read(stream);

    return ((value >> 1) as i32) ^ (-((value & 1) as i32))
  }

  #[napi]
  /**

   * **write**
   * 
   * Writes a 32 bit ( 4 bytes ) zigzag encoded signed variable length integer to the stream. ( -2147483648 to 2147483647 )
  */
  pub fn write(stream: &mut BinaryStream, value: i32) {
    let value = ((value << 1) ^ (value >> 31)) as u32;
    VarInt::write(stream, value);
  }
}