// WriteTo writes the generated bytes to the given writer.
// When the builder is not closed, an error is returned.
194661
func (b *Builder) WriteTo(w io.Writer) (int64, error) {
	if !b.IsClosed() {
		return 0, WithStack(BuilderNotClosedError)
	}
	if n, err := w.Write(b.buf); err != nil {
		return 0, WithStack(err)
	} else {
		return int64(n), nil
	}
}
1172198
func (sel *selector) WriteTo(w io.Writer) (int64, error) {
	return sel.writeTo(w, nil)
}
894889
func (d *Description) WriteTo(w io.Writer) (int64, error) {
	mfr := d.copyTo(d.Manufacturer, descLen)
	hw := d.copyTo(d.Hardware, descLen)
	sw := d.copyTo(d.Software, descLen)
	sn := d.copyTo(d.SerialNum, serialNumLen)
	dp := d.copyTo(d.Datapath, descLen)

	return encoding.WriteTo(w, mfr, hw, sw, sn, dp)
}
651938
func (f *fragment) WriteTo(w io.Writer) (n int64, err error) {
	// Force cache flush.
	if err := f.FlushCache(); err != nil {
		return 0, errors.Wrap(err, "flushing cache")
	}

	// Write out data and cache to a tar archive.
	tw := tar.NewWriter(w)
	if err := f.writeStorageToArchive(tw); err != nil {
		return 0, fmt.Errorf("write storage: %s", err)
	}
	if err := f.writeCacheToArchive(tw); err != nil {
		return 0, fmt.Errorf("write cache: %s", err)
	}
	return 0, nil
}
988670
func (a *Actions) WriteTo(w io.Writer) (int64, error) {
	buf, err := a.bytes()
	if err != nil {
		return int64(len(buf)), err
	}

	return encoding.WriteTo(w, buf)
}
107340
func (a *ActionGroup) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, action{a.Type(), actionLen}, a.Group)
}
860708
func (b Bool) WriteTo(w io.Writer) (int64, error) {
	written, err := fmt.Fprintf(w, "%t", b)
	return int64(written), err
}
500299
func (m Message) WriteTo(w io.Writer) (int64, error) {
	b, err := m.MarshalBinary()
	if err != nil {
		return 0, err
	}
	n, err := fmt.Fprintf(w, "%d %s", len(b), b)
	return int64(n), err
}
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
}
581282
func (v *variable) WriteTo(w io.Writer) (int64, error) {
	n, err := w.Write([]byte(v.value))

	return int64(n), err
}
75773
func (e *Error) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, e.Type, e.Code, e.Data)
}
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)
}
1097085
func (f File) WriteTo(w io.Writer) (int64, error) {
	n, err := w.Write(f.data)
	if err == nil {
		if n != len(f.data) {
			// this shouldn't happen
			//
			//    Write must return a non-nil error if it returns n < len(p)
			//
			// but check just in case
			return int64(n), io.ErrShortWrite
		}
	}
	return int64(n), err
}
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)
}
282152
func (b *Bar) WriteTo(w io.Writer) (int64, error) {
	s := fmt.Sprintf("\r   %s ", b.String())
	_, err := io.WriteString(w, s)
	return int64(len(s)), err
}
1043924
func (ba ByteSlice) WriteTo(w Writer) error {
	if err := VInt(len(ba)).WriteTo(w); err != nil {
		return errorsp.WithStacks(err)
	}
	_, err := w.Write(ba)
	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)
}