Skip to content

Commit b822033

Browse files
authored
feat: add decode options for stricter field and type validation, explicit None handling (#970)
Includes benchmarks, examples, stricter error handling, and new tests for decoding controls.
1 parent e27cba7 commit b822033

9 files changed

Lines changed: 831 additions & 44 deletions

pkg/sdk/conversion_bench_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,30 @@ func BenchmarkDecodeNested(b *testing.B) {
6464
}
6565
}
6666

67+
func BenchmarkDecodeNestedStrict(b *testing.B) {
68+
input, err := sdk.Encode(b.Context(), benchmarkInput)
69+
if err != nil {
70+
b.Fatal(err)
71+
}
72+
73+
options := []sdk.DecodeOption{
74+
sdk.RequireType(runtime.TypeMap),
75+
sdk.OnlyFields("name", "address", "tags"),
76+
sdk.DisallowUnknownFields(),
77+
sdk.DisallowNoneValues(),
78+
}
79+
80+
b.ReportAllocs()
81+
b.ResetTimer()
82+
83+
for b.Loop() {
84+
var output benchmarkUser
85+
if err := sdk.Decode(b.Context(), input, &output, options...); err != nil {
86+
b.Fatal(err)
87+
}
88+
}
89+
}
90+
6791
func BenchmarkTypedBinder(b *testing.B) {
6892
left := runtime.NewString("value")
6993
right := runtime.NewInt(42)

pkg/sdk/conversion_path.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ func (path *conversionPath) Restore(mark int) {
4343
path.data = path.data[:mark]
4444
}
4545

46+
func (path conversionPath) IsRoot() bool {
47+
return len(path.data) == 1
48+
}
49+
4650
func (path conversionPath) String() string {
4751
return string(path.data)
4852
}

0 commit comments

Comments
 (0)