[][src]Trait bitstream_io::read::HuffmanRead

pub trait HuffmanRead<E: Endianness> {
    pub fn read_huffman<T>(
        &mut self,
        tree: &[ReadHuffmanTree<E, T>]
    ) -> Result<T>
    where
        T: Clone
; }

A trait for anything that can read Huffman codes of a given endianness from an input stream

Required methods

pub fn read_huffman<T>(&mut self, tree: &[ReadHuffmanTree<E, T>]) -> Result<T> where
    T: Clone
[src]

Given a compiled Huffman tree, reads bits from the stream until the next symbol is encountered.

Errors

Passes along any I/O error from the underlying stream.

Loading content...

Implementors

impl<R: Read, E: Endianness> HuffmanRead<E> for BitReader<R, E>[src]

pub fn read_huffman<T>(&mut self, tree: &[ReadHuffmanTree<E, T>]) -> Result<T> where
    T: Clone
[src]

Example

use std::io::{Read, Cursor};
use bitstream_io::{BigEndian, BitReader, HuffmanRead};
use bitstream_io::huffman::compile_read_tree;
let tree = compile_read_tree(
    vec![('a', vec![0]),
         ('b', vec![1, 0]),
         ('c', vec![1, 1, 0]),
         ('d', vec![1, 1, 1])]).unwrap();
let data = [0b10110111];
let mut reader = BitReader::endian(Cursor::new(&data), BigEndian);
assert_eq!(reader.read_huffman(&tree).unwrap(), 'b');
assert_eq!(reader.read_huffman(&tree).unwrap(), 'c');
assert_eq!(reader.read_huffman(&tree).unwrap(), 'd');
Loading content...