MCPcopy
hub / github.com/uptrace/uptrace / encodeStruct

Method encodeStruct

pkg/msgp/encoder.go:139–195  ·  view source on GitHub ↗
(b []byte, p unsafe.Pointer, st *structType)

Source from the content-addressed store, hash-verified

137 return AppendMapStringBool(b, *(*map[string]bool)(p), e.flags)
138}
139func (e encoder) encodeStruct(b []byte, p unsafe.Pointer, st *structType) (_ []byte, err error) {
140 if e.flags&ArrayEncodedStructs != 0 {
141 var numField int
142 start := len(b)
143 if len(st.fieldList) < 16 {
144 b = AppendMapLen8(b, numField)
145 } else {
146 b = AppendMapLen16(b, numField)
147 }
148 for id, f := range st.fieldList {
149 v := unsafe.Pointer(uintptr(p) + f.offset)
150 if f.empty(v) {
151 continue
152 }
153 numField++
154 b = AppendUvarint(b, uint64(id))
155 if b, err = f.codec.encode(e, b, v); err != nil {
156 return b, err
157 }
158 }
159 if len(st.fieldList) < 16 {
160 AppendMapLen8(b[:start], numField)
161 } else {
162 AppendMapLen16(b[:start], numField)
163 }
164 return b, nil
165 }
166 var numField int
167 start := len(b)
168 if len(st.fields) < 16 {
169 b = AppendMapLen8(b, numField)
170 } else {
171 b = AppendMapLen16(b, numField)
172 }
173 for i := range st.fields {
174 f := &st.fields[i]
175 v := unsafe.Pointer(uintptr(p) + f.offset)
176 if f.empty(v) {
177 continue
178 }
179 numField++
180 if f.id != -1 {
181 b = AppendUvarint(b, uint64(f.id))
182 } else {
183 b = AppendString(b, f.name)
184 }
185 if b, err = f.codec.encode(e, b, v); err != nil {
186 return b, err
187 }
188 }
189 if len(st.fields) < 16 {
190 AppendMapLen8(b[:start], numField)
191 } else {
192 AppendMapLen16(b[:start], numField)
193 }
194 return b, nil
195}
196func (e encoder) encodeEmbeddedStructPointer(b []byte, p unsafe.Pointer, t reflect.Type, offset uintptr, encode encodeFunc) ([]byte, error) {

Callers 1

createStructEncodeFuncFunction · 0.80

Calls 6

AppendMapLen8Function · 0.85
AppendMapLen16Function · 0.85
AppendUvarintFunction · 0.85
PointerMethod · 0.80
emptyMethod · 0.80
AppendStringFunction · 0.70

Tested by

no test coverage detected