-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MST and repository parsing APIs #167
Comments
I've written code for MST and repo parsing myself for a CAR viewer project, on top of The current APIs I have are: struct Repository<R: tokio::io::AsyncRead + tokio::io::AsyncSeek> { .. }
impl<R: AsyncRead + AsyncSeek + Unpin + Send> Repository<R> {
async fn load(reader: R) -> Result<Self, _> { .. }
fn did(&self) -> &Did { .. }
fn keys<'a>(&'a mut self) -> impl Stream<Item = Result<String, _>> + 'a { .. }
fn get_collection<'a, C: Collection + 'a>(
&'a mut self,
) -> impl futures::Stream<Item = Result<(RecordKey, C::Record), _>> + 'a { .. }
fn get_collection_reversed<'a, C: Collection + 'a>(
&'a mut self,
) -> impl futures::Stream<Item = Result<(RecordKey, C::Record), _>> + 'a { .. }
async fn get<C: Collection>(
&mut self,
rkey: &RecordKey,
) -> Result<Option<C::Record>, _> { .. }
}
mod mst {
enum Located<E> {
Entry(E),
InSubtree(Cid),
}
struct Node { .. }
impl Node {
fn parse(bytes: &[u8]) -> Result<Option<Self>, _> { .. }
fn get(&self, key: &[u8]) -> Option<Located<Cid>> { .. }
fn entries_with_prefix<'a>(
&'a self,
prefix: &'a [u8],
) -> impl Iterator<Item = Located<(&[u8], Cid)>> + 'a { .. }
fn reversed_entries_with_prefix<'a>(
&'a self,
prefix: &'a [u8],
) -> impl Iterator<Item = Located<(&[u8], Cid)>> + 'a { .. }
}
} I went with async APIs because I'm reading a CAR file from disk. For firehose subscribers maybe sync APIs would be fine, but given that the crates in this repo already have async APIs, I figure this works fine as a starting point. |
Thanks for the suggestion! Would it be better to add it as a new package, like |
Sure, |
As part of #118, and to enable consuming
#commit
events from the firehose, we need APIs for parsing and interacting with MSTs and repository CARs.The text was updated successfully, but these errors were encountered: