Skip to main content

assetpack_core/
object.rs

1use crate::{Result, codec::Codec, hash::Hash32};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
4pub enum ObjectKind {
5  Chunk = 1,
6  Recipe = 2,
7}
8
9impl ObjectKind {
10  #[cfg(feature = "sqlite")]
11  pub(crate) fn from_i64(value: i64) -> Option<Self> {
12    Self::from_u8(value.try_into().ok()?)
13  }
14
15  #[cfg(any(feature = "sealed", feature = "sqlite"))]
16  pub(crate) fn from_u8(value: u8) -> Option<Self> {
17    match value {
18      1 => Some(Self::Chunk),
19      2 => Some(Self::Recipe),
20      _ => None,
21    }
22  }
23}
24
25#[derive(Debug, Clone)]
26pub struct VerifiedObject {
27  pub hash: Hash32,
28  pub kind: ObjectKind,
29  pub bytes: Vec<u8>,
30}
31
32#[derive(Debug, Clone)]
33pub struct ObjectRecord {
34  pub hash: Hash32,
35  pub kind: ObjectKind,
36  pub decoded_len: u64,
37  pub codec: Codec,
38  pub stored_bytes: Vec<u8>,
39}
40
41#[allow(async_fn_in_trait)]
42pub trait ObjectSource: Send + Sync {
43  async fn read_object(&self, hash: &Hash32) -> Result<Option<VerifiedObject>>;
44}