Brz

Struct Brz 

Source
pub struct Brz {
    pub index_data: BrzIndexData,
    pub blob_data: Vec<u8>,
}

Fields§

§index_data: BrzIndexData§blob_data: Vec<u8>

(Compressed) blob data as one contiguous byte array.

Implementations§

Source§

impl Brz

Source

pub fn open(path: impl AsRef<Path>) -> Result<Brz, BrzError>

Open and read a brz archive from a file path.

Examples found in repository?
examples/brz_to_brz.rs (line 9)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let src = PathBuf::from("./world.brz");
7    let dst = PathBuf::from("./world_copy.brz");
8
9    let pending = Brz::open(src)?.to_pending()?;
10    Brz::write_pending(dst, pending)?;
11
12    Ok(())
13}
More examples
Hide additional examples
examples/brz_to_brdb.rs (line 9)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let src = PathBuf::from("./world.brz");
7    let dst = PathBuf::from("./world.brdb");
8
9    let pending = Brz::open(src)?.to_pending()?;
10    Brdb::open(dst)?.write_pending("Import brz", pending)?;
11
12    Ok(())
13}
examples/read_brz.rs (line 9)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let path = PathBuf::from("./world.brz");
7
8    // The API for reading a brz is identical to reading a Brdb
9    let db = Brz::open(path)?.into_reader();
10
11    let data = db.global_data()?;
12    println!("Basic Brick assets: {:?}", data.basic_brick_asset_names);
13    println!("Wire ports: {:?}", data.component_wire_port_names);
14    println!("Component types: {:?}", data.component_type_names);
15    println!("Component structs: {:?}", data.component_data_struct_names);
16    println!("Component schemas: {}", db.components_schema()?);
17
18    let chunks = db.brick_chunk_index(1)?;
19    println!("Brick chunks: {chunks:?}");
20    for chunk in chunks {
21        let soa = db.brick_chunk_soa(1, chunk.index)?;
22        println!("Brick soa: {soa:?}");
23        if chunk.num_components > 0 {
24            let (_soa, components) = db.component_chunk_soa(1, chunk.index)?;
25            for c in components {
26                println!("Component: {c}");
27            }
28        }
29        if chunk.num_wires > 0 {
30            let soa = db.wire_chunk_soa(1, chunk.index)?;
31            println!("Wires soa: {soa}");
32        }
33    }
34
35    println!("Files: {}", db.get_fs()?.render());
36
37    Ok(())
38}
examples/world_replace_owner.rs (line 55)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8    let src = PathBuf::from("world.brdb");
9    let dst = PathBuf::from("world_patched.brz");
10
11    assert!(src.exists());
12
13    let db = Brdb::open(src)?.into_reader();
14
15    let owners = db.owners_soa()?;
16
17    // Parse the owners from BrdbValues
18    let mut new_soa = OwnerTableSoA::try_from(&owners.to_value())?;
19
20    // Modify the owner ids
21    new_soa
22        .display_names
23        .iter_mut()
24        .for_each(|id| *id = "PUBLIC".to_owned());
25    new_soa
26        .user_names
27        .iter_mut()
28        .for_each(|id| *id = "PUBLIC".to_owned());
29    new_soa
30        .user_ids
31        .iter_mut()
32        .for_each(|id| *id = Guid::default());
33
34    // convert the owners struct of arrays into bytes using the owners schema
35    let content = db.owners_schema()?.write_brdb(OWNER_TABLE_SOA, &new_soa)?;
36
37    let patch = BrPendingFs::Root(vec![(
38        "World".to_owned(),
39        BrPendingFs::Folder(Some(vec![(
40            "0".to_string(),
41            BrPendingFs::Folder(Some(vec![(
42                "Owners.mps".to_string(),
43                BrPendingFs::File(Some(content)),
44            )])),
45        )])),
46    )]);
47
48    // use .to_pending_patch() if you want to update the same world
49    let pending = db.to_pending()?.with_patch(patch)?;
50    if dst.exists() {
51        std::fs::remove_file(&dst)?;
52    }
53    Brz::write_pending(&dst, pending)?;
54
55    println!("{}", Brz::open(&dst)?.into_reader().owners_soa()?);
56
57    Ok(())
58}
Source

pub fn new(path: impl AsRef<Path>) -> Result<Brz, BrzError>

Open and read a brz archive from a file path.

Examples found in repository?
examples/write_brz.rs (line 21)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let path = PathBuf::from("./example_brick.brz");
7
8    let mut world = World::new();
9    world.meta.bundle.description = "Example World".to_string();
10    world.bricks.push(Brick {
11        position: (0, 0, 6).into(),
12        color: (255, 0, 0).into(),
13        ..Default::default()
14    });
15
16    if path.exists() {
17        std::fs::remove_file(&path)?;
18    }
19    world.write_brz(&path)?;
20
21    let db = Brz::new(&path)?.into_reader();
22
23    println!("{}", db.get_fs()?.render());
24
25    let soa = db.brick_chunk_soa(1, (0, 0, 0).into())?;
26    let color = soa.colors_and_alphas[0];
27    assert_eq!(color.r, 255);
28    assert_eq!(color.g, 0);
29    assert_eq!(color.b, 0);
30    assert_eq!(color.a, 5);
31
32    Ok(())
33}
Source

pub fn read_slice(buf: &[u8]) -> Result<Brz, BrzError>

Read a brz archive from a byte slice.

Source

pub fn read(r: &mut impl Read) -> Result<Brz, BrzError>

Source

pub fn to_vec(&self, zstd_level: Option<i32>) -> Result<Vec<u8>, BrzError>

Write a brz archive to a byte vector.

Source

pub fn to_pending(&self) -> Result<BrPendingFs, BrError>

Examples found in repository?
examples/brz_to_brz.rs (line 9)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let src = PathBuf::from("./world.brz");
7    let dst = PathBuf::from("./world_copy.brz");
8
9    let pending = Brz::open(src)?.to_pending()?;
10    Brz::write_pending(dst, pending)?;
11
12    Ok(())
13}
More examples
Hide additional examples
examples/brz_to_brdb.rs (line 9)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let src = PathBuf::from("./world.brz");
7    let dst = PathBuf::from("./world.brdb");
8
9    let pending = Brz::open(src)?.to_pending()?;
10    Brdb::open(dst)?.write_pending("Import brz", pending)?;
11
12    Ok(())
13}
Source

pub fn write_pending( path: impl AsRef<Path>, pending: BrPendingFs, ) -> Result<(), BrError>

Write a pending fs to a brz file.

Examples found in repository?
examples/brdb_to_brz.rs (line 10)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let src = PathBuf::from("./world.brdb");
7    let dst = PathBuf::from("./world.brz");
8
9    let pending = Brdb::open(src)?.to_pending()?;
10    Brz::write_pending(dst, pending)?;
11
12    Ok(())
13}
More examples
Hide additional examples
examples/brz_to_brz.rs (line 10)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let src = PathBuf::from("./world.brz");
7    let dst = PathBuf::from("./world_copy.brz");
8
9    let pending = Brz::open(src)?.to_pending()?;
10    Brz::write_pending(dst, pending)?;
11
12    Ok(())
13}
examples/world_replace_owner.rs (line 53)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8    let src = PathBuf::from("world.brdb");
9    let dst = PathBuf::from("world_patched.brz");
10
11    assert!(src.exists());
12
13    let db = Brdb::open(src)?.into_reader();
14
15    let owners = db.owners_soa()?;
16
17    // Parse the owners from BrdbValues
18    let mut new_soa = OwnerTableSoA::try_from(&owners.to_value())?;
19
20    // Modify the owner ids
21    new_soa
22        .display_names
23        .iter_mut()
24        .for_each(|id| *id = "PUBLIC".to_owned());
25    new_soa
26        .user_names
27        .iter_mut()
28        .for_each(|id| *id = "PUBLIC".to_owned());
29    new_soa
30        .user_ids
31        .iter_mut()
32        .for_each(|id| *id = Guid::default());
33
34    // convert the owners struct of arrays into bytes using the owners schema
35    let content = db.owners_schema()?.write_brdb(OWNER_TABLE_SOA, &new_soa)?;
36
37    let patch = BrPendingFs::Root(vec![(
38        "World".to_owned(),
39        BrPendingFs::Folder(Some(vec![(
40            "0".to_string(),
41            BrPendingFs::Folder(Some(vec![(
42                "Owners.mps".to_string(),
43                BrPendingFs::File(Some(content)),
44            )])),
45        )])),
46    )]);
47
48    // use .to_pending_patch() if you want to update the same world
49    let pending = db.to_pending()?.with_patch(patch)?;
50    if dst.exists() {
51        std::fs::remove_file(&dst)?;
52    }
53    Brz::write_pending(&dst, pending)?;
54
55    println!("{}", Brz::open(&dst)?.into_reader().owners_soa()?);
56
57    Ok(())
58}
Source

pub fn save(path: impl AsRef<Path>, world: &World) -> Result<(), BrError>

Write a brz archive to a file.

Source

pub fn save_uncompressed( path: impl AsRef<Path>, world: &World, ) -> Result<(), BrError>

Write a brz archive to a file with no compression

Source

pub fn write( &self, w: &mut impl Write, zstd_level: Option<i32>, ) -> Result<(), BrzError>

Write a brz archive to a writer.

Trait Implementations§

Source§

impl AsRef<Brz> for Brz

Source§

fn as_ref(&self) -> &Brz

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Brz

Source§

fn clone(&self) -> Brz

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> IntoReader for &'a Brz

Source§

type Inner = BrzIndex<&'a Brz>

Source§

fn into_reader(self) -> BrReader<Self::Inner>

Source§

impl IntoReader for Brz

Source§

type Inner = BrzIndex<Brz>

Source§

fn into_reader(self) -> BrReader<Self::Inner>

Auto Trait Implementations§

§

impl Freeze for Brz

§

impl RefUnwindSafe for Brz

§

impl Send for Brz

§

impl Sync for Brz

§

impl Unpin for Brz

§

impl UnwindSafe for Brz

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.