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