Skip to content
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

feat: make codec generic over FileClient #12521

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

TropicalDog17
Copy link
Contributor

Closes #12475

Copy link
Member

@emhane emhane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on the right track

@@ -447,15 +464,16 @@ impl ChunkedFileReader {
}

/// Read next chunk from file. Returns [`FileClient`] containing decoded chunk.
pub async fn next_chunk<T>(&mut self) -> Result<Option<T>, T::Error>
pub async fn next_chunk<T, F>(&mut self, codec: T) -> Result<Option<F>, F::Error>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this arg isn't needed, instead use self.codec

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but codec field only in FileClient, not ChunkedFileReader @emhane

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, my bad, I pushed a commit since couldn't add a GitHub suggestion on the code i was thinking about

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for your help!

Copy link
Member

@emhane emhane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@@ -49,6 +47,10 @@ pub struct FileClient {

/// The buffered bodies retrieved when fetching new headers.
bodies: HashMap<BlockHash, BlockBody>,

/// The codec used to decode the file.
#[allow(dead_code)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this attribute can be removed now

Comment on lines +50 to +52

/// The codec used to decode the file.
codec: T,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right so we can remove this field completely...and the generic on file client...would you be ok with doing this last thing or should I?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I will try to do it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure how to remove the generic? Isn't it the part of this pull request, or should I use phantom field for the type T?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the pr makes it apparent that the generic isn't needed: the codec is passed as arg instead, there is no need to save it in the FileClient type (the unused code warning is rust compilers way of hinting about this!).

the current design of how FileClient and ChunkedFileReader are connected, isn't great rn #7650, apologies for the confusion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make FileClient generic over codec
2 participants