// WriteTo implements io.WriterTo interface. It serializes the role
// request into the wire format.
490863
func (rr *RoleRequest) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, rr.Role, pad4{}, rr.GenerationID)
}
1028213
func (a *ActionSetField) WriteTo(w io.Writer) (int64, error) {
	var buf bytes.Buffer

	_, err := a.Field.WriteTo(&buf)
	if err != nil {
		return 0, err
	}

	// Length is padded to 64 bits
	length := buf.Len() + 4

	if length%8 != 0 {
		_, err := buf.Write(make(pad, 8-length%8))
		if err != nil {
			return 0, err
		}
	}

	header := action{a.Type(), uint16(buf.Len() + 4)}
	return encoding.WriteTo(w, header, buf.Bytes())
}
1106630
func (s String) WriteTo(w Writer) error {
	return ByteSlice(s).WriteTo(w)
}
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,
	)
}
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
}
783158
func (dec *declaration) WriteTo(w io.Writer) (int64, error) {
	return dec.writeTo(w, nil)
}
100147
func (q *QueuePropMinRate) WriteTo(w io.Writer) (int64, error) {
	header := queueProp{q.Type(), queuePropLen}
	return encoding.WriteTo(w, header, pad4{}, q.Rate, pad6{})
}
433791
func (i *InstructionWriteActions) WriteTo(w io.Writer) (int64, error) {
	return writeInstructionActions(w, i.Type(), i.Actions)
}
1200349
func (a *ActionOutput) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, action{a.Type(), 16}, *a, pad6{})
}
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
}
463840
func (s String) WriteTo(w io.Writer) (int64, error) {
	written, err := fmt.Fprintf(w, "%s", s)
	return int64(written), err
}
1093088
func (q *QueueStats) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, *q)
}
1121858
func (m *MultipartReply) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, *m, pad4{})
}
1172198
func (sel *selector) WriteTo(w io.Writer) (int64, error) {
	return sel.writeTo(w, nil)
}
413197
func (s RawString) WriteTo(w Writer) error {
	return RawByteSlice(s).WriteTo(w)
}
23832
func (model *Model) WriteTo(w io.Writer) (int64, error) {
	model.RLock()
	defer model.RUnlock()
	b, err := json.Marshal(model)
	if err != nil {
		return 0, err
	}
	n, err := w.Write(b)
	if err != nil {
		return int64(n), err
	}
	return int64(n), nil
}
1281027
func (c Config) WriteTo(w io.Writer) (int64, error) {
	data, err := json.Marshal(c)
	if err != nil {
		return int64(len(data)), err
	}
	return io.Copy(w, bytes.NewReader(data))
}