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

Function getPrimitiveSize

go/fory/codegen/utils.go:255–283  ·  view source on GitHub ↗

getPrimitiveSize returns the byte size of a primitive type

(t types.Type)

Source from the content-addressed store, hash-verified

253
254// getPrimitiveSize returns the byte size of a primitive type
255func getPrimitiveSize(t types.Type) int {
256 // Unwrap alias types
257 t = types.Unalias(t)
258 if elem, ok := getOptionalElementType(t); ok {
259 t = elem
260 }
261
262 // Handle pointer types
263 if ptr, ok := t.(*types.Pointer); ok {
264 t = ptr.Elem()
265 }
266
267 if basic, ok := t.Underlying().(*types.Basic); ok {
268 switch basic.Kind() {
269 case types.Bool, types.Int8, types.Uint8:
270 return 1
271 case types.Int16, types.Uint16:
272 return 2
273 case types.Int32, types.Uint32, types.Float32:
274 return 4
275 case types.Int, types.Int64, types.Uint, types.Uint64, types.Float64:
276 return 8
277 case types.String:
278 return 999 // Variable size, sort last among primitives
279 }
280 }
281
282 return 0
283}
284
285// getTypeIDValue returns numeric value for type ID for sorting
286// This uses the actual Fory TypeId constants for accuracy

Callers 1

analyzeFieldFunction · 0.85

Calls 2

getOptionalElementTypeFunction · 0.85
KindMethod · 0.80

Tested by

no test coverage detected