// WriteTo implements net.PacketConn.WriteTo.
161668
func (c *PacketConn) WriteTo(b []byte, addr net.Addr) (int, error) {
	deadline := c.writeCancel()

	// Check if deadline has already expired.
	select {
	case <-deadline:
		return 0, c.newRemoteOpError("write", addr, &timeoutError{})
	default:
	}

	// If we're being called by Write, there is no addr
	wopts := tcpip.WriteOptions{}
	if addr != nil {
		ua := addr.(*net.UDPAddr)
		wopts.To = &tcpip.FullAddress{Addr: tcpip.Address(ua.IP), Port: uint16(ua.Port)}
	}

	v := buffer.NewView(len(b))
	copy(v, b)

	n, resCh, err := c.ep.Write(tcpip.SlicePayload(v), wopts)
	if resCh != nil {
		select {
		case <-deadline:
			return int(n), c.newRemoteOpError("write", addr, &timeoutError{})
		case <-resCh:
		}

		n, _, err = c.ep.Write(tcpip.SlicePayload(v), wopts)
	}

	if err == tcpip.ErrWouldBlock {
		// Create wait queue entry that notifies a channel.
		waitEntry, notifyCh := waiter.NewChannelEntry(nil)
		c.wq.EventRegister(&waitEntry, waiter.EventOut)
		defer c.wq.EventUnregister(&waitEntry)
		for {
			select {
			case <-deadline:
				return int(n), c.newRemoteOpError("write", addr, &timeoutError{})
			case <-notifyCh:
			}

			n, _, err = c.ep.Write(tcpip.SlicePayload(v), wopts)
			if err != tcpip.ErrWouldBlock {
				break
			}
		}
	}

	if err == nil {
		return int(n), nil
	}

	return int(n), c.newRemoteOpError("write", addr, errors.New(err.String()))
}
1158459
func (b *ByteBuffer) WriteTo(w io.Writer) (int64, error) {
	b.Lock()
	defer b.Unlock()
	return b.b.WriteTo(w)
}
598207
func (q *QueueGetConfigRequest) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, q.Port, pad4{})
}
860708
func (b Bool) WriteTo(w io.Writer) (int64, error) {
	written, err := fmt.Fprintf(w, "%t", b)
	return int64(written), err
}
1144240
func (p *PortMod) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, p.PortNo, pad4{}, p.HWAddr, pad2{},
		p.Config, p.Mask, p.Advertise, pad4{},
	)
}
765087
func (s *Chan) WriteTo(w io.Writer) {
	// new buffer per message
	// if bottleneck, cycle around a set of buffers
	mw := NewWriter(w)

	// single writer, no need for Mutex
	mw.(*writer).lock = new(nullLocker)
Loop:
	for {
		select {
		case <-s.CloseChan:
			break Loop // told we're done

		case msg, ok := <-s.MsgChan:
			if !ok { // chan closed
				break Loop
			}

			if err := mw.WriteMsg(msg); err != nil {
				if err != io.EOF {
					// unexpected error. tell the client.
					s.ErrChan <- err
				}

				break Loop
			}
		}
	}

	// signal we're done
	s.CloseChan <- true
}
1315432
func (p *Port) WriteTo(w io.Writer) (int64, error) {
	name := make([]byte, portNameLen)
	copy(name, []byte(p.Name))

	return encoding.WriteTo(w, p.PortNo, pad4{}, p.HWAddr, pad2{},
		name, p.Config, p.State, p.Curr, p.Advertised, p.Supported,
		p.Peer, p.CurrSpeed, p.MaxSpeed,
	)
}
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
}
95075
func (q *PacketQueue) WriteTo(w io.Writer) (int64, error) {
	var buf bytes.Buffer
	_, err := q.Properties.WriteTo(&buf)
	if err != nil {
		return 0, err
	}

	return encoding.WriteTo(w, q.Queue, q.Port,
		uint16(buf.Len()+packetQueueLen), pad6{}, buf.Bytes())
}
1321291
func (i *InstructionGotoTable) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, instruction{i.Type(), 8}, i.Table, pad3{})
}
996693
func (c *Component) writeTo(b *strings.Builder) {
	b.WriteByte('/')
	b.WriteString(c.protocol.Name)
	value := c.Value()
	if len(value) == 0 {
		return
	}
	if !(c.protocol.Path && value[0] == '/') {
		b.WriteByte('/')
	}
	b.WriteString(value)
}
886110
func (rb *ResponseBuffer) WriteTo(w http.ResponseWriter) error {
	for k, v := range rb.header {
		w.Header()[k] = v
	}
	if rb.buf.Len() > 0 {
		w.Header().Set("Content-Length", strconv.Itoa(rb.buf.Len()))
	}
	if rb.status != 0 {
		w.WriteHeader(rb.status)
	}
	if rb.buf.Len() > 0 {
		if _, err := w.Write(rb.buf.Bytes()); err != nil {
			return err
		}
	}
	return nil
}
1298789
func (p *PortStats) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, p.PortNo, pad4{}, p.RxPackets,
		p.TxPackets, p.RxBytes, p.TxBytes, p.RxDropped, p.TxDropped,
		p.RxErrors, p.TxErrors, p.RxFrameErr, p.RxOverErr, p.RxCrcErr,
		p.Collisions, p.DurationSec, p.DurationNSec,
	)
}
1104483
func (p *packetConn) WriteTo(b []byte, addr net.Addr) (int, error) {
	// Ensure correct Addr type.
	a, ok := addr.(*Addr)
	if !ok || a.HardwareAddr == nil || len(a.HardwareAddr) < 6 {
		return 0, unix.EINVAL
	}

	// Convert hardware address back to byte array form.
	var baddr [8]byte
	copy(baddr[:], a.HardwareAddr)

	// Send message on socket to the specified hardware address from addr
	// packet(7):
	//   When you send packets it is enough to specify sll_family, sll_addr,
	//   sll_halen, sll_ifindex, and sll_protocol. The other fields should
	//   be 0.
	// In this case, sll_family is taken care of automatically by unix.
	err := p.s.Sendto(b, 0, &unix.SockaddrLinklayer{
		Ifindex:  p.ifi.Index,
		Halen:    uint8(len(a.HardwareAddr)),
		Addr:     baddr,
		Protocol: p.pbe,
	})
	return len(b), err
}
674039
func (m *MeterConfigRequest) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, m.Meter, pad4{})
}
818115
func (e *Exportable) WriteTo(w io.Writer) (int64, error) {
	return e.buffer.WriteTo(w)
}
487565
func (p *KubernetesPath) WriteTo(out io.Writer) (int64, error) {
	return 0, fmt.Errorf("KubernetesPath::WriteTo not supported")
}