Trait rlp::rlptraits::View [] [src]

pub trait View<'a, 'view>: Sized {
    type Prototype;
    type PayloadInfo;
    type Data;
    type Item;
    type Iter;
    fn new(bytes: &'a [u8]) -> Self;
    fn as_raw(&'view self) -> &'a [u8];
    fn prototype(&self) -> Self::Prototype;
    fn payload_info(&self) -> Self::PayloadInfo;
    fn data(&'view self) -> Self::Data;
    fn item_count(&self) -> usize;
    fn size(&self) -> usize;
    fn at(&'view self, index: usize) -> Self::Item;
    fn is_null(&self) -> bool;
    fn is_empty(&self) -> bool;
    fn is_list(&self) -> bool;
    fn is_data(&self) -> bool;
    fn is_int(&self) -> bool;
    fn iter(&'view self) -> Self::Iter;
    fn as_val<T>(&self) -> Result<T, DecoderError> where T: RlpDecodable;
    fn val_at<T>(&self, index: usize) -> Result<T, DecoderError> where T: RlpDecodable;
}

A view into RLP encoded data

Associated Types

RLP prototype type

Payload info type

Data type

Item type

Iterator type

Required Methods

Creates a new instance of Rlp reader

The raw data of the RLP as slice.

extern crate rlp;
use rlp::*;

fn main () {
    let data = vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g'];
    let rlp = Rlp::new(&data);
    let dog = rlp.at(1).as_raw();
    assert_eq!(dog, &[0x83, b'd', b'o', b'g']);
}

Get the prototype of the RLP.

Get payload info.

Get underlieing data.

Returns number of RLP items.

extern crate rlp;
use rlp::*;

fn main () {
    let data = vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g'];
    let rlp = Rlp::new(&data);
    assert_eq!(rlp.item_count(), 2);
    let view = rlp.at(1);
    assert_eq!(view.item_count(), 0);
}

Returns the number of bytes in the data, or zero if it isn't data.

extern crate rlp;
use rlp::*;

fn main () {
    let data = vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g'];
    let rlp = Rlp::new(&data);
    assert_eq!(rlp.size(), 0);
    let view = rlp.at(1);
    assert_eq!(view.size(), 3);
}

Get view onto RLP-slice at index.

Caches offset to given index, so access to successive slices is faster.

extern crate rlp;
use rlp::*;

fn main () {
    let data = vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g'];
    let rlp = Rlp::new(&data);
    let dog: String = rlp.at(1).as_val();
    assert_eq!(dog, "dog".to_string());
}

No value

extern crate rlp;
use rlp::*;

fn main () {
    let data = vec![];
    let rlp = Rlp::new(&data);
    assert!(rlp.is_null());
}

Contains a zero-length string or zero-length list.

extern crate rlp;
use rlp::*;

fn main () {
    let data = vec![0xc0];
    let rlp = Rlp::new(&data);
    assert!(rlp.is_empty());
}

List value

extern crate rlp;
use rlp::*;

fn main () {
    let data = vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g'];
    let rlp = Rlp::new(&data);
    assert!(rlp.is_list());
}

String value

extern crate rlp;
use rlp::*;

fn main () {
    let data = vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g'];
    let rlp = Rlp::new(&data);
    assert!(rlp.at(1).is_data());
}

Int value

extern crate rlp;
use rlp::*;

fn main () {
    let data = vec![0xc1, 0x10];
    let rlp = Rlp::new(&data);
    assert_eq!(rlp.is_int(), false);
    assert_eq!(rlp.at(0).is_int(), true);
}

Get iterator over rlp-slices

extern crate rlp;
use rlp::*;

fn main () {
    let data = vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g'];
    let rlp = Rlp::new(&data);
    let strings: Vec<String> = rlp.iter().map(| i | i.as_val()).collect();
}

Decode data into an object

Decode data at given list index into an object

Implementors