mpub.go
func (c MPub) Write(w *bufio.Writer) (err error) {
	for _, s := range [...]string{
		"MPUB ",
		c.Topic,
		"\n",
	} {
		if _, err = w.WriteString(s); err != nil {
			err = errors.Wrap(err, "writing MPUB command")
			return
		}
	}

	var size uint32

	for _, m := range c.Messages {
		size += uint32(len(m))
	}

	if err = binary.Write(w, binary.BigEndian, size); err != nil {
		err = errors.Wrap(err, "writing MPUB body size")
		return
	}

	if err = binary.Write(w, binary.BigEndian, uint32(len(c.Messages))); err != nil {
		err = errors.Wrap(err, "writing MPUB message count")
		return
	}

	for _, m := range c.Messages {
		if err = binary.Write(w, binary.BigEndian, uint32(len(m))); err != nil {
			err = errors.Wrap(err, "writing MPUB message size")
			return
		}

		if _, err = w.Write(m); err != nil {
			err = errors.Wrap(err, "writing MPUB message data")
			return
		}
	}

	return
}
func (c MPub) Write(w *bufio.Writer) (err error) {
	for _, s := range [...]string{
		"MPUB ",
		c.Topic,
		"\n",
	} {
		if _, err = w.WriteString(s); err != nil {
			err = errors.Wrap(err, "writing MPUB command")
			return
		}
	}

	var size uint32

	for _, m := range c.Messages {
		size += uint32(len(m))
	}

	if err = binary.Write(w, binary.BigEndian, size); err != nil {
		err = errors.Wrap(err, "writing MPUB body size")
		return
	}

	if err = binary.Write(w, binary.BigEndian, uint32(len(c.Messages))); err != nil {
		err = errors.Wrap(err, "writing MPUB message count")
		return
	}

	for _, m := range c.Messages {
		if err = binary.Write(w, binary.BigEndian, uint32(len(m))); err != nil {
			err = errors.Wrap(err, "writing MPUB message size")
			return
		}

		if _, err = w.Write(m); err != nil {
			err = errors.Wrap(err, "writing MPUB message data")
			return
		}
	}

	return
}
// Write serializes the command to the given buffered output, satisfies the
// Command interface.