Encode prints the object as YAML.
(obj any)
| 38 | |
| 39 | // Encode prints the object as YAML. |
| 40 | func (p *Encoder) Encode(obj any) error { |
| 41 | count := atomic.AddInt64(&p.printCount, 1) |
| 42 | if count > 1 { |
| 43 | if _, err := p.w.Write(separator); err != nil { |
| 44 | return err |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | output, err := Marshal(obj) |
| 49 | if err != nil { |
| 50 | return err |
| 51 | } |
| 52 | |
| 53 | _, err = p.w.Write(output) |
| 54 | if err != nil { |
| 55 | return err |
| 56 | } |
| 57 | |
| 58 | return nil |
| 59 | } |