feat: add OffsetDateTime, nesting limits and uniform Marshaler dispatch
Test / test (push) Successful in 2m18s
Test / test (push) Successful in 2m18s
Assisted-by: DeepSeek V4.1 Flash
This commit is contained in:
@@ -95,12 +95,10 @@ func (d *decoder) assign(data any, dst reflect.Value) error {
|
||||
return setInt(dst, v)
|
||||
case float64:
|
||||
return setFloat(dst, v)
|
||||
case OffsetDateTime:
|
||||
return setOffsetDateTime(v, dst)
|
||||
case time.Time:
|
||||
if dst.Type() != timeType {
|
||||
return fmt.Errorf("interpres: cannot assign datetime to %s", dst.Type())
|
||||
}
|
||||
dst.Set(reflect.ValueOf(v))
|
||||
return nil
|
||||
return setDateTime(v, dst)
|
||||
default:
|
||||
rv := reflect.ValueOf(data)
|
||||
if rv.IsValid() && dst.Type() == rv.Type() {
|
||||
@@ -235,6 +233,36 @@ func (d *decoder) assignTableSlice(items []map[string]any, dst reflect.Value) er
|
||||
|
||||
// --- low-level setters -----------------------------------------------------
|
||||
|
||||
// setOffsetDateTime stores an offset date-time: in a wrapper destination as it
|
||||
// is, and in a plain time.Time, which takes the instant with the offset the
|
||||
// document wrote, so a timestamp field does not have to name the wrapper.
|
||||
func setOffsetDateTime(v OffsetDateTime, dst reflect.Value) error {
|
||||
switch dst.Type() {
|
||||
case offsetDateTimeType:
|
||||
dst.Set(reflect.ValueOf(v))
|
||||
case timeType:
|
||||
dst.Set(reflect.ValueOf(v.Time))
|
||||
default:
|
||||
return fmt.Errorf("interpres: cannot assign datetime to %s", dst.Type())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// setDateTime stores a time.Time that reached the tree directly, which is the
|
||||
// shape a tree built by hand carries. Dates the parser produced arrive as
|
||||
// OffsetDateTime instead.
|
||||
func setDateTime(v time.Time, dst reflect.Value) error {
|
||||
switch dst.Type() {
|
||||
case timeType:
|
||||
dst.Set(reflect.ValueOf(v))
|
||||
case offsetDateTimeType:
|
||||
dst.Set(reflect.ValueOf(OffsetDateTime{v}))
|
||||
default:
|
||||
return fmt.Errorf("interpres: cannot assign datetime to %s", dst.Type())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func setBasic(dst, val reflect.Value, kind string) error {
|
||||
if dst.Kind() != val.Kind() {
|
||||
return fmt.Errorf("interpres: cannot assign %s to %s", kind, dst.Type())
|
||||
|
||||
Reference in New Issue
Block a user