Documentation
¶
Index ¶
- func Marshal(value interface{}, opts ...Option) ([]byte, error)
- func MarshalContext(ctx context.Context, value interface{}, opts ...Option) ([]byte, error)
- func Unmarshal(data []byte, dest interface{}, opts ...Option) error
- func UnmarshalContext(ctx context.Context, data []byte, dest interface{}, opts ...Option) error
- type Codec
- type Decoder
- type DuplicateKeyPolicy
- type FieldExcluder
- type MalformedPolicy
- type MarshalInterceptor
- type MarshalInterceptors
- type MarshalSession
- type MarshalerArray
- type MarshalerObject
- type Mode
- type NameTransformer
- type NilSlicePolicy
- type NullPolicy
- type NumberPolicy
- type Option
- func WithCaseFormat(caseFormat text.CaseFormat) Option
- func WithContext(ctx context.Context) Option
- func WithDebugPathSink(sink func(PathRef)) Option
- func WithDuplicateKeyPolicy(policy DuplicateKeyPolicy) Option
- func WithFieldExcluder(excluder FieldExcluder) Option
- func WithFieldUnmarshalHook(...) Option
- func WithFormatTag(tag *format.Tag) Option
- func WithMalformedPolicy(policy MalformedPolicy) Option
- func WithMode(mode Mode) Option
- func WithNameTransformer(transformer NameTransformer) Option
- func WithNilSlicePolicy(policy NilSlicePolicy) Option
- func WithNullPolicy(policy NullPolicy) Option
- func WithNumberPolicy(policy NumberPolicy) Option
- func WithOmitEmpty(enabled bool) Option
- func WithPathFieldExcluder(excluder PathFieldExcluder) Option
- func WithPathNameTransformer(transformer PathNameTransformer) Option
- func WithPathTracking(mode PathTrackingMode) Option
- func WithPathUnmarshalHook(...) Option
- func WithScannerHooks(hooks ScannerHooks) Option
- func WithUnknownFieldPolicy(policy UnknownFieldPolicy) Option
- type Options
- type PathFieldExcluder
- type PathNameTransformer
- type PathRef
- type PathSegment
- type PathTrackingMode
- type ScannerHooks
- type SegmentKind
- type UnknownFieldPolicy
- type UnmarshalInterceptor
- type UnmarshalInterceptors
- type UnmarshalSession
- type UnmarshalerArray
- type UnmarshalerJSONArray
- type UnmarshalerJSONObject
- type UnmarshalerObject
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Marshal ¶ added in v0.9.0
Marshal marshals using context.Background unless overridden by options.
func MarshalContext ¶ added in v0.9.0
MarshalContext marshals with an explicit context.
Types ¶
type Codec ¶ added in v0.9.0
type Codec interface {
String(*string) error
Int(*int) error
Int8(*int8) error
Int16(*int16) error
Int32(*int32) error
Int64(*int64) error
Uint(*uint) error
Uint8(*uint8) error
Uint16(*uint16) error
Uint32(*uint32) error
Uint64(*uint64) error
Float32(*float32) error
Float64(*float64) error
Bool(*bool) error
Interface(*interface{}) error
Object(UnmarshalerObject) error
Array(UnmarshalerArray) error
AddString(string)
AddInt(int)
AddInt8(int8)
AddInt16(int16)
AddInt32(int32)
AddInt64(int64)
AddUint(uint)
AddUint8(uint8)
AddUint16(uint16)
AddUint32(uint32)
AddUint64(uint64)
AddFloat32(float32)
AddFloat64(float64)
AddBool(bool)
AddNull()
AddInterface(interface{}) error
AddObject(MarshalerObject)
AddArray(MarshalerArray)
}
Codec is a unified encoder/decoder contract.
type Decoder ¶ added in v0.9.0
type Decoder interface {
String(*string) error
Int(*int) error
Int8(*int8) error
Int16(*int16) error
Int32(*int32) error
Int64(*int64) error
Uint(*uint) error
Uint8(*uint8) error
Uint16(*uint16) error
Uint32(*uint32) error
Uint64(*uint64) error
Float32(*float32) error
Float64(*float64) error
Bool(*bool) error
Interface(*interface{}) error
Object(UnmarshalerJSONObject) error
Array(UnmarshalerJSONArray) error
}
Decoder defines decode-side methods used by generic unmarshalers.
type DuplicateKeyPolicy ¶ added in v0.9.0
type DuplicateKeyPolicy int
DuplicateKeyPolicy controls duplicate object key behavior.
const ( LastWins DuplicateKeyPolicy = iota ErrorOnDuplicate )
type FieldExcluder ¶ added in v0.9.0
FieldExcluder decides whether a field should be excluded.
type MalformedPolicy ¶ added in v0.9.0
type MalformedPolicy int
MalformedPolicy controls malformed JSON tolerance.
const ( Tolerant MalformedPolicy = iota FailFast )
type MarshalInterceptor ¶ added in v0.9.0
type MarshalInterceptors ¶ added in v0.9.0
type MarshalInterceptors map[string]MarshalInterceptor
type MarshalSession ¶ added in v0.9.0
type MarshalSession struct {
Buffer *bytes.Buffer
Options Options
Interceptors MarshalInterceptors
// contains filtered or unexported fields
}
func NewMarshalSession ¶ added in v0.9.0
func NewMarshalSession(options Options) *MarshalSession
func (*MarshalSession) PathRef ¶ added in v0.9.0
func (s *MarshalSession) PathRef() PathRef
func (*MarshalSession) PopPath ¶ added in v0.9.0
func (s *MarshalSession) PopPath()
func (*MarshalSession) PushField ¶ added in v0.9.0
func (s *MarshalSession) PushField(name string)
func (*MarshalSession) PushIndex ¶ added in v0.9.0
func (s *MarshalSession) PushIndex(index int)
func (*MarshalSession) Release ¶ added in v0.9.0
func (s *MarshalSession) Release()
type MarshalerArray ¶ added in v0.9.0
MarshalerArray emits array elements.
type MarshalerObject ¶ added in v0.9.0
MarshalerObject emits object fields.
type NameTransformer ¶ added in v0.9.0
NameTransformer transforms field names for output and path display.
type NilSlicePolicy ¶ added in v0.9.0
type NilSlicePolicy int
NilSlicePolicy controls marshal output for nil slices.
const ( NilSliceAsNull NilSlicePolicy = iota NilSliceAsEmptyArray )
type NullPolicy ¶ added in v0.9.0
type NullPolicy int
NullPolicy controls null assignment behavior.
const ( CompatNulls NullPolicy = iota StrictNulls )
type NumberPolicy ¶ added in v0.9.0
type NumberPolicy int
NumberPolicy controls numeric coercion behavior.
const ( CoerceNumbers NumberPolicy = iota ExactNumbers )
type Option ¶ added in v0.9.0
type Option interface {
// contains filtered or unexported methods
}
Option mutates runtime options.
func WithCaseFormat ¶ added in v0.9.0
func WithCaseFormat(caseFormat text.CaseFormat) Option
func WithContext ¶ added in v0.9.0
func WithDebugPathSink ¶ added in v0.9.0
func WithDuplicateKeyPolicy ¶ added in v0.9.0
func WithDuplicateKeyPolicy(policy DuplicateKeyPolicy) Option
func WithFieldExcluder ¶ added in v0.9.0
func WithFieldExcluder(excluder FieldExcluder) Option
func WithFieldUnmarshalHook ¶ added in v0.9.0
func WithFormatTag ¶ added in v0.9.0
func WithMalformedPolicy ¶ added in v0.9.0
func WithMalformedPolicy(policy MalformedPolicy) Option
func WithNameTransformer ¶ added in v0.9.0
func WithNameTransformer(transformer NameTransformer) Option
func WithNilSlicePolicy ¶ added in v0.9.0
func WithNilSlicePolicy(policy NilSlicePolicy) Option
func WithNullPolicy ¶ added in v0.9.0
func WithNullPolicy(policy NullPolicy) Option
func WithNumberPolicy ¶ added in v0.9.0
func WithNumberPolicy(policy NumberPolicy) Option
func WithOmitEmpty ¶ added in v0.9.0
func WithPathFieldExcluder ¶ added in v0.9.0
func WithPathFieldExcluder(excluder PathFieldExcluder) Option
func WithPathNameTransformer ¶ added in v0.9.0
func WithPathNameTransformer(transformer PathNameTransformer) Option
func WithPathTracking ¶ added in v0.9.0
func WithPathTracking(mode PathTrackingMode) Option
func WithPathUnmarshalHook ¶ added in v0.9.0
func WithScannerHooks ¶ added in v0.9.0
func WithScannerHooks(hooks ScannerHooks) Option
func WithUnknownFieldPolicy ¶ added in v0.9.0
func WithUnknownFieldPolicy(policy UnknownFieldPolicy) Option
type Options ¶ added in v0.9.0
type Options struct {
Ctx context.Context
Mode Mode
UnknownFieldPolicy UnknownFieldPolicy
NumberPolicy NumberPolicy
NullPolicy NullPolicy
DuplicateKeyPolicy DuplicateKeyPolicy
MalformedPolicy MalformedPolicy
PathTracking PathTrackingMode
CaseFormat text.CaseFormat
FormatTag *format.Tag
TimeLayout string
NameTransformer NameTransformer
FieldExcluder FieldExcluder
PathName PathNameTransformer
PathExcluder PathFieldExcluder
DebugPathSink func(PathRef)
FieldUnmarshalHook func(ctx context.Context, holder unsafe.Pointer, field string, value any) (any, error)
PathUnmarshalHook func(ctx context.Context, holder unsafe.Pointer, path []string, field string, value any) (any, error)
OmitEmpty bool
NilSlicePolicy NilSlicePolicy
// contains filtered or unexported fields
}
Options defines runtime behavior.
type PathFieldExcluder ¶ added in v0.9.0
PathFieldExcluder excludes fields using path segments without forcing path string joins.
type PathNameTransformer ¶ added in v0.9.0
PathNameTransformer transforms names using path segments without forcing path string joins.
type PathRef ¶ added in v0.9.0
type PathRef struct {
// contains filtered or unexported fields
}
PathRef references path segments without eager string allocation.
func (PathRef) Segments ¶ added in v0.9.0
func (p PathRef) Segments() []PathSegment
type PathSegment ¶ added in v0.9.0
type PathSegment struct {
Field string
Index int
Kind SegmentKind
}
PathSegment describes one path component.
type PathTrackingMode ¶ added in v0.9.0
type PathTrackingMode int
PathTrackingMode controls path tracking overhead.
const ( PathTrackingOff PathTrackingMode = iota PathTrackingErrorsOnly PathTrackingFull )
type ScannerHooks ¶ added in v0.9.0
type ScannerHooks interface {
SkipWhitespace(data []byte, pos int) int
FindQuoteOrEscape(data []byte, pos int) (quotePos int, escapePos int)
FindStructural(data []byte, pos int) int
}
ScannerHooks contains block-scan hooks for decoder whitespace and token scans.
type SegmentKind ¶ added in v0.9.0
type SegmentKind int
SegmentKind identifies path segment type.
const ( SegmentField SegmentKind = iota SegmentIndex )
type UnknownFieldPolicy ¶ added in v0.9.0
type UnknownFieldPolicy int
UnknownFieldPolicy controls unknown key handling.
const ( IgnoreUnknown UnknownFieldPolicy = iota ErrorOnUnknown )
type UnmarshalInterceptor ¶ added in v0.9.0
type UnmarshalInterceptors ¶ added in v0.9.0
type UnmarshalInterceptors map[string]UnmarshalInterceptor
type UnmarshalSession ¶ added in v0.9.0
type UnmarshalSession struct {
Options Options
Interceptors UnmarshalInterceptors
// contains filtered or unexported fields
}
func NewUnmarshalSession ¶ added in v0.9.0
func NewUnmarshalSession(options Options) *UnmarshalSession
func (*UnmarshalSession) PathRef ¶ added in v0.9.0
func (s *UnmarshalSession) PathRef() PathRef
func (*UnmarshalSession) PopPath ¶ added in v0.9.0
func (s *UnmarshalSession) PopPath()
func (*UnmarshalSession) PushField ¶ added in v0.9.0
func (s *UnmarshalSession) PushField(name string)
func (*UnmarshalSession) PushIndex ¶ added in v0.9.0
func (s *UnmarshalSession) PushIndex(index int)
type UnmarshalerArray ¶ added in v0.9.0
UnmarshalerArray receives array elements.
type UnmarshalerJSONArray ¶ added in v0.9.0
UnmarshalerJSONArray receives array elements.