// WriteTo implements io.WriterTo interface. It serializes the version
// bitmap into the wire format.
322574
func (h *HelloElemVersionBitmap) WriteTo(w io.Writer) (int64, error) {
	// Calculate the padding used to align the list of bitmaps.
	maplen := len(h.Bitmaps) * 4
	padding := make([]byte, (helloElemLen+maplen)%8)

	// Total length of the element includes the length of the
	// optional header, length of the bitmaps and the padding
	// used to align the message to 64-bits border.
	totalLen := helloElemLen + maplen + len(padding)

	// Compose the header of the element and marshal it
	// altogether with a version bitmaps and required padding.
	header := helloElem{h.Type(), uint16(totalLen)}
	return encoding.WriteTo(w, header, h.Bitmaps, padding)
}
665616
func (row Row) WriteTo(writer io.Writer) (err error) {
	encoded, err := encodeRow(row)
	if err != nil {
		return fmt.Errorf("WriteTo encoding error: %v", err)
	}
	return WriteMessage(writer, encoded)
}
1093088
func (q *QueueStats) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, *q)
}
785910
func (m *Image) WriteTo(w io.Writer) (int64, error) {
	n, err := w.Write(m.encodedPNG())
	return int64(n), err
}
371054
func (m MeterBands) WriteTo(w io.Writer) (int64, error) {
	var n int64

	for _, meter := range m {
		nn, err := meter.WriteTo(w)
		n += nn

		if err != nil {
			return n, err
		}
	}

	return n, nil
}
1271831
func (c *Container) WriteTo(w io.Writer) (n int64, err error) {
	if c.isArray() {
		return c.arrayWriteTo(w)
	} else if c.isRun() {
		return c.runWriteTo(w)
	} else {
		return c.bitmapWriteTo(w)
	}
}
818115
func (e *Exportable) WriteTo(w io.Writer) (int64, error) {
	return e.buffer.WriteTo(w)
}
1358800
func (c Contents) WriteTo(w io.Writer) (n int64, err error) {
	for i := 0; i < len(c)-1; i++ {
		x, e := fmt.Fprintf(w, "%s%s", strings.Join(c[i], colDelimiter), rowDelimiter)
		if e != nil {
			return
		}
		n += int64(x)
	}
	if i := len(c) - 1; i > 0 {
		x, e := fmt.Fprintf(w, "%s", strings.Join(c[i], colDelimiter))
		if e != nil {
			return n, e
		}
		n += int64(x)
	}
	return
}
435102
func (s *String) WriteTo(w io.Writer) (n int64, err error) {
	// unsigned short, can't use Short
	var length = uint16(len(s.Value))
	err = binary.Write(w, binary.BigEndian, &length)
	if err != nil {
		return
	}

	// Then write string bytes
	_, err = w.Write([]byte(s.Value))
	if err != nil {
		return
	}
	n += int64(length)

	return
}
1098072
func (sf *scriptFlags) WriteTo(w io.Writer) (int64, error) {
	var b [8]byte
	if sf.hasScript {
		b[0] |= 1 << 1
	}
	if sf.change {
		b[0] |= 1 << 5
	}
	if sf.unsynced {
		b[0] |= 1 << 6
	}
	if sf.partialSync {
		b[0] |= 1 << 7
	}

	n, err := w.Write(b[:])
	return int64(n), err
}
1069431
func (not Not) WriteTo(w Writer) error {
	if _, err := fmt.Fprint(w, "NOT "); err != nil {
		return err
	}
	switch not[0].(type) {
	case condAnd, condOr:
		if _, err := fmt.Fprint(w, "("); err != nil {
			return err
		}
	}

	if err := not[0].WriteTo(w); err != nil {
		return err
	}

	switch not[0].(type) {
	case condAnd, condOr:
		if _, err := fmt.Fprint(w, ")"); err != nil {
			return err
		}
	}

	return nil
}
389794
func (b *ByteBuffer) WriteTo(w io.Writer) (int64, error) {
	n, err := w.Write(b.B)
	return int64(n), err
}
1072062
func (p POSTable) WriteTo(w io.Writer) (int64, error) {
	var b bytes.Buffer
	enc := gob.NewEncoder(&b)
	if err := enc.Encode(p.POSs); err != nil {
		return 0, err
	}
	if err := enc.Encode(p.NameList); err != nil {
		return 0, err
	}
	return b.WriteTo(w)
}
860555
func (i RawVInt) WriteTo(w Writer) error {
	var arr [8]byte
	n := 0
	for i != 0 {
		arr[n] = byte(i & 0xff)
		n++
		i >>= 8
	}
	_, err := w.Write(arr[:n])
	return errorsp.WithStacks(err)
}
502445
func (p *MemFSPath) WriteTo(out io.Writer) (int64, error) {
	if p.contents == nil {
		return 0, os.ErrNotExist
	}
	n, err := out.Write(p.contents)
	return int64(n), err
}
678153
func (ba RawByteSlice) WriteTo(w Writer) error {
	_, err := w.Write(ba)
	return errorsp.WithStacks(err)
}
1134628
func (b Blob) WriteTo(w io.Writer) (int64, error) {
	written, err := w.Write([]byte(b))
	return int64(written), err
}