// writeTo for runContainer16 follows this
// spec: https://github.com/RoaringBitmap/RoaringFormatSpec
//
342712
func (b *runContainer16) writeTo(stream io.Writer) (int, error) {
	buf := make([]byte, 2+4*len(b.iv))
	binary.LittleEndian.PutUint16(buf[0:], uint16(len(b.iv)))
	for i, v := range b.iv {
		binary.LittleEndian.PutUint16(buf[2+i*4:], v.start)
		binary.LittleEndian.PutUint16(buf[2+2+i*4:], v.length)
	}
	return stream.Write(buf)
}
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{},
	)
}
1018969
func (arr *ByteArray) WriteTo(w io.Writer) (n int64, err error) {
	var nn int64

	// Write length-prefix
	var length = types.Int32(len(arr.Value))
	nn, err = length.WriteTo(w)
	if err != nil {
		return
	}
	n += nn

	// Then write byte array
	for _, elem := range arr.Value {
		nn, err = elem.WriteTo(w)
		if err != nil {
			return
		}
		n += nn
	}

	return
}
1068848
func (hdr *rpmHeader) WriteTo(outfile io.Writer, regionTag int) error {
	if regionTag != 0 && regionTag >= RPMTAG_HEADERREGIONS {
		return errors.New("invalid region tag")
	}
	// sort tags
	var keys []int
	for k := range hdr.entries {
		if k < RPMTAG_HEADERREGIONS {
			// discard existing regions
			continue
		}
		keys = append(keys, k)
	}
	sort.Ints(keys)
	entries := bytes.NewBuffer(make([]byte, 0, 16*len(keys)))
	blobs := bytes.NewBuffer(make([]byte, 0, hdr.origSize))
	for _, k := range keys {
		if k == regionTag {
			continue
		}
		if err := writeTag(entries, blobs, k, hdr.entries[k]); err != nil {
			return err
		}
	}
	intro := headerIntro{
		Magic:    introMagic,
		Reserved: 0,
		Entries:  uint32(len(keys) + 1),
		Size:     uint32(blobs.Len() + 16),
	}
	if err := binary.Write(outfile, binary.BigEndian, &intro); err != nil {
		return err
	}
	if err := writeRegion(outfile, blobs, regionTag, len(keys)); err != nil {
		return err
	}
	totalSize := 96 + blobs.Len() + entries.Len()
	if _, err := io.Copy(outfile, entries); err != nil {
		return err
	}
	if _, err := io.Copy(outfile, blobs); err != nil {
		return err
	}
	if regionTag == RPMTAG_HEADERSIGNATURES {
		alignment := totalSize % 8
		if alignment != 0 {
			outfile.Write(make([]byte, 8-alignment))
		}
	}
	return nil
}
58055
func (p *PortStatus) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, p.Reason, pad7{}, &p.Port)
}
1336300
func (f Float) WriteTo(w io.Writer) (int64, error) {
	written, err := fmt.Fprintf(w, "%f", f)
	return int64(written), err
}
888375
func (b *Bitmap) WriteTo(w io.Writer) (n int64, err error) {
	b.Optimize()
	return b.writeToUnoptimized(w)
}
166412
func (g *GroupStatsRequest) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, g.Group, pad4{})
}
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
}
328639
func (f *BloomFilter) WriteTo(stream io.Writer) (int64, error) {
	err := binary.Write(stream, binary.BigEndian, uint64(f.m))
	if err != nil {
		return 0, err
	}
	err = binary.Write(stream, binary.BigEndian, uint64(f.k))
	if err != nil {
		return 0, err
	}
	numBytes, err := f.b.WriteTo(stream)
	return numBytes + int64(2*binary.Size(uint64(0))), err
}
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))
}
463840
func (s String) WriteTo(w io.Writer) (int64, error) {
	written, err := fmt.Fprintf(w, "%s", s)
	return int64(written), err
}
754358
func (e *Entry) WriteTo(w io.Writer) (n int64, err error) {
	r := e.Open()
	if r == nil {
		return 0, errors.New("asar: entry cannot be opened")
	}
	return io.Copy(w, r)
}
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
}
860708
func (b Bool) WriteTo(w io.Writer) (int64, error) {
	written, err := fmt.Fprintf(w, "%t", b)
	return int64(written), err
}
1264599
func (t Time) WriteTo(w Writer) error {
	bytes, err := time.Time(t).MarshalBinary()
	if err != nil {
		return errorsp.WithStacks(err)
	}
	return errorsp.WithStacks(ByteSlice(bytes).WriteTo(w))
}
19582
func (m *Image) WriteTo(w io.Writer) (int64, error) {
	return 0, png.Encode(w, m.Paletted)
}