Esempio n. 1
0
func TestDecoder(t *testing.T) {
	frames := [][]byte{
		make([]byte, 1025),
		make([]byte, 1024*5),
		make([]byte, 1024*1024*5),
		make([]byte, 1025),
	}
	pr, pw := io.Pipe()
	fw := framer.NewLengthDelimitedFrameWriter(pw)
	go func() {
		for i := range frames {
			fw.Write(frames[i])
		}
		pw.Close()
	}()

	r := framer.NewLengthDelimitedFrameReader(pr)
	d := &fakeDecoder{}
	dec := NewDecoder(r, d)
	if _, _, err := dec.Decode(nil, nil); err != nil || !bytes.Equal(d.got, frames[0]) {
		t.Fatalf("unexpected %v %v", err, len(d.got))
	}
	if _, _, err := dec.Decode(nil, nil); err != nil || !bytes.Equal(d.got, frames[1]) {
		t.Fatalf("unexpected %v %v", err, len(d.got))
	}
	if _, _, err := dec.Decode(nil, nil); err != ErrObjectTooLarge || !bytes.Equal(d.got, frames[1]) {
		t.Fatalf("unexpected %v %v", err, len(d.got))
	}
	if _, _, err := dec.Decode(nil, nil); err != nil || !bytes.Equal(d.got, frames[3]) {
		t.Fatalf("unexpected %v %v", err, len(d.got))
	}
	if _, _, err := dec.Decode(nil, nil); err != io.EOF {
		t.Fatalf("unexpected %v %v", err, len(d.got))
	}
}
Esempio n. 2
0
// NewFrameWriter implements stream framing for this serializer
func (lengthDelimitedFramer) NewFrameWriter(w io.Writer) io.Writer {
	return framer.NewLengthDelimitedFrameWriter(w)
}
Esempio n. 3
0
// NewFrameWriter implements stream framing for this serializer
func (s *RawSerializer) NewFrameWriter(w io.Writer) io.Writer {
	return framer.NewLengthDelimitedFrameWriter(w)
}