func (e Encoder) WriteFrame(f *Frame) (int, error) {
	var err error
	var n, nn int
	if err = e.bufW.WriteByte(flagSym); err != nil {
		return 0, err
	}
	n++
	if f.HasAddressCtrlPrefix {
		if nn, err = writeEscapedData(addressCtrlSeq, e.bufW); err != nil {
			return n + nn, err
		}
		n += nn
	}
	if nn, err = writeEscapedData(f.Payload, e.bufW); err != nil {
		return n + nn, err
	}
	n += nn
	if nn, err = writeEscapedData(f.FCS, e.bufW); err != nil {
		return n + nn, err
	}
	n += nn
	if err = e.bufW.WriteByte(flagSym); err != nil {
		return n + 1, err
	}
	n++
	if err = e.bufW.Flush(); err != nil {
		return n, err
	}
	return n, nil
}
WriteFrame writes the frame f on the output stream, encoding it's content.
package hdlc
import (
	"bufio"
	"encoding/binary"
	"io"
	"github.com/sigurn/crc16"
)
type Encoder struct {
	w    io.Writer
	bufW *bufio.Writer
}
func NewEncoder(w io.Writer) *Encoder {
	return &Encoder{
		w:    w,
		bufW: bufio.NewWriter(w),
	}
}