MCPcopy
hub / github.com/tinylib/msgp / WriteToJSON

Method WriteToJSON

msgp/json.go:63–88  ·  view source on GitHub ↗

WriteToJSON translates MessagePack from 'r' and writes it as JSON to 'w' until the underlying reader returns io.EOF. It returns the number of bytes written, and an error if it stopped before EOF.

(w io.Writer)

Source from the content-addressed store, hash-verified

61// JSON to 'w' until the underlying reader returns io.EOF. It returns
62// the number of bytes written, and an error if it stopped before EOF.
63func (m *Reader) WriteToJSON(w io.Writer) (n int64, err error) {
64 var j jsWriter
65 var bf *bufio.Writer
66 if jsw, ok := w.(jsWriter); ok {
67 j = jsw
68 } else {
69 bf = bufio.NewWriter(w)
70 j = bf
71 }
72 var nn int
73 for err == nil {
74 nn, err = rwNext(j, m)
75 n += int64(nn)
76 }
77 if err != io.EOF {
78 if bf != nil {
79 bf.Flush()
80 }
81 return
82 }
83 err = nil
84 if bf != nil {
85 err = bf.Flush()
86 }
87 return
88}
89
90func rwNext(w jsWriter, src *Reader) (int, error) {
91 t, err := src.NextType()

Callers 3

TestReadIntfRecursionFunction · 0.95
FuzzReaderFunction · 0.95
CopyToJSONFunction · 0.95

Calls 2

FlushMethod · 0.95
rwNextFunction · 0.85

Tested by 2

TestReadIntfRecursionFunction · 0.76
FuzzReaderFunction · 0.76