(tinfo *typeInfo, val reflect.Value)
| 824 | } |
| 825 | |
| 826 | func (p *printer) marshalStruct(tinfo *typeInfo, val reflect.Value) error { |
| 827 | s := parentStack{p: p} |
| 828 | for i := range tinfo.fields { |
| 829 | finfo := &tinfo.fields[i] |
| 830 | if finfo.flags&fAttr != 0 { |
| 831 | continue |
| 832 | } |
| 833 | vf := finfo.value(val, dontInitNilPointers) |
| 834 | if !vf.IsValid() { |
| 835 | // The field is behind an anonymous struct field that's |
| 836 | // nil. Skip it. |
| 837 | continue |
| 838 | } |
| 839 | |
| 840 | switch finfo.flags & fMode { |
| 841 | case fCDATA, fCharData: |
| 842 | emit := EscapeText |
| 843 | if finfo.flags&fMode == fCDATA { |
| 844 | emit = emitCDATA |
| 845 | } |
| 846 | if err := s.trim(finfo.parents); err != nil { |
| 847 | return err |
| 848 | } |
| 849 | if vf.CanInterface() && vf.Type().Implements(textMarshalerType) { |
| 850 | data, err := vf.Interface().(encoding.TextMarshaler).MarshalText() |
| 851 | if err != nil { |
| 852 | return err |
| 853 | } |
| 854 | if err := emit(p, data); err != nil { |
| 855 | return err |
| 856 | } |
| 857 | continue |
| 858 | } |
| 859 | if vf.CanAddr() { |
| 860 | pv := vf.Addr() |
| 861 | if pv.CanInterface() && pv.Type().Implements(textMarshalerType) { |
| 862 | data, err := pv.Interface().(encoding.TextMarshaler).MarshalText() |
| 863 | if err != nil { |
| 864 | return err |
| 865 | } |
| 866 | if err := emit(p, data); err != nil { |
| 867 | return err |
| 868 | } |
| 869 | continue |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | var scratch [64]byte |
| 874 | vf = indirect(vf) |
| 875 | switch vf.Kind() { |
| 876 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: |
| 877 | if err := emit(p, strconv.AppendInt(scratch[:0], vf.Int(), 10)); err != nil { |
| 878 | return err |
| 879 | } |
| 880 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: |
| 881 | if err := emit(p, strconv.AppendUint(scratch[:0], vf.Uint(), 10)); err != nil { |
| 882 | return err |
| 883 | } |
no test coverage detected