feat: add KV unmarshal feature with struct tag support #24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey feel free to close as unplanned if you feel this does not align to the project goal.
the
tldris, sometimes you may have a spoe message which is not called very often and technical debt to write a whole iterator pattern simply for this message, having the struct drive the datatype and the message keys add a convenient way to get the data.Add
Unmarshal()method to KVScanner that unmarshals KV entries into structs using struct tags, similar to encoding/json. This provides a convenient API for extracting structured data from SPOE messages.Features:
spoe:"keyname"maps KV keys to struct fieldsPerformance:
The unmarshal feature trades some performance for convenience. Benchmarks show manual iteration is ~3x faster, but unmarshal provides better developer experience for non-hot paths.
Benchmark Results:
The additional allocations come from:
Usage Example: