use std::path::Path;
use crate::model::identity::RobotId;
use crate::model::manifest::ManifestDocument;
use crate::model::{AssetId, Robot};
use crate::bundle::{BundleError, BundleRoot, ParticipantAssets, read_manifest_document};
#[derive(Clone, Debug)]
pub struct RuntimeBundle {
root: BundleRoot,
manifest: ManifestDocument,
assets: ParticipantAssets,
}
impl RuntimeBundle {
pub fn open(root: impl AsRef<Path>) -> Result<Self, BundleError> {
let root = BundleRoot::open(root.as_ref())?;
let manifest = read_manifest_document(&root)?;
Ok(Self {
assets: ParticipantAssets::new(root.clone()),
root,
manifest,
})
}
#[must_use]
pub fn root(&self) -> &Path {
self.root.path()
}
#[must_use]
pub const fn manifest(&self) -> &ManifestDocument {
&self.manifest
}
#[must_use]
pub const fn robot(&self) -> &Robot {
self.manifest.robot()
}
#[must_use]
pub const fn robot_id(&self) -> &RobotId {
self.robot().id()
}
pub fn asset(&self, id: &AssetId) -> Result<Vec<u8>, BundleError> {
self.assets.read(id)
}
#[must_use]
pub const fn assets(&self) -> &ParticipantAssets {
&self.assets
}
pub(crate) fn relocated(mut self, path: std::path::PathBuf) -> Self {
self.root.relocate(path.clone());
self.assets.relocate(path);
self
}
}