// WriteTo writes a response writer (temp: status code, headers and body) to another response writer.
486356
func (w *responseWriter) WriteTo(to ResponseWriter) {
	// set the status code, failure status code are first class
	if w.statusCode >= 400 {
		to.WriteHeader(w.statusCode)
	}

	// append the headers
	if w.Header() != nil {
		for k, values := range w.Header() {
			for _, v := range values {
				if to.Header().Get(v) == "" {
					to.Header().Add(k, v)
				}
			}
		}

	}
	// the body is not copied, this writer doesn't support recording
}
598207
func (q *QueueGetConfigRequest) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, q.Port, pad4{})
}
953128
func (msg Message) WriteTo(w io.Writer) (int64, error) {
	var bytesWritten int

	nw, err := fmt.Fprintf(w, "%s%s", msg.Address, msg.Typetags())
	if err != nil {
		return 0, err
	}
	bytesWritten += nw

	for _, a := range msg.Arguments {
		nw, err := a.WriteTo(w)
		if err != nil {
			return 0, err
		}
		bytesWritten += int(nw)
	}

	return int64(bytesWritten), nil
}
81525
func (q *QueueStatsRequest) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, q.Port, q.Queue)
}
350792
func (s Slice) WriteTo(w io.Writer) (n int64, err error) {
	nWrite, err := w.Write(s)
	return int64(nWrite), err
}
413197
func (s RawString) WriteTo(w Writer) error {
	return RawByteSlice(s).WriteTo(w)
}
1172198
func (sel *selector) WriteTo(w io.Writer) (int64, error) {
	return sel.writeTo(w, nil)
}
149550
func (c *Conn) WriteTo(b []byte, addr net.Addr) (int, error) {
	return c.p.WriteTo(b, addr)
}
44778
func (f *FlowRemoved) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, f.Cookie, f.Priority, f.Reason,
		f.Table, f.DurationSec, f.DurationNSec, f.IdleTimeout,
		f.HardTimeout, f.PacketCount, f.ByteCount, &f.Match,
	)
}
1356526
func (i Int32) WriteTo(w Writer) error {
	arr := [4]byte{byte(i), byte(i >> 8), byte(i >> 16), byte(i >> 24)}
	_, err := w.Write(arr[:])
	return errorsp.WithStacks(err)
}
860708
func (b Bool) WriteTo(w io.Writer) (int64, error) {
	written, err := fmt.Fprintf(w, "%t", b)
	return int64(written), err
}
995273
func (r Record) WriteTo(w io.Writer) (int64, error) {
	n, err := fmt.Fprintf(w, "%s\t%s\n", r.IP, r.Hosts)
	return int64(n), err
}
125271
func (m *Message) WriteTo(w io.Writer) (int64, error) {

	total, err := m.Header.WriteTo(w)
	if err != nil {
		return total, err
	}

	mediaType, mediaTypeParams, err := m.Header.ContentType()
	if err != nil && err != ErrHeadersMissingField {
		return total, err
	}
	hasParts := strings.HasPrefix(mediaType, "multipart")
	hasSubMessage := strings.HasPrefix(mediaType, "message")

	if !hasParts && !hasSubMessage {
		return m.writeBody(w, total)
	}

	written, err := io.WriteString(w, "\r\n")
	total += int64(written)
	if err != nil {
		return total, err
	}

	if hasSubMessage {
		written2, err := m.SubMessage.WriteTo(w)
		return total + written2, err

	}
	// hasParts
	return m.writeParts(w, mediaTypeParams["boundary"], total)
}
1264599
func (t Time) WriteTo(w Writer) error {
	bytes, err := time.Time(t).MarshalBinary()
	if err != nil {
		return errorsp.WithStacks(err)
	}
	return errorsp.WithStacks(ByteSlice(bytes).WriteTo(w))
}
877622
func (f *FlowStats) WriteTo(w io.Writer) (int64, error) {
	var buf bytes.Buffer

	_, err := encoding.WriteTo(&buf, f.Table, pad1{}, f.DurationSec,
		f.DurationNSec, f.Priority, f.IdleTimeout, f.HardTimeout,
		f.Flags, pad4{}, f.Cookie, f.PacketCount, f.ByteCount,
		&f.Match, &f.Instructions,
	)

	if err != nil {
		return 0, err
	}

	return encoding.WriteTo(w, uint16(buf.Len()+2), buf.Bytes())
}
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)
}
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
}