func (asm *WriterAssembly) Write(messages []*Message) {
	writer := asm.getWriter()
	if writer == nil {
		logrus.Warning("No writer assigned to writer assembly")
		asm.Flush(messages)
		return  
	}
	contentLen := 0
	for _, msg := range messages {
		if contentLen+len(msg.GetPayload()) > len(asm.buffer) {
			asm.buffer = append(asm.buffer[:contentLen], msg.GetPayload()...)
		} else {
			copy(asm.buffer[contentLen:], msg.GetPayload())
		}
		contentLen += len(msg.GetPayload())
	}
	if _, err := writer.Write(asm.buffer[:contentLen]); err != nil {
		if asm.handleError != nil {
			if !asm.handleError(err) {
				asm.Flush(messages)
			}
		} else {
			logrus.Error("Stream write error:", err)
		}
		return  
	}
	if asm.validate != nil && !asm.validate() {
		asm.Flush(messages)
	}
}
Write is an AssemblyFunc compatible implementation to pass all messages from
a MessageBatch to an io.Writer.
Messages are formatted using a given formatter. If the io.Writer fails to
write the assembled buffer all messages are passed to the FLush() method.
package core
import (
	"github.com/sirupsen/logrus"
	"io"
	"sync"
)
type WriterAssembly struct {
	writer      io.Writer
	flush       func(*Message)
	modulator   Modulator
	buffer      []byte
	validate    func() bool
	handleError func(error) bool
	writerGuard *sync.Mutex
}
func NewWriterAssembly(writer io.Writer, flush func(*Message), modulator Modulator) WriterAssembly {
	return WriterAssembly{
		writer:      writer,
		modulator:   modulator,
		flush:       flush,
		writerGuard: new(sync.Mutex),
	}
}
func (asm *WriterAssembly) SetValidator(validate func() bool) {
	asm.validate = validate
}
func (asm *WriterAssembly) SetErrorHandler(handleError func(error) bool) {
	asm.handleError = handleError
}
func (asm *WriterAssembly) SetWriter(writer io.Writer) {
	asm.writerGuard.Lock()
	defer asm.writerGuard.Unlock()
	asm.writer = writer
}
func (asm *WriterAssembly) SetFlush(flush func(*Message)) {
	asm.flush = flush
}
func (asm *WriterAssembly) getWriter() io.Writer {
	asm.writerGuard.Lock()
	defer asm.writerGuard.Unlock()
	return asm.writer
}