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)]
/**

 * **Uint8**
 * 
 * Represents an unsigned 8-bit ( 1 byte ) integer. ( 0 to 255 )
*/
pub struct Uint8 {}

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

   * **read**
   * 
   * Reads an unsigned 8-bit ( 1 byte ) integer from the stream. ( 0 to 255 )
  */
  pub fn read(stream: &mut BinaryStream) -> Result<u8> {
    let bytes = match stream.read(1) {
      Ok(bytes) => bytes,
      Err(err) => return Err(err)
    };
    
    Ok(bytes[0])
  }

  #[napi]
  /**

   * **write**
   * 
   * Writes an unsigned 8-bit ( 1 byte ) integer to the stream. ( 0 to 255 )
  */
  pub fn write(stream: &mut BinaryStream, value: u8) {
    stream.write(vec![value]);
  }
}

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