(tag string, in reflect.Value)
| 212 | } |
| 213 | |
| 214 | func (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 | |
| 256 | func (e *encoder) mappingv(tag string, f func()) { |
| 257 | implicit := tag == "" |
no test coverage detected