mirror of https://github.com/goccy/go-json.git
Fix error by linter
This commit is contained in:
parent
45780881a4
commit
c41c158a56
|
@ -9,10 +9,10 @@ import (
|
||||||
type anonymousFieldDecoder struct {
|
type anonymousFieldDecoder struct {
|
||||||
structType *runtime.Type
|
structType *runtime.Type
|
||||||
offset uintptr
|
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{
|
return &anonymousFieldDecoder{
|
||||||
structType: structType,
|
structType: structType,
|
||||||
offset: offset,
|
offset: offset,
|
||||||
|
|
|
@ -10,14 +10,14 @@ import (
|
||||||
type arrayDecoder struct {
|
type arrayDecoder struct {
|
||||||
elemType *runtime.Type
|
elemType *runtime.Type
|
||||||
size uintptr
|
size uintptr
|
||||||
valueDecoder decoder
|
valueDecoder Decoder
|
||||||
alen int
|
alen int
|
||||||
structName string
|
structName string
|
||||||
fieldName string
|
fieldName string
|
||||||
zeroValue unsafe.Pointer
|
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))
|
zeroValue := *(*unsafe.Pointer)(unsafe_New(elemType))
|
||||||
return &arrayDecoder{
|
return &arrayDecoder{
|
||||||
valueDecoder: dec,
|
valueDecoder: dec,
|
||||||
|
|
|
@ -10,13 +10,13 @@ import (
|
||||||
|
|
||||||
type bytesDecoder struct {
|
type bytesDecoder struct {
|
||||||
typ *runtime.Type
|
typ *runtime.Type
|
||||||
sliceDecoder decoder
|
sliceDecoder Decoder
|
||||||
structName string
|
structName string
|
||||||
fieldName string
|
fieldName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func byteUnmarshalerSliceDecoder(typ *runtime.Type, structName string, fieldName string) decoder {
|
func byteUnmarshalerSliceDecoder(typ *runtime.Type, structName string, fieldName string) Decoder {
|
||||||
var unmarshalDecoder decoder
|
var unmarshalDecoder Decoder
|
||||||
switch {
|
switch {
|
||||||
case runtime.PtrTo(typ).Implements(unmarshalJSONType):
|
case runtime.PtrTo(typ).Implements(unmarshalJSONType):
|
||||||
unmarshalDecoder = newUnmarshalJSONDecoder(runtime.PtrTo(typ), structName, fieldName)
|
unmarshalDecoder = newUnmarshalJSONDecoder(runtime.PtrTo(typ), structName, fieldName)
|
||||||
|
|
|
@ -17,7 +17,7 @@ var (
|
||||||
jsonNumberType = reflect.TypeOf(json.Number(""))
|
jsonNumberType = reflect.TypeOf(json.Number(""))
|
||||||
typeAddr *runtime.TypeAddr
|
typeAddr *runtime.TypeAddr
|
||||||
cachedDecoderMap unsafe.Pointer // map[uintptr]decoder
|
cachedDecoderMap unsafe.Pointer // map[uintptr]decoder
|
||||||
cachedDecoder []decoder
|
cachedDecoder []Decoder
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -25,16 +25,16 @@ func init() {
|
||||||
if typeAddr == nil {
|
if typeAddr == nil {
|
||||||
typeAddr = &runtime.TypeAddr{}
|
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)
|
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) {
|
func storeDecoder(typ uintptr, dec Decoder, m map[uintptr]Decoder) {
|
||||||
newDecoderMap := make(map[uintptr]decoder, len(m)+1)
|
newDecoderMap := make(map[uintptr]Decoder, len(m)+1)
|
||||||
newDecoderMap[typ] = dec
|
newDecoderMap[typ] = dec
|
||||||
|
|
||||||
for k, v := range m {
|
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)))
|
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()
|
decoderMap := loadDecoderMap()
|
||||||
if dec, exists := decoderMap[typeptr]; exists {
|
if dec, exists := decoderMap[typeptr]; exists {
|
||||||
return dec, nil
|
return dec, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
dec, err := compileHead(typ, map[uintptr]decoder{})
|
dec, err := compileHead(typ, map[uintptr]Decoder{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ func compileToGetDecoderSlowPath(typeptr uintptr, typ *runtime.Type) (decoder, e
|
||||||
return dec, nil
|
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 {
|
switch {
|
||||||
case runtime.PtrTo(typ).Implements(unmarshalJSONType):
|
case runtime.PtrTo(typ).Implements(unmarshalJSONType):
|
||||||
return newUnmarshalJSONDecoder(runtime.PtrTo(typ), "", ""), nil
|
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)
|
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 {
|
switch {
|
||||||
case runtime.PtrTo(typ).Implements(unmarshalJSONType):
|
case runtime.PtrTo(typ).Implements(unmarshalJSONType):
|
||||||
return newUnmarshalJSONDecoder(runtime.PtrTo(typ), structName, fieldName), nil
|
return newUnmarshalJSONDecoder(runtime.PtrTo(typ), structName, fieldName), nil
|
||||||
|
@ -153,7 +153,7 @@ func isStringTagSupportedType(typ *runtime.Type) bool {
|
||||||
return true
|
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) {
|
if runtime.PtrTo(typ).Implements(unmarshalTextType) {
|
||||||
return newUnmarshalTextDecoder(runtime.PtrTo(typ), structName, fieldName), nil
|
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)
|
dec, err := compile(typ.Elem(), structName, fieldName, structTypeToDecoder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -189,79 +189,79 @@ func compilePtr(typ *runtime.Type, structName, fieldName string, structTypeToDec
|
||||||
return newPtrDecoder(dec, typ.Elem(), structName, fieldName), nil
|
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) {
|
return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) {
|
||||||
*(*int)(p) = int(v)
|
*(*int)(p) = int(v)
|
||||||
}), nil
|
}), 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) {
|
return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) {
|
||||||
*(*int8)(p) = int8(v)
|
*(*int8)(p) = int8(v)
|
||||||
}), nil
|
}), 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) {
|
return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) {
|
||||||
*(*int16)(p) = int16(v)
|
*(*int16)(p) = int16(v)
|
||||||
}), nil
|
}), 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) {
|
return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) {
|
||||||
*(*int32)(p) = int32(v)
|
*(*int32)(p) = int32(v)
|
||||||
}), nil
|
}), 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) {
|
return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) {
|
||||||
*(*int64)(p) = v
|
*(*int64)(p) = v
|
||||||
}), nil
|
}), 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) {
|
return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) {
|
||||||
*(*uint)(p) = uint(v)
|
*(*uint)(p) = uint(v)
|
||||||
}), nil
|
}), 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) {
|
return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) {
|
||||||
*(*uint8)(p) = uint8(v)
|
*(*uint8)(p) = uint8(v)
|
||||||
}), nil
|
}), 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) {
|
return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) {
|
||||||
*(*uint16)(p) = uint16(v)
|
*(*uint16)(p) = uint16(v)
|
||||||
}), nil
|
}), 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) {
|
return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) {
|
||||||
*(*uint32)(p) = uint32(v)
|
*(*uint32)(p) = uint32(v)
|
||||||
}), nil
|
}), 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) {
|
return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) {
|
||||||
*(*uint64)(p) = v
|
*(*uint64)(p) = v
|
||||||
}), nil
|
}), 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) {
|
return newFloatDecoder(structName, fieldName, func(p unsafe.Pointer, v float64) {
|
||||||
*(*float32)(p) = float32(v)
|
*(*float32)(p) = float32(v)
|
||||||
}), nil
|
}), 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) {
|
return newFloatDecoder(structName, fieldName, func(p unsafe.Pointer, v float64) {
|
||||||
*(*float64)(p) = v
|
*(*float64)(p) = v
|
||||||
}), nil
|
}), 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) {
|
if typ == runtime.Type2RType(jsonNumberType) {
|
||||||
return newNumberDecoder(structName, fieldName, func(p unsafe.Pointer, v json.Number) {
|
return newNumberDecoder(structName, fieldName, func(p unsafe.Pointer, v json.Number) {
|
||||||
*(*json.Number)(p) = v
|
*(*json.Number)(p) = v
|
||||||
|
@ -270,15 +270,15 @@ func compileString(typ *runtime.Type, structName, fieldName string) (decoder, er
|
||||||
return newStringDecoder(structName, fieldName), nil
|
return newStringDecoder(structName, fieldName), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func compileBool(structName, fieldName string) (decoder, error) {
|
func compileBool(structName, fieldName string) (Decoder, error) {
|
||||||
return newBoolDecoder(structName, fieldName), nil
|
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
|
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()
|
elem := typ.Elem()
|
||||||
decoder, err := compile(elem, structName, fieldName, structTypeToDecoder)
|
decoder, err := compile(elem, structName, fieldName, structTypeToDecoder)
|
||||||
if err != nil {
|
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
|
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()
|
elem := typ.Elem()
|
||||||
decoder, err := compile(elem, structName, fieldName, structTypeToDecoder)
|
decoder, err := compile(elem, structName, fieldName, structTypeToDecoder)
|
||||||
if err != nil {
|
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
|
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)
|
keyDec, err := compileMapKey(typ.Key(), structName, fieldName, structTypeToDecoder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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
|
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
|
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()
|
fieldNum := typ.NumField()
|
||||||
conflictedMap := map[string]struct{}{}
|
conflictedMap := map[string]struct{}{}
|
||||||
fieldMap := map[string]*structFieldSet{}
|
fieldMap := map[string]*structFieldSet{}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/goccy/go-json/internal/runtime"
|
"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))
|
typeptr := uintptr(unsafe.Pointer(typ))
|
||||||
if typeptr > typeAddr.MaxTypeAddr {
|
if typeptr > typeAddr.MaxTypeAddr {
|
||||||
return compileToGetDecoderSlowPath(typeptr, typ)
|
return compileToGetDecoderSlowPath(typeptr, typ)
|
||||||
|
@ -19,7 +19,7 @@ func CompileToGetDecoder(typ *runtime.Type) (decoder, error) {
|
||||||
return dec, nil
|
return dec, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
dec, err := compileHead(typ, map[uintptr]decoder{})
|
dec, err := compileHead(typ, map[uintptr]Decoder{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
var decMu sync.RWMutex
|
var decMu sync.RWMutex
|
||||||
|
|
||||||
func CompileToGetDecoder(typ *runtime.Type) (decoder, error) {
|
func CompileToGetDecoder(typ *runtime.Type) (Decoder, error) {
|
||||||
typeptr := uintptr(unsafe.Pointer(typ))
|
typeptr := uintptr(unsafe.Pointer(typ))
|
||||||
if typeptr > typeAddr.MaxTypeAddr {
|
if typeptr > typeAddr.MaxTypeAddr {
|
||||||
return compileToGetDecoderSlowPath(typeptr, typ)
|
return compileToGetDecoderSlowPath(typeptr, typ)
|
||||||
|
@ -25,7 +25,7 @@ func CompileToGetDecoder(typ *runtime.Type) (decoder, error) {
|
||||||
}
|
}
|
||||||
decMu.RUnlock()
|
decMu.RUnlock()
|
||||||
|
|
||||||
dec, err := compileHead(typ, map[uintptr]decoder{})
|
dec, err := compileHead(typ, map[uintptr]Decoder{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
if s.UseNumber {
|
||||||
return d.numberDecoder
|
return d.numberDecoder
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,13 +11,13 @@ type mapDecoder struct {
|
||||||
mapType *runtime.Type
|
mapType *runtime.Type
|
||||||
keyType *runtime.Type
|
keyType *runtime.Type
|
||||||
valueType *runtime.Type
|
valueType *runtime.Type
|
||||||
keyDecoder decoder
|
keyDecoder Decoder
|
||||||
valueDecoder decoder
|
valueDecoder Decoder
|
||||||
structName string
|
structName string
|
||||||
fieldName 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{
|
return &mapDecoder{
|
||||||
mapType: mapType,
|
mapType: mapType,
|
||||||
keyDecoder: keyDec,
|
keyDecoder: keyDec,
|
||||||
|
|
|
@ -7,13 +7,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type ptrDecoder struct {
|
type ptrDecoder struct {
|
||||||
dec decoder
|
dec Decoder
|
||||||
typ *runtime.Type
|
typ *runtime.Type
|
||||||
structName string
|
structName string
|
||||||
fieldName 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{
|
return &ptrDecoder{
|
||||||
dec: dec,
|
dec: dec,
|
||||||
typ: typ,
|
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)
|
dec, ok := d.dec.(*ptrDecoder)
|
||||||
if !ok {
|
if !ok {
|
||||||
return d.dec
|
return d.dec
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
type sliceDecoder struct {
|
type sliceDecoder struct {
|
||||||
elemType *runtime.Type
|
elemType *runtime.Type
|
||||||
isElemPointerType bool
|
isElemPointerType bool
|
||||||
valueDecoder decoder
|
valueDecoder Decoder
|
||||||
size uintptr
|
size uintptr
|
||||||
arrayPool sync.Pool
|
arrayPool sync.Pool
|
||||||
structName string
|
structName string
|
||||||
|
@ -32,7 +32,7 @@ const (
|
||||||
defaultSliceCapacity = 2
|
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{
|
return &sliceDecoder{
|
||||||
valueDecoder: dec,
|
valueDecoder: dec,
|
||||||
elemType: elemType,
|
elemType: elemType,
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type structFieldSet struct {
|
type structFieldSet struct {
|
||||||
dec decoder
|
dec Decoder
|
||||||
offset uintptr
|
offset uintptr
|
||||||
isTaggedKey bool
|
isTaggedKey bool
|
||||||
key string
|
key string
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
type decoder interface {
|
type Decoder interface {
|
||||||
Decode([]byte, int64, int64, unsafe.Pointer) (int64, error)
|
Decode([]byte, int64, int64, unsafe.Pointer) (int64, error)
|
||||||
DecodeStream(*Stream, int64, unsafe.Pointer) error
|
DecodeStream(*Stream, int64, unsafe.Pointer) error
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,14 +9,14 @@ import (
|
||||||
|
|
||||||
type wrappedStringDecoder struct {
|
type wrappedStringDecoder struct {
|
||||||
typ *runtime.Type
|
typ *runtime.Type
|
||||||
dec decoder
|
dec Decoder
|
||||||
stringDecoder *stringDecoder
|
stringDecoder *stringDecoder
|
||||||
structName string
|
structName string
|
||||||
fieldName string
|
fieldName string
|
||||||
isPtrType bool
|
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{
|
return &wrappedStringDecoder{
|
||||||
typ: typ,
|
typ: typ,
|
||||||
dec: dec,
|
dec: dec,
|
||||||
|
|
Loading…
Reference in New Issue