mojang cant get their cases straight

i had to implement like 4 cases just  to parse that file
This commit is contained in:
adman
2026-04-21 09:38:14 +02:00
parent d87c362270
commit f6001c8b22
7 changed files with 265 additions and 33 deletions
+17 -2
View File
@@ -18,8 +18,11 @@ type Format struct {
Name string
requireAll bool
errorOnExtra bool
decoders map[reflect.Type]func(any, string) (any, error)
encoders map[reflect.Type]func(any, string) (any, error)
trySnakeCase bool
tryLowCase bool
decoders map[reflect.Type]func(any, string) (any, error)
encoders map[reflect.Type]func(any, string) (any, error)
}
func NewFormat(name string, opts ...Option) *Format {
@@ -48,6 +51,18 @@ func WithErrorOnExtra() Option {
}
}
func WithTrySnakeCase() Option {
return func(f *Format) {
f.trySnakeCase = true
}
}
func WithTryLowCase() Option {
return func(f *Format) {
f.tryLowCase = true
}
}
func WithTypeCodec(decodeFn, encodeFn any) Option {
dt := reflect.TypeOf(decodeFn)
et := reflect.TypeOf(encodeFn)