(rv reflect.Value)
| 95 | } |
| 96 | |
| 97 | func (e *encoder) encodeStruct(rv reflect.Value) (cbor.Value, error) { |
| 98 | if rv.CanInterface() && document.IsNoSerde(rv.Interface()) { |
| 99 | return nil, &document.UnmarshalTypeError{ |
| 100 | Value: fmt.Sprintf("unsupported type"), |
| 101 | Type: rv.Type(), |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | switch { |
| 106 | case rv.Type().ConvertibleTo(serde.ReflectTypeOf.Time): |
| 107 | return nil, &document.InvalidMarshalError{ |
| 108 | Message: fmt.Sprintf("unsupported type %s", rv.Type().String()), |
| 109 | } |
| 110 | case rv.Type().ConvertibleTo(serde.ReflectTypeOf.BigFloat): |
| 111 | fallthrough |
| 112 | case rv.Type().ConvertibleTo(serde.ReflectTypeOf.BigInt): |
| 113 | return e.encodeNumber(rv) |
| 114 | } |
| 115 | |
| 116 | fields := serde.GetStructFields(rv.Type()) |
| 117 | |
| 118 | mv := cbor.Map{} |
| 119 | for _, f := range fields.All() { |
| 120 | if f.Name == "" { |
| 121 | return nil, &document.InvalidMarshalError{Message: "map key cannot be empty"} |
| 122 | } |
| 123 | |
| 124 | fv, found := serde.EncoderFieldByIndex(rv, f.Index) |
| 125 | if !found { |
| 126 | continue |
| 127 | } |
| 128 | |
| 129 | cv, err := e.encode(fv, f.Tag) |
| 130 | if err != nil { |
| 131 | return nil, err |
| 132 | } |
| 133 | if cv == nil { // from omitEmpty |
| 134 | continue |
| 135 | } |
| 136 | |
| 137 | mv[f.Name] = cv |
| 138 | } |
| 139 | |
| 140 | return mv, nil |
| 141 | } |
| 142 | |
| 143 | func (e *encoder) encodeMap(rv reflect.Value) (cbor.Map, error) { |
| 144 | mv := cbor.Map{} |
no test coverage detected