Skip to main content

StreamReader

Struct StreamReader 

Source
pub struct StreamReader<'a> {
    pub base_stream: &'a mut dyn Stream,
    /* private fields */
}
Expand description

reader stream struct

Fields§

§base_stream: &'a mut dyn Stream

Implementations§

Source§

impl<'a> StreamReader<'a>

Source

pub fn from(stream: &'a mut dyn Stream) -> Result<StreamReader<'a>, String>

from stream use LittleEndian reader integer

§Examples
 use iostream::io::*;
 let mut ms=MemoryStream::new();
 //...write data to ms
 let mut ws: StreamReader = StreamReader::from(&mut ms).unwrap();
Source

pub fn from_big_endian( stream: &'a mut dyn Stream, ) -> Result<StreamReader<'a>, String>

from stream use BigEndian reader integer

§Examples
 use iostream::io::*;
 let mut ms=MemoryStream::new();
 //...write data to ms
 let mut ws: StreamReader = StreamReader::from_big_endian(&mut ms).unwrap();
Source

pub fn peek(&mut self) -> Result<u8, StreamError>

peek the current stream next byte

Source

pub fn read_byte(&mut self) -> Result<u8, StreamError>

read u8 from stream

Source

pub fn read_all(&mut self, buf: &mut Vec<u8>) -> Result<usize, StreamError>

read vec from stream,return read length

Source

pub fn read( &mut self, buf: &mut [u8], offset: usize, count: usize, ) -> Result<usize, StreamError>

read u8 from stream,can use offset and count buff position,return read len

Source

pub fn read_i16(&mut self) -> Result<i16, StreamError>

read i16 from stream,return it value

Source

pub fn read_u16(&mut self) -> Result<u16, StreamError>

read u16 from stream,return it value

Source

pub fn read_u32(&mut self) -> Result<u32, StreamError>

read u32 from stream,return it value

Source

pub fn read_i32(&mut self) -> Result<i32, StreamError>

read i32 from stream,return it value

Source

pub fn read_i64(&mut self) -> Result<i64, StreamError>

read i64 from stream,return it value

Source

pub fn read_u64(&mut self) -> Result<u64, StreamError>

read u64 from stream,return it value

Source

pub fn read_single(&mut self) -> Result<f32, StreamError>

read f32 from stream,return it value

Source

pub fn read_double(&mut self) -> Result<f64, StreamError>

read f64 from stream,return it value

Source

pub fn read_u8_array(&mut self, len: u32) -> Result<Vec<u8>, StreamError>

read vec from the current stream,can specify need read length to buffer

§Examples
    use iostream::io::*;
    let mut ms=MemoryStream::new();
    let data:[u8;1024]=[5;1024];
    ms.write_all(&data).unwrap();

    ms.set_position(0).unwrap();

    let mut rs=StreamReader::from(&mut ms).unwrap();
    let rt= rs.read_u8_array(1024).unwrap();
    assert_eq!(data[..],rt[..] );
Source

pub fn read_string(&mut self) -> Result<String, Box<dyn Error>>

read string to current stream

Source

pub fn read_line(&mut self) -> Result<String, Box<dyn Error>>

read str line from current stream

Source

pub fn read_all_lines(&mut self) -> Result<Vec<String>, Box<dyn Error>>

read all str line from current stream

Source

pub fn read_all_text(&mut self) -> Result<String, Box<dyn Error>>

read all data to string

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for StreamReader<'a>

§

impl<'a> !Send for StreamReader<'a>

§

impl<'a> !Sync for StreamReader<'a>

§

impl<'a> !UnwindSafe for StreamReader<'a>

§

impl<'a> Freeze for StreamReader<'a>

§

impl<'a> Unpin for StreamReader<'a>

§

impl<'a> UnsafeUnpin for StreamReader<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.