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
impl Brz
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Brz, BrzError>
pub fn open(path: impl AsRef<Path>) -> Result<Brz, BrzError>
Open and read a brz archive from a file path.
Examples found in repository?
More examples
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}Sourcepub fn new(path: impl AsRef<Path>) -> Result<Brz, BrzError>
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}pub fn read(r: &mut impl Read) -> Result<Brz, BrzError>
Sourcepub fn to_vec(&self, zstd_level: Option<i32>) -> Result<Vec<u8>, BrzError>
pub fn to_vec(&self, zstd_level: Option<i32>) -> Result<Vec<u8>, BrzError>
Write a brz archive to a byte vector.
Sourcepub fn to_pending(&self) -> Result<BrPendingFs, BrError>
pub fn to_pending(&self) -> Result<BrPendingFs, BrError>
Examples found in repository?
More examples
Sourcepub fn write_pending(
path: impl AsRef<Path>,
pending: BrPendingFs,
) -> Result<(), BrError>
pub fn write_pending( path: impl AsRef<Path>, pending: BrPendingFs, ) -> Result<(), BrError>
Write a pending fs to a brz file.
Examples found in repository?
More examples
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}Sourcepub fn save(path: impl AsRef<Path>, world: &World) -> Result<(), BrError>
pub fn save(path: impl AsRef<Path>, world: &World) -> Result<(), BrError>
Write a brz archive to a file.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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