func (e *Encoder) EncodeString(payloads ...string) error {
	for _, p := range payloads {
		if err := e.Encode([]byte(p)); err != nil {
			return err
		}
	}
	return nil
}
EncodeString works similarly as Encode but payloads are specified as strings.
package pktline
import (
	"bytes"
	"errors"
	"fmt"
	"io"
)
type Encoder struct {
	w io.Writer
}
const (
	MaxPayloadSize = 65516
)
var (
	FlushPkt = []byte{'0', '0', '0', '0'}
	Flush = []byte{}
	FlushString = ""
	ErrPayloadTooLong = errors.New("payload is too long")
)
func NewEncoder(w io.Writer) *Encoder {
	return &Encoder{
		w: w,
	}
}
func (e *Encoder) Flush() error {
	_, err := e.w.Write(FlushPkt)
	return err
}
func (e *Encoder) Encode(payloads ...[]byte) error {
	for _, p := range payloads {
		if err := e.encodeLine(p); err != nil {
			return err
		}
	}
	return nil
}
func (e *Encoder) encodeLine(p []byte) error {
	if len(p) > MaxPayloadSize {
		return ErrPayloadTooLong
	}
	if bytes.Equal(p, Flush) {
		return e.Flush()
	}
	n := len(p) + 4
	if _, err := e.w.Write(asciiHex16(n)); err != nil {
		return err
	}
	_, err := e.w.Write(p)
	return err
}
func asciiHex16(n int) []byte {
	var ret [4]byte
	ret[0] = byteToASCIIHex(byte(n & 0xf000 >> 12))
	ret[1] = byteToASCIIHex(byte(n & 0x0f00 >> 8))
	ret[2] = byteToASCIIHex(byte(n & 0x00f0 >> 4))
	ret[3] = byteToASCIIHex(byte(n & 0x000f))
	return ret[:]
}
func byteToASCIIHex(n byte) byte {
	if n < 10 {
		return '0' + n
	}
	return 'a' - 10 + n
}