func NewEncoderDecoder(rw io.ReadWriter) *EncoderDecoder {
	return &EncoderDecoder{*NewEncoder(rw), *NewDecoder(rw)}
}
NewEncoderDecoder constructs pkt-line encoder/decoder.
package pktline
import (
	"bytes"
	"errors"
	"fmt"
	"io"
	"strconv"
)
var (
	ErrShortRead   = errors.New("input is too short")
	ErrInputExcess = errors.New("input is too long")
	ErrTooLong     = errors.New("too long payload")
	ErrInvalidLen  = errors.New("invalid length")
)
const (
	headLen = 4
	maxLen  = 65524  
)
type Decoder struct {
	r io.Reader
}
func NewDecoder(r io.Reader) *Decoder {
	return &Decoder{r: r}
}
func (d *Decoder) Decode(payload *[]byte) error {
	head := make([]byte, headLen)
	_, err := io.ReadFull(d.r, head)
	if err == io.ErrUnexpectedEOF {
		return ErrShortRead
	}
	if err != nil {
		return err
	}
	lineLen, err := strconv.ParseInt(string(head), 16, 16)
	if err != nil {
		return err
	}
	if lineLen == 0 {  
		*payload = nil
		return nil
	}
	if lineLen < headLen {
		return ErrInvalidLen
	}
	*payload = make([]byte, lineLen-headLen)
	if lineLen == headLen {  
		return nil
	}
	_, err = io.ReadFull(d.r, *payload)
	if err == io.ErrUnexpectedEOF {
		return ErrShortRead
	}
	if err != nil {
		return err
	}
	return nil
}
func Decode(line []byte) (payload []byte, err error) {
	buffer := bytes.NewBuffer(line)
	decoder := NewDecoder(buffer)
	err = decoder.Decode(&payload)
	if err != nil {
		return
	}
	if buffer.Len() != 0 {
		err = ErrInputExcess
		return
	}
	return
}
func (d *Decoder) DecodeUntilFlush(lines *[][]byte) (err error) {
	*lines = make([][]byte, 0)
	for {
		var l []byte
		err = d.Decode(&l)
		if err != nil {
			return
		}
		if l == nil {  
			return
		}
		*lines = append(*lines, l)
	}
}
type Encoder struct {
	w io.Writer
}
func NewEncoder(w io.Writer) *Encoder {
	return &Encoder{w: w}
}
func (e *Encoder) Encode(payload []byte) error {
	line, err := Encode(payload)
	if err != nil {
		return err
	}
	_, err = e.w.Write(line)
	if err != nil {
		return err
	}
	return nil
}
func Encode(payload []byte) ([]byte, error) {
	if payload == nil {
		return []byte("0000"), nil
	}
	if len(payload)+headLen > maxLen {
		return nil, ErrTooLong
	}
	head := []byte(fmt.Sprintf("%04x", len(payload)+headLen))
	return append(head, payload...), nil
}
type EncoderDecoder struct {
	Encoder
	Decoder
}