(f *codecFnInfo, rv reflect.Value)
| 530 | } |
| 531 | |
| 532 | func (e *Encoder) kStruct(f *codecFnInfo, rv reflect.Value) { |
| 533 | var newlen int |
| 534 | ti := f.ti |
| 535 | toMap := !(ti.toArray || e.h.StructToArray) |
| 536 | var mf map[string]interface{} |
| 537 | if ti.flagMissingFielder { |
| 538 | mf = rv2i(rv).(MissingFielder).CodecMissingFields() |
| 539 | toMap = true |
| 540 | newlen += len(mf) |
| 541 | } else if ti.flagMissingFielderPtr { |
| 542 | rv2 := e.addrRV(rv, ti.rt, ti.ptr) |
| 543 | mf = rv2i(rv2).(MissingFielder).CodecMissingFields() |
| 544 | toMap = true |
| 545 | newlen += len(mf) |
| 546 | } |
| 547 | tisfi := ti.sfi.source() |
| 548 | newlen += len(tisfi) |
| 549 | |
| 550 | var fkvs = e.slist.get(newlen)[:newlen] |
| 551 | |
| 552 | recur := e.h.RecursiveEmptyCheck |
| 553 | |
| 554 | var kv sfiRv |
| 555 | var j int |
| 556 | if toMap { |
| 557 | newlen = 0 |
| 558 | for _, si := range e.kStructSfi(f) { |
| 559 | kv.r = si.path.field(rv) |
| 560 | if si.path.omitEmpty && isEmptyValue(kv.r, e.h.TypeInfos, recur) { |
| 561 | continue |
| 562 | } |
| 563 | kv.v = si |
| 564 | fkvs[newlen] = kv |
| 565 | newlen++ |
| 566 | } |
| 567 | |
| 568 | var mf2s []stringIntf |
| 569 | if len(mf) > 0 { |
| 570 | mf2s = make([]stringIntf, 0, len(mf)) |
| 571 | for k, v := range mf { |
| 572 | if k == "" { |
| 573 | continue |
| 574 | } |
| 575 | if ti.infoFieldOmitempty && isEmptyValue(reflect.ValueOf(v), e.h.TypeInfos, recur) { |
| 576 | continue |
| 577 | } |
| 578 | mf2s = append(mf2s, stringIntf{k, v}) |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | e.mapStart(newlen + len(mf2s)) |
| 583 | |
| 584 | // When there are missing fields, and Canonical flag is set, |
| 585 | // we cannot have the missing fields and struct fields sorted independently. |
| 586 | // We have to capture them together and sort as a unit. |
| 587 | |
| 588 | if len(mf2s) > 0 && e.h.Canonical { |
| 589 | mf2w := make([]encStructFieldObj, newlen+len(mf2s)) |
nothing calls this directly
no test coverage detected