Repository navigation
feat(cbor): add RegisterDecoder for per-type decoders - #4206
danielntmd wants to merge 1 commit into
Conversation
|
Claude finished @danielntmd's task in 4m 17s —— View job Review completeSummary: Clean design overall — the unsafe-pointer approach is well-reasoned and the PR description already documents the primary risk (eface layout assumption). Two Important:
No blockers or nits beyond the above. |
PR Reviewer Guide 🔍(Review updated until commit e15e2e7)Here are some key observations to aid the review process:
|
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (23.72%) is below the target coverage (60.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #4206 +/- ##
==========================================
- Coverage 81.94% 80.61% -1.34%
==========================================
Files 512 510 -2
Lines 39122 39119 -3
==========================================
- Hits 32060 31536 -524
- Misses 7053 7574 +521
Partials 9 9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
- RegisterDecoder registers a decoder for *T and **T destinations. Unmarshal and UnmarshalFirst use it, and fxamacker for every other type. - The decoder is chosen from the destination's type. A nil or non-zero destination goes to fxamacker, which merges into it. - A decoder that fails is logged (SetLogger, sampled) and the item is decoded again with fxamacker. - Registration is for init only, and a second decoder for a type panics. - The table is keyed by the interface's type word to skip hashing, which relies on gc's layout of an interface, as reflect does. No decoder is registered yet, so nothing changes until one is.
e1a6b5b to
e15e2e7
Compare
|
Claude finished @danielntmd's task in 10m 46s —— View job Review completeSummary: This PR wires Important:
No blockers. These are the same two root issues flagged in the prior automated review (nil-decoder gap and the undocumented zero-destination gate), still present on top of the new fallback-to-fxamacker logging behavior added since then, plus the func-cast concern restated at its new line number. |
Titlefeat(cbor): add RegisterDecoder for per-type decoders PR TypeEnhancement Description
|
| Relevant files | |||||
|---|---|---|---|---|---|
| Enhancement |
| ||||
| Configuration changes |
|
| if err != nil { | ||
| return nil, err | ||
| } | ||
| cbor.SetLogger(logger) |
There was a problem hiding this comment.
With metrics this is avoidable, but this logger will be removed when fallback is removed.
|
Persistent review updated to latest commit e15e2e7 |
This PR does not change decoding behavior and only introduces the public API for integrating with a fast CBOR decoder, which follows in the next PRs.
Adds
cbor.RegisterDecoder[T], which makes a function the decoder of*Tand**Tdestinations.UnmarshalandUnmarshalFirstuse the decoder registered for the destination's type, and fxamacker for every other type.Adds a logger and uses fxamacker as the fallback.
No tests in this PR in order to avoid unit tests and mocked behavior. Tests through the public API will be introduced downstream when the types are registered.
On the safety of the unsafe pointer*:
decoders.golooks a destination up by the runtime type held in its interface. The lookup is by exact type, so the pointer inside the interface is always the type its decoder was written for, and the casts only erase and restore that type. It assumes gc's layout of an interface, whichreflectalso relies on.It saves: