MCPcopy
hub / github.com/go-yaml/yaml / structv

Method structv

encode.go:214–254  ·  view source on GitHub ↗
(tag string, in reflect.Value)

Source from the content-addressed store, hash-verified

212}
213
214func (e *encoder) structv(tag string, in reflect.Value) {
215 sinfo, err := getStructInfo(in.Type())
216 if err != nil {
217 panic(err)
218 }
219 e.mappingv(tag, func() {
220 for _, info := range sinfo.FieldsList {
221 var value reflect.Value
222 if info.Inline == nil {
223 value = in.Field(info.Num)
224 } else {
225 value = e.fieldByIndex(in, info.Inline)
226 if !value.IsValid() {
227 continue
228 }
229 }
230 if info.OmitEmpty && isZero(value) {
231 continue
232 }
233 e.marshal("", reflect.ValueOf(info.Key))
234 e.flow = info.Flow
235 e.marshal("", value)
236 }
237 if sinfo.InlineMap >= 0 {
238 m := in.Field(sinfo.InlineMap)
239 if m.Len() > 0 {
240 e.flow = false
241 keys := keyList(m.MapKeys())
242 sort.Sort(keys)
243 for _, k := range keys {
244 if _, found := sinfo.FieldsMap[k.String()]; found {
245 panic(fmt.Sprintf("cannot have key %q in inlined map: conflicts with struct field", k.String()))
246 }
247 e.marshal("", k)
248 e.flow = false
249 e.marshal("", m.MapIndex(k))
250 }
251 }
252 }
253 })
254}
255
256func (e *encoder) mappingv(tag string, f func()) {
257 implicit := tag == ""

Callers 1

marshalMethod · 0.95

Calls 8

mappingvMethod · 0.95
fieldByIndexMethod · 0.95
marshalMethod · 0.95
getStructInfoFunction · 0.85
isZeroFunction · 0.85
keyListTypeAlias · 0.85
LenMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected