MCPcopy Create free account
hub / github.com/apache/fory / getTypeID

Function getTypeID

go/fory/codegen/utils.go:176–252  ·  view source on GitHub ↗

getTypeID returns the Fory TypeID for a given type

(t types.Type)

Source from the content-addressed store, hash-verified

174
175// getTypeID returns the Fory TypeID for a given type
176func getTypeID(t types.Type) string {
177 // Unwrap alias types
178 t = types.Unalias(t)
179 if elem, ok := getOptionalElementType(t); ok {
180 t = elem
181 }
182
183 // Handle pointer types
184 if ptr, ok := t.(*types.Pointer); ok {
185 t = ptr.Elem()
186 }
187
188 // Check slice types. Unannotated Go slices are logical list<T> fields;
189 // explicit array(...) tags are handled by runtime field metadata.
190 if _, ok := t.(*types.Slice); ok {
191 return "LIST"
192 }
193
194 // Check map types
195 if _, ok := t.(*types.Map); ok {
196 return "MAP"
197 }
198
199 // Check interface types
200 if iface, ok := t.(*types.Interface); ok {
201 if iface.Empty() {
202 return "INTERFACE" // Use a placeholder for empty any
203 }
204 }
205
206 // Check named types first
207 if named, ok := t.(*types.Named); ok {
208 typeStr := named.String()
209 switch typeStr {
210 case "time.Time":
211 return "TIMESTAMP"
212 case "github.com/apache/fory/go/fory.Date":
213 return "DATE"
214 }
215 // Struct types
216 if _, ok := named.Underlying().(*types.Struct); ok {
217 return "NAMED_STRUCT"
218 }
219 }
220
221 // Check basic types
222 if basic, ok := t.Underlying().(*types.Basic); ok {
223 switch basic.Kind() {
224 case types.Bool:
225 return "BOOL"
226 case types.Int8:
227 return "INT8"
228 case types.Int16:
229 return "INT16"
230 case types.Int32:
231 return "VARINT32"
232 case types.Int, types.Int64:
233 return "VARINT64"

Callers 1

analyzeFieldFunction · 0.85

Calls 4

getOptionalElementTypeFunction · 0.85
KindMethod · 0.80
EmptyMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected