Struct ByteBlock

Source
pub struct ByteBlock(pub Vec<u8>);
Expand description

Datablock that consists of a list of bytes.

It is possible to store any block of data in a ByteBlock, but that would require to know the Endianness of the file beforehand, so the bytes are written in the correct order.

Using a Datablock, on the other hand, allows to make use of the functionality of an EndianFile, so the data can be written without worrying about the endianness.

§Examples

Creating a ByteBlock from a Vec<u8>:

use tiff_encoder::prelude::*;

// A vector holding arbitrary u8 data.
// This is the data we want to store as a Byteblock.
let data_8bits: Vec<u8> = vec![0; 65536];

// Create an Offsets of a single Byteblock from the buffer.
// This is the value that can be used directly as an IFD entry value.
let byte_block = ByteBlock::single(data_8bits);

Creating a ByteBlock from a Vec<u32>:

extern crate byteorder;
// Crate byteorder will be used to write 32-bit information in a 8-bit buffer.
use byteorder::{LittleEndian, WriteBytesExt};
use tiff_encoder::prelude::*;


// A vector holding arbitrary u32 data.
// This is the data we want to store as a Byteblock.
let data_32bits: Vec<u32> = vec![0; 65536];

// First, let's store the data in a u8 buffer.
let mut image_bytes = Vec::with_capacity(262144); // 65536*4 (each u32 has a size of 4 bytes)
for val in data_32bits {
    // A little endian TIFF file is assumed in this example.
    image_bytes.write_u32::<LittleEndian>(val).unwrap();
}

// Create an Offsets of a single Byteblock from the buffer.
// This is the value that can be used directly as an IFD entry value.
let byte_block = ByteBlock::single(image_bytes);

Tuple Fields§

§0: Vec<u8>

Implementations§

Source§

impl ByteBlock

Source

pub fn offsets(blocks: Vec<Vec<u8>>) -> Offsets<ByteBlock>

Constructs an Offsets of ByteBlocks from a vector of vectors of bytes.

Each vector of bytes represents one ByteBlock.

Source

pub fn single(block: Vec<u8>) -> Offsets<ByteBlock>

Constructs an Offsets from a vector of bytes.

This vector of bytes represents a single ByteBlock.

Trait Implementations§

Source§

impl Datablock for ByteBlock

Source§

fn size(&self) -> u32

The number of bytes occupied by this Datablock. Read more
Source§

fn write_to(self, file: &mut EndianFile) -> Result<()>

Writes this Datablock to an EndianFile. The number of bytes written must be exactly same number as returned by size(&self). Read more

Auto Trait Implementations§

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.