MCPcopy Create free account
hub / github.com/google/gapid / SizeOf

Function SizeOf

gapis/memory/alignof_sizeof.go:72–116  ·  view source on GitHub ↗

SizeOf returns the byte size of the type t.

(t reflect.Type, m *device.MemoryLayout)

Source from the content-addressed store, hash-verified

70
71// SizeOf returns the byte size of the type t.
72func SizeOf(t reflect.Type, m *device.MemoryLayout) uint64 {
73 switch t.Kind() {
74 case reflect.Uint8:
75 if t.Implements(tyCharTy) {
76 return uint64(m.GetChar().GetSize())
77 }
78 return uint64(m.GetI8().GetSize())
79 case reflect.Bool, reflect.Int8:
80 return uint64(m.GetI8().GetSize())
81 case reflect.Int16, reflect.Uint16:
82 return uint64(m.GetI16().GetSize())
83 case reflect.Int32, reflect.Uint32:
84 return uint64(m.GetI32().GetSize())
85 case reflect.Float32:
86 return uint64(m.GetF32().GetSize())
87 case reflect.Float64:
88 return uint64(m.GetF64().GetSize())
89 case reflect.Int64, reflect.Uint64:
90 switch {
91 case t.Implements(tyPointer):
92 return uint64(m.GetPointer().GetSize())
93 case t.Implements(tyIntTy) || t.Implements(tyUintTy):
94 return uint64(m.GetInteger().GetSize())
95 case t.Implements(tySizeTy):
96 return uint64(m.GetSize().GetSize())
97 default:
98 return uint64(m.GetI64().GetSize())
99 }
100 case reflect.Int, reflect.Uint:
101 return uint64(m.GetInteger().GetSize())
102 case reflect.Array:
103 return SizeOf(t.Elem(), m) * uint64(t.Len())
104 case reflect.String:
105 return 1
106 }
107
108 switch {
109 case t.Implements(tyPointer):
110 return uint64(m.GetPointer().GetSize())
111 case t.Implements(tySizedTy):
112 return reflect.New(t).Interface().(SizedTy).TypeSize(m)
113 }
114
115 panic(fmt.Errorf("MemoryLayout.SizeOf not implemented for type %v (%v)", t, t.Kind()))
116}

Callers 3

ElementSizeMethod · 0.85
decodeFunction · 0.85
encodeFunction · 0.85

Calls 7

ImplementsMethod · 0.80
TypeSizeMethod · 0.80
InterfaceMethod · 0.80
KindMethod · 0.65
LenMethod · 0.65
NewMethod · 0.65
GetSizeMethod · 0.45

Tested by

no test coverage detected