fncs.marshal = func(enc *jsontext.Encoder, va addressableValue, mo *jsonopts.Struct) error {
xe := export.Encoder(enc)
if mo.Format != "" && mo.FormatDepth == xe.Tokens.Depth() {
- return newInvalidFormatError(enc, t, mo)
+ return newInvalidFormatError(enc, t)
}
// Optimize for marshaling without preceding whitespace.
fncs.unmarshal = func(dec *jsontext.Decoder, va addressableValue, uo *jsonopts.Struct) error {
xd := export.Decoder(dec)
if uo.Format != "" && uo.FormatDepth == xd.Tokens.Depth() {
- return newInvalidFormatError(dec, t, uo)
+ return newInvalidFormatError(dec, t)
}
tok, err := dec.ReadToken()
if err != nil {
return nil
}
}
- return newUnmarshalErrorAfterWithSkipping(dec, uo, t, nil)
+ return newUnmarshalErrorAfterWithSkipping(dec, t, nil)
}
return &fncs
}
fncs.marshal = func(enc *jsontext.Encoder, va addressableValue, mo *jsonopts.Struct) error {
xe := export.Encoder(enc)
if mo.Format != "" && mo.FormatDepth == xe.Tokens.Depth() {
- return newInvalidFormatError(enc, t, mo)
+ return newInvalidFormatError(enc, t)
}
// Optimize for marshaling without preceding whitespace.
fncs.unmarshal = func(dec *jsontext.Decoder, va addressableValue, uo *jsonopts.Struct) error {
xd := export.Decoder(dec)
if uo.Format != "" && uo.FormatDepth == xd.Tokens.Depth() {
- return newInvalidFormatError(dec, t, uo)
+ return newInvalidFormatError(dec, t)
}
var flags jsonwire.ValueFlags
val, err := xd.ReadValue(&flags)
mo.Format = ""
return marshalArray(enc, va, mo)
default:
- return newInvalidFormatError(enc, t, mo)
+ return newInvalidFormatError(enc, t)
}
} else if mo.Flags.Get(jsonflags.FormatByteArrayAsArray) && va.Kind() == reflect.Array {
return marshalArray(enc, va, mo)
uo.Format = ""
return unmarshalArray(dec, va, uo)
default:
- return newInvalidFormatError(dec, t, uo)
+ return newInvalidFormatError(dec, t)
}
} else if uo.Flags.Get(jsonflags.FormatByteArrayAsArray) && va.Kind() == reflect.Array {
return unmarshalArray(dec, va, uo)
fncs.marshal = func(enc *jsontext.Encoder, va addressableValue, mo *jsonopts.Struct) error {
xe := export.Encoder(enc)
if mo.Format != "" && mo.FormatDepth == xe.Tokens.Depth() {
- return newInvalidFormatError(enc, t, mo)
+ return newInvalidFormatError(enc, t)
}
// Optimize for marshaling without preceding whitespace or string escaping.
fncs.unmarshal = func(dec *jsontext.Decoder, va addressableValue, uo *jsonopts.Struct) error {
xd := export.Decoder(dec)
if uo.Format != "" && uo.FormatDepth == xd.Tokens.Depth() {
- return newInvalidFormatError(dec, t, uo)
+ return newInvalidFormatError(dec, t)
}
stringify := xd.Tokens.Last.NeedObjectName() || uo.Flags.Get(jsonflags.StringifyNumbers)
var flags jsonwire.ValueFlags
fncs.marshal = func(enc *jsontext.Encoder, va addressableValue, mo *jsonopts.Struct) error {
xe := export.Encoder(enc)
if mo.Format != "" && mo.FormatDepth == xe.Tokens.Depth() {
- return newInvalidFormatError(enc, t, mo)
+ return newInvalidFormatError(enc, t)
}
// Optimize for marshaling without preceding whitespace or string escaping.
fncs.unmarshal = func(dec *jsontext.Decoder, va addressableValue, uo *jsonopts.Struct) error {
xd := export.Decoder(dec)
if uo.Format != "" && uo.FormatDepth == xd.Tokens.Depth() {
- return newInvalidFormatError(dec, t, uo)
+ return newInvalidFormatError(dec, t)
}
stringify := xd.Tokens.Last.NeedObjectName() || uo.Flags.Get(jsonflags.StringifyNumbers)
var flags jsonwire.ValueFlags
if mo.Format == "nonfinite" {
allowNonFinite = true
} else {
- return newInvalidFormatError(enc, t, mo)
+ return newInvalidFormatError(enc, t)
}
}
if uo.Format == "nonfinite" {
allowNonFinite = true
} else {
- return newInvalidFormatError(dec, t, uo)
+ return newInvalidFormatError(dec, t)
}
}
stringify := xd.Tokens.Last.NeedObjectName() || uo.Flags.Get(jsonflags.StringifyNumbers)
emitNull = false
mo.Format = ""
default:
- return newInvalidFormatError(enc, t, mo)
+ return newInvalidFormatError(enc, t)
}
}
case "emitnull", "emitempty":
uo.Format = "" // only relevant for marshaling
default:
- return newInvalidFormatError(dec, t, uo)
+ return newInvalidFormatError(dec, t)
}
}
tok, err := dec.ReadToken()
}
return errUnmarshal
}
- return newUnmarshalErrorAfterWithSkipping(dec, uo, t, nil)
+ return newUnmarshalErrorAfterWithSkipping(dec, t, nil)
}
return &fncs
}
fncs.marshal = func(enc *jsontext.Encoder, va addressableValue, mo *jsonopts.Struct) error {
xe := export.Encoder(enc)
if mo.Format != "" && mo.FormatDepth == xe.Tokens.Depth() {
- return newInvalidFormatError(enc, t, mo)
+ return newInvalidFormatError(enc, t)
}
once.Do(init)
if errInit != nil && !mo.Flags.Get(jsonflags.ReportErrorsWithLegacySemantics) {
fncs.unmarshal = func(dec *jsontext.Decoder, va addressableValue, uo *jsonopts.Struct) error {
xd := export.Decoder(dec)
if uo.Format != "" && uo.FormatDepth == xd.Tokens.Depth() {
- return newInvalidFormatError(dec, t, uo)
+ return newInvalidFormatError(dec, t)
}
tok, err := dec.ReadToken()
if err != nil {
}
return errUnmarshal
}
- return newUnmarshalErrorAfterWithSkipping(dec, uo, t, nil)
+ return newUnmarshalErrorAfterWithSkipping(dec, t, nil)
}
return &fncs
}
emitNull = false
mo.Format = ""
default:
- return newInvalidFormatError(enc, t, mo)
+ return newInvalidFormatError(enc, t)
}
}
case "emitnull", "emitempty":
uo.Format = "" // only relevant for marshaling
default:
- return newInvalidFormatError(dec, t, uo)
+ return newInvalidFormatError(dec, t)
}
}
}
return errUnmarshal
}
- return newUnmarshalErrorAfterWithSkipping(dec, uo, t, nil)
+ return newUnmarshalErrorAfterWithSkipping(dec, t, nil)
}
return &fncs
}
fncs.marshal = func(enc *jsontext.Encoder, va addressableValue, mo *jsonopts.Struct) error {
xe := export.Encoder(enc)
if mo.Format != "" && mo.FormatDepth == xe.Tokens.Depth() {
- return newInvalidFormatError(enc, t, mo)
+ return newInvalidFormatError(enc, t)
}
once.Do(init)
if err := enc.WriteToken(jsontext.BeginArray); err != nil {
fncs.unmarshal = func(dec *jsontext.Decoder, va addressableValue, uo *jsonopts.Struct) error {
xd := export.Decoder(dec)
if uo.Format != "" && uo.FormatDepth == xd.Tokens.Depth() {
- return newInvalidFormatError(dec, t, uo)
+ return newInvalidFormatError(dec, t)
}
tok, err := dec.ReadToken()
if err != nil {
}
return errUnmarshal
}
- return newUnmarshalErrorAfterWithSkipping(dec, uo, t, nil)
+ return newUnmarshalErrorAfterWithSkipping(dec, t, nil)
}
return &fncs
}
fncs.marshal = func(enc *jsontext.Encoder, va addressableValue, mo *jsonopts.Struct) error {
xe := export.Encoder(enc)
if mo.Format != "" && mo.FormatDepth == xe.Tokens.Depth() {
- return newInvalidFormatError(enc, t, mo)
+ return newInvalidFormatError(enc, t)
}
if va.IsNil() {
return enc.WriteToken(jsontext.Null)
fncs.unmarshal = func(dec *jsontext.Decoder, va addressableValue, uo *jsonopts.Struct) error {
xd := export.Decoder(dec)
if uo.Format != "" && uo.FormatDepth == xd.Tokens.Depth() {
- return newInvalidFormatError(dec, t, uo)
+ return newInvalidFormatError(dec, t)
}
if uo.Flags.Get(jsonflags.MergeWithLegacySemantics) && !va.IsNil() {
// Legacy merge behavior is difficult to explain.
k := dec.PeekKind()
if !isAnyType(t) {
- return newUnmarshalErrorBeforeWithSkipping(dec, uo, t, internal.ErrNilInterface)
+ return newUnmarshalErrorBeforeWithSkipping(dec, t, internal.ErrNilInterface)
}
switch k {
case 'f', 't':
}
// coder is implemented by [jsontext.Encoder] or [jsontext.Decoder].
-type coder interface{ StackPointer() jsontext.Pointer }
+type coder interface {
+ StackPointer() jsontext.Pointer
+ Options() Options
+}
// newInvalidFormatError wraps err in a SemanticError because
// the current type t cannot handle the provided options format.
// If [jsonflags.ReportErrorsWithLegacySemantics] is specified,
// then this automatically skips the next value when unmarshaling
// to ensure that the value is fully consumed.
-func newInvalidFormatError(c coder, t reflect.Type, o *jsonopts.Struct) error {
- err := fmt.Errorf("invalid format flag %q", o.Format)
+func newInvalidFormatError(c coder, t reflect.Type) error {
+ err := fmt.Errorf("invalid format flag %q", c.Options().(*jsonopts.Struct).Format)
switch c := c.(type) {
case *jsontext.Encoder:
err = newMarshalErrorBefore(c, t, err)
case *jsontext.Decoder:
- err = newUnmarshalErrorBeforeWithSkipping(c, o, t, err)
+ err = newUnmarshalErrorBeforeWithSkipping(c, t, err)
}
return err
}
// newUnmarshalErrorBeforeWithSkipping is like [newUnmarshalErrorBefore],
// but automatically skips the next value if
// [jsonflags.ReportErrorsWithLegacySemantics] is specified.
-func newUnmarshalErrorBeforeWithSkipping(d *jsontext.Decoder, o *jsonopts.Struct, t reflect.Type, err error) error {
+func newUnmarshalErrorBeforeWithSkipping(d *jsontext.Decoder, t reflect.Type, err error) error {
err = newUnmarshalErrorBefore(d, t, err)
- if o.Flags.Get(jsonflags.ReportErrorsWithLegacySemantics) {
+ if export.Decoder(d).Flags.Get(jsonflags.ReportErrorsWithLegacySemantics) {
if err2 := export.Decoder(d).SkipValue(); err2 != nil {
return err2
}
// newUnmarshalErrorAfterWithSkipping is like [newUnmarshalErrorAfter],
// but automatically skips the remainder of the current value if
// [jsonflags.ReportErrorsWithLegacySemantics] is specified.
-func newUnmarshalErrorAfterWithSkipping(d *jsontext.Decoder, o *jsonopts.Struct, t reflect.Type, err error) error {
+func newUnmarshalErrorAfterWithSkipping(d *jsontext.Decoder, t reflect.Type, err error) error {
err = newUnmarshalErrorAfter(d, t, err)
- if o.Flags.Get(jsonflags.ReportErrorsWithLegacySemantics) {
+ if export.Decoder(d).Flags.Get(jsonflags.ReportErrorsWithLegacySemantics) {
if err2 := export.Decoder(d).SkipValueRemainder(); err2 != nil {
return err2
}