func (e Encoder) flush() error {
	length := e.buf.Len()
	if length > 0 {
		if err := binary.Write(e.w, binary.BigEndian, uint16(length)); err != nil {
			return errors.Wrap(err, "An error occured writing length bytes during flush")
		}
		if _, err := e.buf.WriteTo(e.w); err != nil {
			return errors.Wrap(err, "An error occured writing message bytes during flush")
		}
	}
	_, err := e.w.Write(EndMessage)
	if err != nil {
		return errors.Wrap(err, "An error occurred ending encoding message")
	}
	e.buf.Reset()
	return nil
}
flush finishes the encoding stream by flushing it to the writer
package encoding
import (
	"encoding/binary"
	"io"
	"math"
	"reflect"
	"bytes"
	"github.com/johnnadratowski/golang-neo4j-bolt-driver/errors"
	"github.com/johnnadratowski/golang-neo4j-bolt-driver/structures"
)
const (
	NilMarker = 0xC0
	TrueMarker = 0xC3
	FalseMarker = 0xC2
	Int8Marker = 0xC8
	Int16Marker = 0xC9
	Int32Marker = 0xCA
	Int64Marker = 0xCB
	FloatMarker = 0xC1
	TinyStringMarker = 0x80
	String8Marker = 0xD0
	String16Marker = 0xD1
	String32Marker = 0xD2
	TinySliceMarker = 0x90
	Slice8Marker = 0xD4
	Slice16Marker = 0xD5
	Slice32Marker = 0xD6
	TinyMapMarker = 0xA0
	Map8Marker = 0xD8
	Map16Marker = 0xD9
	Map32Marker = 0xDA
	TinyStructMarker = 0xB0
	Struct8Marker = 0xDC
	Struct16Marker = 0xDD
)
var (
	EndMessage = []byte{byte(0x00), byte(0x00)}
)
type Encoder struct {
	w         io.Writer
	buf       *bytes.Buffer
	chunkSize uint16
}
func NewEncoder(w io.Writer, chunkSize uint16) Encoder {
	return Encoder{
		w:         w,
		buf:       &bytes.Buffer{},
		chunkSize: chunkSize,
	}
}
func Marshal(v interface{}) ([]byte, error) {
	x := &bytes.Buffer{}
	err := NewEncoder(x, math.MaxUint16).Encode(v)
	return x.Bytes(), err
}
func (e Encoder) Write(p []byte) (n int, err error) {
	n, err = e.buf.Write(p)
	if err != nil {
		err = errors.Wrap(err, "An error occurred writing to encoder temp buffer")
		return n, err
	}
	length := e.buf.Len()
	for length >= int(e.chunkSize) {
		if err := binary.Write(e.w, binary.BigEndian, e.chunkSize); err != nil {
			return 0, errors.Wrap(err, "An error occured writing chunksize")
		}
		numWritten, err := e.w.Write(e.buf.Next(int(e.chunkSize)))
		if err != nil {
			err = errors.Wrap(err, "An error occured writing a chunk")
		}
		return numWritten, err
	}
	return n, nil
}