// WriteTo writes data to w until there's no more data to write or when an error occurs.
// The return value n is the number of bytes written.
// Any error encountered during the write is also returned.
486587
func (d *Decoder) WriteTo(w io.Writer) (int64, error) {
	if d.stream == nil {
		return 0, errors.New("no input has been initialized")
	}
	var n int64
	for d.current.err == nil {
		if len(d.current.b) > 0 {
			n2, err2 := w.Write(d.current.b)
			n += int64(n2)
			if err2 != nil && d.current.err == nil {
				d.current.err = err2
				break
			}
		}
		d.nextBlock()
	}
	err := d.current.err
	if err != nil {
		d.drainOutput()
	}
	if err == io.EOF {
		err = nil
	}
	return n, err
}
32201
func (b *base) WriteTo(w io.Writer) (int64, error) {
	// Create a byte buffer.
	var bf bytes.Buffer

	// Write the Packet data to the buffer.
	bf.Write(b.fixedHeader)
	bf.Write(b.variableHeader)
	bf.Write(b.payload)

	// Write the buffered data to the writer.
	n, err := w.Write(bf.Bytes())

	// Return the result.
	return int64(n), err
}
413197
func (s RawString) WriteTo(w Writer) error {
	return RawByteSlice(s).WriteTo(w)
}
1208646
func (f *File) WriteTo(w io.Writer) (int64, error) {
	return f.WriteToIndent(w, "")
}
141168
func (r Rope) WriteTo(w io.Writer) (n int64, err error) {
	if r.node == nil {
		return 0, nil // Nothing to do
	}
	return r.node.WriteTo(w)
}
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)
	}
}
389794
func (b *ByteBuffer) WriteTo(w io.Writer) (int64, error) {
	n, err := w.Write(b.B)
	return int64(n), err
}
728914
func (ini *INI) WriteTo(w io.Writer) (int64, error) {
	var written int64

	// Global section.
	m, err := ini.printSection(w, &ini.global)
	written += int64(m)
	if err != nil {
		return written, err
	}
	first := len(ini.global.Data) > 0

	for i, section := range ini.sections {
		if i > 0 || first {
			m, err := fmt.Fprintf(w, "\n")
			written += int64(m)
			if err != nil {
				return written, err
			}
		}
		m, err := ini.printSection(w, section)
		written += int64(m)
		if err != nil {
			return written, err
		}
	}

	return written, nil
}
81736
func (r *reader) WriteTo(w io.Writer) (int64, error) {
	if r.err != nil {
		return 0, r.err
	}

	n, err := r.buf.WriteTo(w)
	if err != nil {
		// r.err doesn't need to be set because a write error occurred and the
		// stream hasn't been corrupted.
		return n, err
	}

	// pass a bufferFallbackWriter to nextFrame so that write errors may be
	// recovered from, allowing the unwritten stream to be read successfully.
	wfallback := &bufferFallbackWriter{
		w:   w,
		buf: &r.buf,
	}
	for {
		var m int
		m, err = r.nextFrame(wfallback)
		if wfallback.writerErr != nil && err == nil {
			// a partial write was made before an error occurred and not all m
			// bytes were writen to w.  but decoded bytes were successfully
			// buffered and reading can resume later.
			n += wfallback.n
			return n, wfallback.writerErr
		}
		n += int64(m)
		if err == io.EOF {
			return n, nil
		}
		if err != nil {
			r.err = err
			return n, err
		}
	}
	panic("unreachable")
}
831337
func (r *Reader) WriteTo(w io.Writer) (int64, error) {
	var (
		i   int64
		ii  int
		err error
	)
	// first, clear buffer
	if r.buffered() > 0 {
		ii, err = w.Write(r.data[r.n:])
		i += int64(ii)
		if err != nil {
			return i, err
		}
		r.data = r.data[0:0]
		r.n = 0
	}
	for r.state == nil {
		// here we just do
		// 1:1 reads and writes
		r.more()
		if r.buffered() > 0 {
			ii, err = w.Write(r.data)
			i += int64(ii)
			if err != nil {
				return i, err
			}
			r.data = r.data[0:0]
			r.n = 0
		}
	}
	if r.state != io.EOF {
		return i, r.err()
	}
	return i, nil
}
1336300
func (f Float) WriteTo(w io.Writer) (int64, error) {
	written, err := fmt.Fprintf(w, "%f", f)
	return int64(written), err
}
933461
func (isNull IsNull) WriteTo(w Writer) error {
	_, err := fmt.Fprintf(w, "%s IS NULL", w.Key(isNull[0]))
	return err
}
1158459
func (b *ByteBuffer) WriteTo(w io.Writer) (int64, error) {
	b.Lock()
	defer b.Unlock()
	return b.b.WriteTo(w)
}
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)
}
70048
func (i *InstructionWriteMetadata) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, instruction{i.Type(), 24},
		pad4{}, i.Metadata, i.MetadataMask)
}
1015385
func (s *DatagramSession) WriteTo(b []byte, addr net.Addr) (n int, err error) {
	header := []byte("3.0 " + s.id + " " + addr.String() + "\n")
	msg := append(header, b...)
	n, err = s.udpconn.WriteToUDP(msg, s.rUDPAddr)
	return n, err
}
1148670
func (c *Command) WriteTo(w io.Writer) (int64, error) {
	var total int64
	var buf [4]byte

	n, err := w.Write(c.Name)
	total += int64(n)
	if err != nil {
		return total, err
	}

	for _, param := range c.Params {
		n, err := w.Write(byteSpace)
		total += int64(n)
		if err != nil {
			return total, err
		}
		n, err = w.Write(param)
		total += int64(n)
		if err != nil {
			return total, err
		}
	}

	n, err = w.Write(byteNewLine)
	total += int64(n)
	if err != nil {
		return total, err
	}

	if c.Body != nil {
		bufs := buf[:]
		binary.BigEndian.PutUint32(bufs, uint32(len(c.Body)))
		n, err := w.Write(bufs)
		total += int64(n)
		if err != nil {
			return total, err
		}
		n, err = w.Write(c.Body)
		total += int64(n)
		if err != nil {
			return total, err
		}
	}

	return total, nil
}