diff --git a/internal/decoder/anonymous_field.go b/internal/decoder/anonymous_field.go index 25af1d9..0f557cb 100644 --- a/internal/decoder/anonymous_field.go +++ b/internal/decoder/anonymous_field.go @@ -9,10 +9,10 @@ import ( type anonymousFieldDecoder struct { structType *runtime.Type offset uintptr - dec decoder + dec Decoder } -func newAnonymousFieldDecoder(structType *runtime.Type, offset uintptr, dec decoder) *anonymousFieldDecoder { +func newAnonymousFieldDecoder(structType *runtime.Type, offset uintptr, dec Decoder) *anonymousFieldDecoder { return &anonymousFieldDecoder{ structType: structType, offset: offset, diff --git a/internal/decoder/array.go b/internal/decoder/array.go index f917fa3..4283a00 100644 --- a/internal/decoder/array.go +++ b/internal/decoder/array.go @@ -10,14 +10,14 @@ import ( type arrayDecoder struct { elemType *runtime.Type size uintptr - valueDecoder decoder + valueDecoder Decoder alen int structName string fieldName string zeroValue unsafe.Pointer } -func newArrayDecoder(dec decoder, elemType *runtime.Type, alen int, structName, fieldName string) *arrayDecoder { +func newArrayDecoder(dec Decoder, elemType *runtime.Type, alen int, structName, fieldName string) *arrayDecoder { zeroValue := *(*unsafe.Pointer)(unsafe_New(elemType)) return &arrayDecoder{ valueDecoder: dec, diff --git a/internal/decoder/bytes.go b/internal/decoder/bytes.go index e8fcc91..da7535f 100644 --- a/internal/decoder/bytes.go +++ b/internal/decoder/bytes.go @@ -10,13 +10,13 @@ import ( type bytesDecoder struct { typ *runtime.Type - sliceDecoder decoder + sliceDecoder Decoder structName string fieldName string } -func byteUnmarshalerSliceDecoder(typ *runtime.Type, structName string, fieldName string) decoder { - var unmarshalDecoder decoder +func byteUnmarshalerSliceDecoder(typ *runtime.Type, structName string, fieldName string) Decoder { + var unmarshalDecoder Decoder switch { case runtime.PtrTo(typ).Implements(unmarshalJSONType): unmarshalDecoder = newUnmarshalJSONDecoder(runtime.PtrTo(typ), structName, fieldName) diff --git a/internal/decoder/compile.go b/internal/decoder/compile.go index 6be4bce..b57af80 100644 --- a/internal/decoder/compile.go +++ b/internal/decoder/compile.go @@ -17,7 +17,7 @@ var ( jsonNumberType = reflect.TypeOf(json.Number("")) typeAddr *runtime.TypeAddr cachedDecoderMap unsafe.Pointer // map[uintptr]decoder - cachedDecoder []decoder + cachedDecoder []Decoder ) func init() { @@ -25,16 +25,16 @@ func init() { if typeAddr == nil { typeAddr = &runtime.TypeAddr{} } - cachedDecoder = make([]decoder, typeAddr.AddrRange>>typeAddr.AddrShift) + cachedDecoder = make([]Decoder, typeAddr.AddrRange>>typeAddr.AddrShift) } -func loadDecoderMap() map[uintptr]decoder { +func loadDecoderMap() map[uintptr]Decoder { p := atomic.LoadPointer(&cachedDecoderMap) - return *(*map[uintptr]decoder)(unsafe.Pointer(&p)) + return *(*map[uintptr]Decoder)(unsafe.Pointer(&p)) } -func storeDecoder(typ uintptr, dec decoder, m map[uintptr]decoder) { - newDecoderMap := make(map[uintptr]decoder, len(m)+1) +func storeDecoder(typ uintptr, dec Decoder, m map[uintptr]Decoder) { + newDecoderMap := make(map[uintptr]Decoder, len(m)+1) newDecoderMap[typ] = dec for k, v := range m { @@ -44,13 +44,13 @@ func storeDecoder(typ uintptr, dec decoder, m map[uintptr]decoder) { atomic.StorePointer(&cachedDecoderMap, *(*unsafe.Pointer)(unsafe.Pointer(&newDecoderMap))) } -func compileToGetDecoderSlowPath(typeptr uintptr, typ *runtime.Type) (decoder, error) { +func compileToGetDecoderSlowPath(typeptr uintptr, typ *runtime.Type) (Decoder, error) { decoderMap := loadDecoderMap() if dec, exists := decoderMap[typeptr]; exists { return dec, nil } - dec, err := compileHead(typ, map[uintptr]decoder{}) + dec, err := compileHead(typ, map[uintptr]Decoder{}) if err != nil { return nil, err } @@ -58,7 +58,7 @@ func compileToGetDecoderSlowPath(typeptr uintptr, typ *runtime.Type) (decoder, e return dec, nil } -func compileHead(typ *runtime.Type, structTypeToDecoder map[uintptr]decoder) (decoder, error) { +func compileHead(typ *runtime.Type, structTypeToDecoder map[uintptr]Decoder) (Decoder, error) { switch { case runtime.PtrTo(typ).Implements(unmarshalJSONType): return newUnmarshalJSONDecoder(runtime.PtrTo(typ), "", ""), nil @@ -68,7 +68,7 @@ func compileHead(typ *runtime.Type, structTypeToDecoder map[uintptr]decoder) (de return compile(typ.Elem(), "", "", structTypeToDecoder) } -func compile(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) { +func compile(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]Decoder) (Decoder, error) { switch { case runtime.PtrTo(typ).Implements(unmarshalJSONType): return newUnmarshalJSONDecoder(runtime.PtrTo(typ), structName, fieldName), nil @@ -153,7 +153,7 @@ func isStringTagSupportedType(typ *runtime.Type) bool { return true } -func compileMapKey(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) { +func compileMapKey(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]Decoder) (Decoder, error) { if runtime.PtrTo(typ).Implements(unmarshalTextType) { return newUnmarshalTextDecoder(runtime.PtrTo(typ), structName, fieldName), nil } @@ -181,7 +181,7 @@ ERROR: } } -func compilePtr(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) { +func compilePtr(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]Decoder) (Decoder, error) { dec, err := compile(typ.Elem(), structName, fieldName, structTypeToDecoder) if err != nil { return nil, err @@ -189,79 +189,79 @@ func compilePtr(typ *runtime.Type, structName, fieldName string, structTypeToDec return newPtrDecoder(dec, typ.Elem(), structName, fieldName), nil } -func compileInt(typ *runtime.Type, structName, fieldName string) (decoder, error) { +func compileInt(typ *runtime.Type, structName, fieldName string) (Decoder, error) { return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) { *(*int)(p) = int(v) }), nil } -func compileInt8(typ *runtime.Type, structName, fieldName string) (decoder, error) { +func compileInt8(typ *runtime.Type, structName, fieldName string) (Decoder, error) { return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) { *(*int8)(p) = int8(v) }), nil } -func compileInt16(typ *runtime.Type, structName, fieldName string) (decoder, error) { +func compileInt16(typ *runtime.Type, structName, fieldName string) (Decoder, error) { return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) { *(*int16)(p) = int16(v) }), nil } -func compileInt32(typ *runtime.Type, structName, fieldName string) (decoder, error) { +func compileInt32(typ *runtime.Type, structName, fieldName string) (Decoder, error) { return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) { *(*int32)(p) = int32(v) }), nil } -func compileInt64(typ *runtime.Type, structName, fieldName string) (decoder, error) { +func compileInt64(typ *runtime.Type, structName, fieldName string) (Decoder, error) { return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) { *(*int64)(p) = v }), nil } -func compileUint(typ *runtime.Type, structName, fieldName string) (decoder, error) { +func compileUint(typ *runtime.Type, structName, fieldName string) (Decoder, error) { return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) { *(*uint)(p) = uint(v) }), nil } -func compileUint8(typ *runtime.Type, structName, fieldName string) (decoder, error) { +func compileUint8(typ *runtime.Type, structName, fieldName string) (Decoder, error) { return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) { *(*uint8)(p) = uint8(v) }), nil } -func compileUint16(typ *runtime.Type, structName, fieldName string) (decoder, error) { +func compileUint16(typ *runtime.Type, structName, fieldName string) (Decoder, error) { return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) { *(*uint16)(p) = uint16(v) }), nil } -func compileUint32(typ *runtime.Type, structName, fieldName string) (decoder, error) { +func compileUint32(typ *runtime.Type, structName, fieldName string) (Decoder, error) { return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) { *(*uint32)(p) = uint32(v) }), nil } -func compileUint64(typ *runtime.Type, structName, fieldName string) (decoder, error) { +func compileUint64(typ *runtime.Type, structName, fieldName string) (Decoder, error) { return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) { *(*uint64)(p) = v }), nil } -func compileFloat32(structName, fieldName string) (decoder, error) { +func compileFloat32(structName, fieldName string) (Decoder, error) { return newFloatDecoder(structName, fieldName, func(p unsafe.Pointer, v float64) { *(*float32)(p) = float32(v) }), nil } -func compileFloat64(structName, fieldName string) (decoder, error) { +func compileFloat64(structName, fieldName string) (Decoder, error) { return newFloatDecoder(structName, fieldName, func(p unsafe.Pointer, v float64) { *(*float64)(p) = v }), nil } -func compileString(typ *runtime.Type, structName, fieldName string) (decoder, error) { +func compileString(typ *runtime.Type, structName, fieldName string) (Decoder, error) { if typ == runtime.Type2RType(jsonNumberType) { return newNumberDecoder(structName, fieldName, func(p unsafe.Pointer, v json.Number) { *(*json.Number)(p) = v @@ -270,15 +270,15 @@ func compileString(typ *runtime.Type, structName, fieldName string) (decoder, er return newStringDecoder(structName, fieldName), nil } -func compileBool(structName, fieldName string) (decoder, error) { +func compileBool(structName, fieldName string) (Decoder, error) { return newBoolDecoder(structName, fieldName), nil } -func compileBytes(typ *runtime.Type, structName, fieldName string) (decoder, error) { +func compileBytes(typ *runtime.Type, structName, fieldName string) (Decoder, error) { return newBytesDecoder(typ, structName, fieldName), nil } -func compileSlice(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) { +func compileSlice(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]Decoder) (Decoder, error) { elem := typ.Elem() decoder, err := compile(elem, structName, fieldName, structTypeToDecoder) if err != nil { @@ -287,7 +287,7 @@ func compileSlice(typ *runtime.Type, structName, fieldName string, structTypeToD return newSliceDecoder(decoder, elem, elem.Size(), structName, fieldName), nil } -func compileArray(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) { +func compileArray(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]Decoder) (Decoder, error) { elem := typ.Elem() decoder, err := compile(elem, structName, fieldName, structTypeToDecoder) if err != nil { @@ -296,7 +296,7 @@ func compileArray(typ *runtime.Type, structName, fieldName string, structTypeToD return newArrayDecoder(decoder, elem, typ.Len(), structName, fieldName), nil } -func compileMap(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) { +func compileMap(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]Decoder) (Decoder, error) { keyDec, err := compileMapKey(typ.Key(), structName, fieldName, structTypeToDecoder) if err != nil { return nil, err @@ -308,7 +308,7 @@ func compileMap(typ *runtime.Type, structName, fieldName string, structTypeToDec return newMapDecoder(typ, typ.Key(), keyDec, typ.Elem(), valueDec, structName, fieldName), nil } -func compileInterface(typ *runtime.Type, structName, fieldName string) (decoder, error) { +func compileInterface(typ *runtime.Type, structName, fieldName string) (Decoder, error) { return newInterfaceDecoder(typ, structName, fieldName), nil } @@ -367,7 +367,7 @@ func removeConflictFields(fieldMap map[string]*structFieldSet, conflictedMap map } } -func compileStruct(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) { +func compileStruct(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]Decoder) (Decoder, error) { fieldNum := typ.NumField() conflictedMap := map[string]struct{}{} fieldMap := map[string]*structFieldSet{} diff --git a/internal/decoder/compile_norace.go b/internal/decoder/compile_norace.go index 4fa66ca..592f637 100644 --- a/internal/decoder/compile_norace.go +++ b/internal/decoder/compile_norace.go @@ -8,7 +8,7 @@ import ( "github.com/goccy/go-json/internal/runtime" ) -func CompileToGetDecoder(typ *runtime.Type) (decoder, error) { +func CompileToGetDecoder(typ *runtime.Type) (Decoder, error) { typeptr := uintptr(unsafe.Pointer(typ)) if typeptr > typeAddr.MaxTypeAddr { return compileToGetDecoderSlowPath(typeptr, typ) @@ -19,7 +19,7 @@ func CompileToGetDecoder(typ *runtime.Type) (decoder, error) { return dec, nil } - dec, err := compileHead(typ, map[uintptr]decoder{}) + dec, err := compileHead(typ, map[uintptr]Decoder{}) if err != nil { return nil, err } diff --git a/internal/decoder/compile_race.go b/internal/decoder/compile_race.go index f72896c..b691bc9 100644 --- a/internal/decoder/compile_race.go +++ b/internal/decoder/compile_race.go @@ -11,7 +11,7 @@ import ( var decMu sync.RWMutex -func CompileToGetDecoder(typ *runtime.Type) (decoder, error) { +func CompileToGetDecoder(typ *runtime.Type) (Decoder, error) { typeptr := uintptr(unsafe.Pointer(typ)) if typeptr > typeAddr.MaxTypeAddr { return compileToGetDecoderSlowPath(typeptr, typ) @@ -25,7 +25,7 @@ func CompileToGetDecoder(typ *runtime.Type) (decoder, error) { } decMu.RUnlock() - dec, err := compileHead(typ, map[uintptr]decoder{}) + dec, err := compileHead(typ, map[uintptr]Decoder{}) if err != nil { return nil, err } diff --git a/internal/decoder/interface.go b/internal/decoder/interface.go index a22ac35..a1bc9b5 100644 --- a/internal/decoder/interface.go +++ b/internal/decoder/interface.go @@ -85,7 +85,7 @@ func newInterfaceDecoder(typ *runtime.Type, structName, fieldName string) *inter } } -func (d *interfaceDecoder) numDecoder(s *Stream) decoder { +func (d *interfaceDecoder) numDecoder(s *Stream) Decoder { if s.UseNumber { return d.numberDecoder } diff --git a/internal/decoder/map.go b/internal/decoder/map.go index f3a60de..501f009 100644 --- a/internal/decoder/map.go +++ b/internal/decoder/map.go @@ -11,13 +11,13 @@ type mapDecoder struct { mapType *runtime.Type keyType *runtime.Type valueType *runtime.Type - keyDecoder decoder - valueDecoder decoder + keyDecoder Decoder + valueDecoder Decoder structName string fieldName string } -func newMapDecoder(mapType *runtime.Type, keyType *runtime.Type, keyDec decoder, valueType *runtime.Type, valueDec decoder, structName, fieldName string) *mapDecoder { +func newMapDecoder(mapType *runtime.Type, keyType *runtime.Type, keyDec Decoder, valueType *runtime.Type, valueDec Decoder, structName, fieldName string) *mapDecoder { return &mapDecoder{ mapType: mapType, keyDecoder: keyDec, diff --git a/internal/decoder/ptr.go b/internal/decoder/ptr.go index 133cc7c..fa8ed03 100644 --- a/internal/decoder/ptr.go +++ b/internal/decoder/ptr.go @@ -7,13 +7,13 @@ import ( ) type ptrDecoder struct { - dec decoder + dec Decoder typ *runtime.Type structName string fieldName string } -func newPtrDecoder(dec decoder, typ *runtime.Type, structName, fieldName string) *ptrDecoder { +func newPtrDecoder(dec Decoder, typ *runtime.Type, structName, fieldName string) *ptrDecoder { return &ptrDecoder{ dec: dec, typ: typ, @@ -22,7 +22,7 @@ func newPtrDecoder(dec decoder, typ *runtime.Type, structName, fieldName string) } } -func (d *ptrDecoder) contentDecoder() decoder { +func (d *ptrDecoder) contentDecoder() Decoder { dec, ok := d.dec.(*ptrDecoder) if !ok { return d.dec diff --git a/internal/decoder/slice.go b/internal/decoder/slice.go index 376d0f1..3584f8a 100644 --- a/internal/decoder/slice.go +++ b/internal/decoder/slice.go @@ -12,7 +12,7 @@ import ( type sliceDecoder struct { elemType *runtime.Type isElemPointerType bool - valueDecoder decoder + valueDecoder Decoder size uintptr arrayPool sync.Pool structName string @@ -32,7 +32,7 @@ const ( defaultSliceCapacity = 2 ) -func newSliceDecoder(dec decoder, elemType *runtime.Type, size uintptr, structName, fieldName string) *sliceDecoder { +func newSliceDecoder(dec Decoder, elemType *runtime.Type, size uintptr, structName, fieldName string) *sliceDecoder { return &sliceDecoder{ valueDecoder: dec, elemType: elemType, diff --git a/internal/decoder/struct.go b/internal/decoder/struct.go index 95e10c2..253f046 100644 --- a/internal/decoder/struct.go +++ b/internal/decoder/struct.go @@ -12,7 +12,7 @@ import ( ) type structFieldSet struct { - dec decoder + dec Decoder offset uintptr isTaggedKey bool key string diff --git a/internal/decoder/type.go b/internal/decoder/type.go index 89695a2..fd9ffb9 100644 --- a/internal/decoder/type.go +++ b/internal/decoder/type.go @@ -7,7 +7,7 @@ import ( "unsafe" ) -type decoder interface { +type Decoder interface { Decode([]byte, int64, int64, unsafe.Pointer) (int64, error) DecodeStream(*Stream, int64, unsafe.Pointer) error } diff --git a/internal/decoder/wrapped_string.go b/internal/decoder/wrapped_string.go index 5015db3..8dbdb3a 100644 --- a/internal/decoder/wrapped_string.go +++ b/internal/decoder/wrapped_string.go @@ -9,14 +9,14 @@ import ( type wrappedStringDecoder struct { typ *runtime.Type - dec decoder + dec Decoder stringDecoder *stringDecoder structName string fieldName string isPtrType bool } -func newWrappedStringDecoder(typ *runtime.Type, dec decoder, structName, fieldName string) *wrappedStringDecoder { +func newWrappedStringDecoder(typ *runtime.Type, dec Decoder, structName, fieldName string) *wrappedStringDecoder { return &wrappedStringDecoder{ typ: typ, dec: dec,