(name string, v any)
| 20 | } |
| 21 | |
| 22 | func (e *Encoder) Encode(name string, v any) error { |
| 23 | if err := e.writeByte(Compound); err != nil { |
| 24 | return err |
| 25 | } |
| 26 | if !e.dontWriteRootCompoundName { |
| 27 | if err := e.writeString(name); err != nil { |
| 28 | return err |
| 29 | } |
| 30 | } |
| 31 | val := reflect.ValueOf(v) |
| 32 | switch val.Kind() { |
| 33 | case reflect.Struct: |
| 34 | return e.encodeCompoundStruct(val) |
| 35 | case reflect.Map: |
| 36 | return e.encodeCompoundMap(val) |
| 37 | default: |
| 38 | return fmt.Errorf("Encode expects map/struct, not %s", val.Type()) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | func (e *Encoder) WriteRootName(val bool) { |
| 43 | e.dontWriteRootCompoundName = !val |
no test coverage detected