Encode the data in the supplied value to the stream given on creation. When the function returns the output has been written to the stream.
(v interface{})
| 56 | // When the function returns the output has been |
| 57 | // written to the stream. |
| 58 | func (e *Encoder) Encode(v interface{}) error { |
| 59 | f, ok := v.(marshalerFaster) |
| 60 | if ok { |
| 61 | e.buf.Reset() |
| 62 | err := f.MarshalJSONBuf(&e.buf) |
| 63 | if err != nil { |
| 64 | return err |
| 65 | } |
| 66 | |
| 67 | _, err = io.Copy(e.w, &e.buf) |
| 68 | return err |
| 69 | } |
| 70 | |
| 71 | return e.enc.Encode(v) |
| 72 | } |
| 73 | |
| 74 | // EncodeFast will unmarshal the data if fast marshall is available. |
| 75 | // This function can be used if you want to be sure the fast |