Fix bug in json framer.

pull/6/head
Wojciech Tyczynski 2016-05-04 11:35:06 +02:00
parent 3aadafd411
commit 11849e232e
1 changed files with 2 additions and 1 deletions

View File

@ -145,6 +145,7 @@ func (r *jsonFrameReader) Read(data []byte) (int, error) {
// RawMessage#Unmarshal appends to data - we reset the slice down to 0 and will either see
// data written to data, or be larger than data and a different array.
n := len(data)
m := json.RawMessage(data[:0])
if err := r.decoder.Decode(&m); err != nil {
return 0, err
@ -153,7 +154,7 @@ func (r *jsonFrameReader) Read(data []byte) (int, error) {
// If capacity of data is less than length of the message, decoder will allocate a new slice
// and set m to it, which means we need to copy the partial result back into data and preserve
// the remaining result for subsequent reads.
if n := cap(data); len(m) > n {
if len(m) > n {
data = append(data[0:0], m[:n]...)
r.remaining = m[n:]
return n, io.ErrShortBuffer