UnmarshalAsJSON takes raw messagepack and writes it as JSON to 'w'. If an error is returned, the bytes not translated will also be returned. If no errors are encountered, the length of the returned slice will be zero.
(w io.Writer, msg []byte)
| 38 | // no errors are encountered, the length of the returned |
| 39 | // slice will be zero. |
| 40 | func UnmarshalAsJSON(w io.Writer, msg []byte) ([]byte, error) { |
| 41 | var ( |
| 42 | scratch []byte |
| 43 | cast bool |
| 44 | dst jsWriter |
| 45 | err error |
| 46 | ) |
| 47 | if jsw, ok := w.(jsWriter); ok { |
| 48 | dst = jsw |
| 49 | cast = true |
| 50 | } else { |
| 51 | dst = bufio.NewWriterSize(w, 512) |
| 52 | } |
| 53 | for len(msg) > 0 && err == nil { |
| 54 | msg, scratch, err = writeNext(dst, msg, scratch, 0) |
| 55 | } |
| 56 | if !cast && err == nil { |
| 57 | err = dst.(*bufio.Writer).Flush() |
| 58 | } |
| 59 | return msg, err |
| 60 | } |
| 61 | |
| 62 | func writeNext(w jsWriter, msg []byte, scratch []byte, depth int) ([]byte, []byte, error) { |
| 63 | if len(msg) < 1 { |
searching dependent graphs…