#[cfg(feature = "dev")]
use arbitrary::Arbitrary;
use bab_rs::generic::storage::single_slice_store::SliceStreamResumptionInfo;
use bab_rs::generic::storage::units::{ByteCount, ChunkCount, ChunkIndex};
use ufotofu::prelude::*;
use bab_rs::generic::storage::verifiable_streaming::SliceStreamingOptions;
use crate::prelude::*;
use crate::storage::Store;
pub trait PayloadPrefixStore: Store {
async fn append_to_payload_prefix<K, P>(
&mut self,
namespace_id: &NamespaceId,
key: &K,
p: &mut P,
stream_options: SliceStreamingOptions,
) -> Result<(), AppendToPayloadPrefixError<P::Error, Self::InternalError>>
where
K: Keylike,
P: BulkProducer<Item = u8>;
async fn length_of_payload_prefix<K>(
&mut self,
namespace_id: &NamespaceId,
key: &K,
expected_digest: Option<PayloadDigest>,
) -> Result<ByteCount, InternalOrNoSuchEntryError<Self::InternalError>>
where
K: Keylike;
async fn prefix_stream_resumption_info<K>(
&mut self,
namespace_id: &NamespaceId,
key: &K,
expected_digest: Option<PayloadDigest>,
) -> Result<Option<SliceStreamResumptionInfo>, InternalOrNoSuchEntryError<Self::InternalError>>
where
K: Keylike;
async fn get_verifiable_stream<K, C>(
&mut self,
namespace_id: &NamespaceId,
key: &K,
expected_digest: Option<PayloadDigest>,
start: ChunkIndex,
length: ChunkCount,
stream_options: SliceStreamingOptions,
c: &mut C,
) -> Result<ByteCount, GetVerifiableStreamError<C::Error, Self::InternalError>>
where
K: Keylike,
C: BulkConsumer<Item = u8>;
}
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Debug)]
#[cfg_attr(feature = "dev", derive(Arbitrary))]
pub enum InternalOrNoSuchEntryError<StoreError> {
NoSuchEntry,
StoreError(StoreError),
}
impl<StoreError> From<StoreError> for InternalOrNoSuchEntryError<StoreError> {
fn from(value: StoreError) -> Self {
Self::StoreError(value)
}
}
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Debug)]
#[cfg_attr(feature = "dev", derive(Arbitrary))]
pub enum AppendToPayloadPrefixError<ProducerError, StoreError> {
ProducerError(ProducerError),
UnexpectedEndOfStream,
VerificationError,
NoSuchEntry,
StoreError(StoreError),
}
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Debug)]
#[cfg_attr(feature = "dev", derive(Arbitrary))]
pub enum GetVerifiableStreamError<ConsumerError, StoreError> {
ConsumerError(ConsumerError),
StoreError(StoreError),
NoSuchEntry,
}