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

Replace ReadContext.metadata with typemap. #305

Open
XAMPPRocky opened this issue Jun 29, 2021 · 2 comments
Open

Replace ReadContext.metadata with typemap. #305

XAMPPRocky opened this issue Jun 29, 2021 · 2 comments
Assignees
Labels
area/filters Related to Quilkin's filter API. kind/design Proposal discussing new features / fixes and how they should be implemented priority/low Issues that don't need to be addressed in the near term.

Comments

@XAMPPRocky
Copy link
Collaborator

XAMPPRocky commented Jun 29, 2021

Currently the metadata field requires knowing the right string, and then knowing what type to downcast to. However we can actually encapsulate these things into the type system, and we can take it a step further and use types instead of strings to identify dynamic metadata, this is not only more efficient as it removes two levels of indirection in the lookup (Arc -> String -> str), it also guarantees that the value will always be the right type. Here's an example of how the capture bytes metadata would work.

pub struct CaptureBytes;

impl typemap::Key for CaptureBytes {
    type Value = Vec<u8>;
}

// in capture bytes using typemap::TypeMap
ctx.metadata.set::<CaptureBytes>(ctx.contents.clone());

// In another filter.
let capture_bytes: &Vec<u8> = ctx.metadata.get::<CaptureBytes>().unwrap();
@XAMPPRocky XAMPPRocky self-assigned this Jun 29, 2021
@iffyio
Copy link
Collaborator

iffyio commented Jun 30, 2021

I like this idea, both for the perf and clarity/type-safety but I can imagine it'll be nice to have configurable keys and this won't be able to support that - I don't know of any use case that would require dynamic keys but I can't say at all how common it'll be either 🤷‍♂️ I'm thinking maybe we can start with this and if it turns out that some use case requires dynamic string we can solve that as we go (maybe use a separate map or go back to the current solution or something else entirely)? But as of today I'll be up for changing to use typemap

@XAMPPRocky
Copy link
Collaborator Author

XAMPPRocky commented Jul 5, 2021

Well my current hesitation is over CaptureBytes's utility with this change. Currently with capture byte's configurable keys you can capture data into different buckets, where as with type map you wouldn't be able to do that. so maybe we need take another look at how we're handling dynamic metadata a bit closer, because there are going to be other filters that want to capture, so maybe we can build that assumption into how you set metadata.

@XAMPPRocky XAMPPRocky added area/filters Related to Quilkin's filter API. kind/design Proposal discussing new features / fixes and how they should be implemented priority/low Issues that don't need to be addressed in the near term. labels Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/filters Related to Quilkin's filter API. kind/design Proposal discussing new features / fixes and how they should be implemented priority/low Issues that don't need to be addressed in the near term.
Projects
None yet
Development

No branches or pull requests

2 participants