binarystream 2.6.10

A simple binary stream for Node.js
Documentation
use napi_derive::napi;
use napi::{bindgen_prelude::FromNapiValue, Result};
use crate::binary::BinaryStream;

#[napi]
#[derive(Clone)]
/**

 * **Bool**
 * 
 * Represents a boolean value. ( true or false )
*/
pub struct Bool {}

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

   * **read**
   * 
   * Reads a boolean ( 1 byte ) value from the stream. ( true or false )
  */
  pub fn read(stream: &mut BinaryStream) -> Result<bool> {
    let bytes = match stream.read(1) {
      Ok(bytes) => bytes,
      Err(err) => return Err(err)
    };
    
    Ok(bytes[0] != 0)
  }

  #[napi]
  /**

   * **write**
   * 
   * Writes a boolean ( 1 byte ) value to the stream. ( true or false )
  */
  pub fn write(stream: &mut BinaryStream, value: bool) {
    let value = match value {
      true => 1,
      false => 0,
    };
    
    stream.write(vec![value])
  }
}

impl FromNapiValue for Bool {
  unsafe fn from_napi_value(_: napi::sys::napi_env, _: napi::sys::napi_value) -> Result<Self> {
    Ok(Bool {})
  }
}