pub trait Streamable<T>: Reader<T> + Writer {
    // Provided methods
    fn parse(&self) -> Result<Vec<u8>, BinaryError> { ... }
    fn fparse(&self) -> Vec<u8> { ... }
    fn compose(source: &[u8], position: &mut usize) -> Result<T, BinaryError>
       where Self: Sized { ... }
    fn fcompose(source: &[u8], position: &mut usize) -> T
       where Self: Sized { ... }
}
👎Deprecated since 0.3.0: This module is deprecated and will be removed in v0.4.0. Use the Reader and Writer traits instead.
Expand description

This trait exists only for backwards compatibility.

If you wish to read and write from a ByteReader or ByteWriter, use the Reader and Writer traits.

New Implementation Example

use binary_util::io::{ByteReader, ByteWriter};
use binary_util::interfaces::{Reader, Writer};

pub struct MyStruct;

impl Reader for MyStruct;
impl Writer for MyStruct;

Streamable

A trait to parse and unparse header structs from a given buffer.

use binary_util::{Streamable, error::BinaryError};

struct Foo {
    bar: u8,
    foo_bar: u16
}
impl Streamable for Foo {
    fn parse(&self) -> Result<Vec<u8>, BinaryError> {
        use std::io::Write;
        let mut stream = Vec::<u8>::new();
        stream.write_all(&self.bar.parse()?[..])?;
        stream.write_all(&self.bar.parse()?[..])?;
        Ok(stream)
    }

    fn compose(source: &[u8], position: &mut usize) -> Result<Self, BinaryError> {
        // Streamable is implemented for all primitives, so we can
        // just use this implementation to read our properties.
        Ok(Self {
            bar: u8::compose(&source, position)?,
            foo_bar: u16::compose(&source, position)?
        })
    }
}

Warning: This module is deprecated and will be removed in v0.4.0.

Provided Methods§

source

fn parse(&self) -> Result<Vec<u8>, BinaryError>

👎Deprecated since 0.3.0: This module is deprecated and will be removed in v0.4.0. Use the Reader and Writer traits instead.

Writes self to the given buffer.

source

fn fparse(&self) -> Vec<u8>

👎Deprecated since 0.3.0: This module is deprecated and will be removed in v0.4.0. Use the Reader and Writer traits instead.

Writes and unwraps self to the given buffer.

⚠️ This method is not fail safe, and will panic if result is Err.

source

fn compose(source: &[u8], position: &mut usize) -> Result<T, BinaryError>where Self: Sized,

👎Deprecated since 0.3.0: This module is deprecated and will be removed in v0.4.0. Use the Reader and Writer traits instead.

Reads self from the given buffer.

source

fn fcompose(source: &[u8], position: &mut usize) -> Twhere Self: Sized,

👎Deprecated since 0.3.0: This module is deprecated and will be removed in v0.4.0. Use the Reader and Writer traits instead.

Reads and unwraps self from the given buffer.

⚠️ This method is not fail safe, and will panic if result is Err.

Implementations on Foreign Types§

source§

impl Streamable<i128> for i128

source§

impl Streamable<char> for char

source§

impl Streamable<String> for String

source§

impl Streamable<u16> for u16

source§

impl Streamable<i8> for i8

source§

impl Streamable<i32> for i32

source§

impl Streamable<f32> for f32

source§

impl Streamable<u8> for u8

source§

impl Streamable<bool> for bool

source§

impl Streamable<u32> for u32

source§

impl Streamable<u128> for u128

source§

impl Streamable<i64> for i64

source§

impl Streamable<u64> for u64

source§

impl Streamable<f64> for f64

source§

impl Streamable<i16> for i16

Implementors§