Пример #1
0
// Decoder creates a new styxproto.Decoder that traces messages
// received on r.
func Decoder(r io.Reader, fn Func) *styxproto.Decoder {
	rd, wr := io.Pipe()
	decoderInput := styxproto.NewDecoderSize(r, 8*kilobyte)
	decoderTrace := styxproto.NewDecoderSize(rd, 8*kilobyte)
	go func() {
		for decoderInput.Next() {
			fn(decoderInput.Msg())
			styxproto.Write(wr, decoderInput.Msg())
		}
		wr.Close()
	}()
	return decoderTrace
}
Пример #2
0
// Encoder creates a new styxproto.Encoder that traces messages
// before writing them to w.
func Encoder(w io.Writer, fn Func) *styxproto.Encoder {
	rd, wr := io.Pipe()
	encoder := styxproto.NewEncoder(wr)
	decoder := styxproto.NewDecoderSize(rd, 8*kilobyte)
	go func() {
		for decoder.Next() {
			fn(decoder.Msg())
			styxproto.Write(w, decoder.Msg())
		}
	}()
	return encoder
}