openbim_ifc_capi/ifczip.rs
1//! ifcZIP (#450): a STEP or ifcXML model in a ZIP archive.
2//!
3//! Reading needs no call of its own: `openbim_ifc_v0_1_model_parse` and
4//! `openbim_ifc_v0_1_model_open` recognize an archive by its ZIP signature.
5
6use openbim_ifc_binding_core::IfcModel;
7
8use crate::buffer::fill;
9use crate::model::{done, with_model, OpenbimIfcModel};
10use crate::status::{boundary, OpenbimIfcStatus};
11use crate::xml::profile;
12
13/// Serialize as an ifcZIP archive into a caller buffer; `out_required` gets
14/// the size.
15///
16/// `inner` (UTF-8, `inner_len` bytes) is null with length 0 or `step` for
17/// STEP inside (`model.ifc`), or `ifcxml` (any case) for ifcXML
18/// (`model.ifcXML`) in the layout `profile` names as for
19/// `openbim_ifc_v0_1_model_write_ifcxml`. `InvalidValue` for another
20/// `inner` or a `profile` with STEP inside; otherwise as the inner write,
21/// and `FeatureDisabled` without the `zip` feature.
22///
23/// # Safety
24/// As `openbim_ifc_v0_1_model_write`; `inner` and `profile`, if non-null,
25/// valid for `inner_len` and `profile_len` reads.
26#[no_mangle]
27pub unsafe extern "C" fn openbim_ifc_v0_1_model_write_ifczip(
28 model: OpenbimIfcModel,
29 inner: *const u8,
30 inner_len: usize,
31 profile: *const u8,
32 profile_len: usize,
33 buffer: *mut u8,
34 capacity: usize,
35 out_required: *mut usize,
36) -> OpenbimIfcStatus {
37 boundary(|| {
38 // SAFETY: caller contract above; a null, empty text is `None` as
39 // for the profile.
40 let texts = unsafe {
41 (
42 self::profile(inner, inner_len),
43 self::profile(profile, profile_len),
44 )
45 };
46 let (inner, profile) = match texts {
47 (Ok(inner), Ok(profile)) => (inner, profile),
48 (Err(status), _) | (_, Err(status)) => return status,
49 };
50 with_model(model, |m: &mut IfcModel| {
51 let bytes = m.write_ifczip(inner, profile)?;
52 // SAFETY: caller contract above.
53 done(unsafe { fill(&bytes, buffer, capacity, out_required) })
54 })
55 })
56}