// WriteTo writes the header to w.
504758
func (hdr *SeriesIndexHeader) WriteTo(w io.Writer) (n int64, err error) {
	var buf bytes.Buffer
	buf.WriteString(SeriesIndexMagic)
	binary.Write(&buf, binary.BigEndian, hdr.Version)
	binary.Write(&buf, binary.BigEndian, hdr.MaxSeriesID)
	binary.Write(&buf, binary.BigEndian, hdr.MaxOffset)
	binary.Write(&buf, binary.BigEndian, hdr.Count)
	binary.Write(&buf, binary.BigEndian, hdr.Capacity)
	binary.Write(&buf, binary.BigEndian, hdr.KeyIDMap.Offset)
	binary.Write(&buf, binary.BigEndian, hdr.KeyIDMap.Size)
	binary.Write(&buf, binary.BigEndian, hdr.IDOffsetMap.Offset)
	binary.Write(&buf, binary.BigEndian, hdr.IDOffsetMap.Size)
	return buf.WriteTo(w)
}
61206
func (m *MeterBandDrop) WriteTo(w io.Writer) (int64, error) {
	header := meterBand{m.Type(), meterBandLen}
	return encoding.WriteTo(w, header, m.Rate, m.BurstSize, pad4{})
}
1108482
func (out *RAMOutputStream) WriteTo(output util.DataOutput) error {
	err := out.Flush()
	if err != nil {
		return err
	}
	end := out.file.length
	pos := int64(0)
	buffer := 0
	for pos < end {
		length := BUFFER_SIZE
		nextPos := pos + int64(length)
		if nextPos > end { // at the last buffer
			length = int(end - pos)
		}
		err = output.WriteBytes(out.file.Buffer(buffer)[:length])
		if err != nil {
			return err
		}
		buffer++
		pos = nextPos
	}
	return nil
}
75773
func (e *Error) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, e.Type, e.Code, e.Data)
}
592205
func (e *ErrorExperimenter) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, ErrTypeExperimenter, e.ExpType,
		e.Experimenter, e.Data)
}
435060
func (between Between) WriteTo(w Writer) error {
	if _, err := fmt.Fprintf(w, "%s BETWEEN ? AND ?", w.Key(between.Col)); err != nil {
		return err
	}
	w.Append(between.LessVal, between.MoreVal)
	return nil
}
933461
func (isNull IsNull) WriteTo(w Writer) error {
	_, err := fmt.Fprintf(w, "%s IS NULL", w.Key(isNull[0]))
	return err
}
1050882
func (m *MultipartRequest) WriteTo(w io.Writer) (int64, error) {
	// By default, body will be embedded into the reader type.
	return encoding.WriteTo(w, m.Type, m.Flags, pad4{}, m.Body)
}
339806
func (b *Buffer) WriteTo(w io.Writer) (int64, error) {
	version := b.preOp()
	n, err := b.buf.WriteTo(w)
	b.postOp(version)
	return n, err
}
1151811
func (a *p2SHScript) WriteTo(w io.Writer) (n int64, err error) {
	// Prepare and write 32-bit little-endian length header
	var lenBytes [4]byte
	binary.LittleEndian.PutUint32(lenBytes[:], uint32(len(*a)))

	written, err := w.Write(lenBytes[:])
	n += int64(written)
	if err != nil {
		return n, err
	}

	// Now write the bytes themselves.
	written, err = w.Write(*a)

	return n + int64(written), err
}
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)
}
643479
func (h *authHeaderWriterTo) WriteTo(w io.Writer) (n int64, err error) {

	var (
		signedContent bytes.Buffer
		bytesWritten  int64
	)

	// Timestamp
	ts := jwt.TimeFunc().UTC().Unix()
	if err = binary.Write(&signedContent, byteOrder, timestamp(ts)); err != nil {
		return 0, err
	}

	// Token len
	tokenLen := len(h.token)
	// Check to see if it overflows uint16
	if int(tokenLength(tokenLen)) != tokenLen {
		return 0, ErrBadToken
	}

	// Token
	if err = binary.Write(&signedContent, byteOrder, h.token); err != nil {
		return 0, err
	}

	// Payload len
	payloadLen := len(h.payload)
	// Check to see if it overflows uint16
	if int(payloadLength(payloadLen)) != payloadLen {
		return 0, ErrPayloadTooLarge
	}
	if err = binary.Write(&signedContent, byteOrder, payloadLength(payloadLen)); err != nil {
		return 0, err
	}

	// Payload
	if err = binary.Write(&signedContent, byteOrder, h.payload); err != nil {
		return 0, err
	}

	// Sign the contents of the buffer
	sig, err := h.signer.Sign(signedContent.Bytes())
	if err != nil {
		return 0, err
	}

	// Write the magic number
	err = binary.Write(w, byteOrder, MagicNumber)
	if err != nil {
		return n, err
	}
	n += int64(binary.Size(MagicNumber))

	// Write the protocol version
	err = binary.Write(w, byteOrder, ProtocolVersion)
	if err != nil {
		return n, err
	}
	n += int64(binary.Size(ProtocolVersion))

	// Write the length of everything left except the payload len and payload
	allLen := uint32(tokenLen + 8)
	err = binary.Write(w, byteOrder, allLen)
	if err != nil {
		return n, err
	}

	// Write the signature
	err = binary.Write(w, byteOrder, sig)
	if err != nil {
		return n, err
	}
	n += int64(binary.Size(sig))

	// Write the buffer contents (timestamp, token, payloadlen, payload)
	bytesWritten, err = signedContent.WriteTo(w)
	if err != nil {
		return n, err
	}
	n += bytesWritten

	return n, nil
}
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
}
148315
func (t *Template) WriteTo(w io.Writer) (n int64, err error) {
	var buf bytes.Buffer

	// Write "generated" header comment.
	buf.WriteString("// Generated by ego.\n")
	buf.WriteString("// DO NOT EDIT\n\n")

	// Write blocks.
	writeBlocksTo(&buf, t.Blocks)

	// Parse buffer as a Go file.
	fset := token.NewFileSet()
	f, err := parser.ParseFile(fset, "", buf.Bytes(), parser.ParseComments)
	if err != nil {
		n, _ = buf.WriteTo(w)
		return n, err
	}

	// Inject required packages.
	injectImports(f)

	// Attempt to gofmt.
	var result bytes.Buffer
	if err := format.Node(&result, fset, f); err != nil {
		n, _ = buf.WriteTo(w)
		return n, err
	}

	// Write to output writer.
	return result.WriteTo(w)
}
608772
func (h *Hello) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, h.Elements)
}
734370
func (b *Bucket) WriteTo(w io.Writer) (int64, error) {
	// Serialize the list of actions first, to set the
	// valid length into the bucket header.
	actions, err := b.Actions.bytes()
	if err != nil {
		return 0, err
	}

	// The length of the bucket header consist of the
	// header length itself and the length of actions.
	return encoding.WriteTo(w, uint16(bucketLen+len(actions)),
		b.Weight, b.WatchPort, b.WatchGroup, pad4{}, actions)
}
448086
func (header *Header) WriteTo(w io.Writer) (int64, error) {
	switch header.Version {
	case 1:
		return header.writeVersion1(w)
	case 2:
		return header.writeVersion2(w)
	default:
		return 0, ErrUnknownProxyProtocolVersion
	}
}