MCPcopy
hub / github.com/pquerna/ffjson / handleFieldAddr

Function handleFieldAddr

inception/decoder.go:67–191  ·  view source on GitHub ↗
(ic *Inception, name string, takeAddr bool, typ reflect.Type, ptr bool, quoted bool)

Source from the content-addressed store, hash-verified

65}
66
67func handleFieldAddr(ic *Inception, name string, takeAddr bool, typ reflect.Type, ptr bool, quoted bool) string {
68 out := fmt.Sprintf("/* handler: %s type=%v kind=%v quoted=%t*/\n", name, typ, typ.Kind(), quoted)
69
70 umlx := typ.Implements(unmarshalFasterType) || typeInInception(ic, typ, shared.MustDecoder)
71 umlx = umlx || reflect.PtrTo(typ).Implements(unmarshalFasterType)
72
73 umlstd := typ.Implements(unmarshalerType) || reflect.PtrTo(typ).Implements(unmarshalerType)
74
75 out += tplStr(decodeTpl["handleUnmarshaler"], handleUnmarshaler{
76 IC: ic,
77 Name: name,
78 Typ: typ,
79 Ptr: reflect.Ptr,
80 TakeAddr: takeAddr || ptr,
81 UnmarshalJSONFFLexer: umlx,
82 Unmarshaler: umlstd,
83 })
84
85 if umlx || umlstd {
86 return out
87 }
88
89 // TODO(pquerna): generic handling of token type mismatching struct type
90 switch typ.Kind() {
91 case reflect.Int,
92 reflect.Int8,
93 reflect.Int16,
94 reflect.Int32,
95 reflect.Int64:
96
97 allowed := buildTokens(quoted, "FFTok_string", "FFTok_integer", "FFTok_null")
98 out += getAllowTokens(typ.Name(), allowed...)
99
100 out += getNumberHandler(ic, name, takeAddr || ptr, typ, "ParseInt")
101
102 case reflect.Uint,
103 reflect.Uint8,
104 reflect.Uint16,
105 reflect.Uint32,
106 reflect.Uint64:
107
108 allowed := buildTokens(quoted, "FFTok_string", "FFTok_integer", "FFTok_null")
109 out += getAllowTokens(typ.Name(), allowed...)
110
111 out += getNumberHandler(ic, name, takeAddr || ptr, typ, "ParseUint")
112
113 case reflect.Float32,
114 reflect.Float64:
115
116 allowed := buildTokens(quoted, "FFTok_string", "FFTok_double", "FFTok_integer", "FFTok_null")
117 out += getAllowTokens(typ.Name(), allowed...)
118
119 out += getNumberHandler(ic, name, takeAddr || ptr, typ, "ParseFloat")
120
121 case reflect.Bool:
122 ic.OutputImports[`"bytes"`] = true
123 ic.OutputImports[`"errors"`] = true
124

Callers 1

handleFieldFunction · 0.85

Calls 6

typeInInceptionFunction · 0.85
tplStrFunction · 0.85
buildTokensFunction · 0.85
getAllowTokensFunction · 0.85
getNumberHandlerFunction · 0.85
getArrayHandlerFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…