// WriteSliceTo writes the slice of the types, that implement io.WriterTo
// interface into the given writer.
//
// The function will panic if the given variable is not a slice or elements
// of the slice does not implement interface io.WriterTo.
170417
func WriteSliceTo(w io.Writer, slice interface{}) (int64, error) {
	var n int64

	// Retrieve the lengt of the provided slice.
	sliceValue := reflect.ValueOf(slice)
	sliceLen := sliceValue.Len()

	for index := 0; index < sliceLen; index++ {
		// It is expected, that elements of the slice would not implement
		// the io.WriterTo interface, but their pointers will.
		addr := sliceValue.Index(index).Addr()
		writer := addr.Interface().(io.WriterTo)

		// Write the data to the provided writer instance.
		nn, err := writer.WriteTo(w)
		n += nn

		if err != nil {
			return n, err
		}
	}

	return n, nil
}
1321291
func (i *InstructionGotoTable) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, instruction{i.Type(), 8}, i.Table, pad3{})
}
435102
func (s *String) WriteTo(w io.Writer) (n int64, err error) {
	// unsigned short, can't use Short
	var length = uint16(len(s.Value))
	err = binary.Write(w, binary.BigEndian, &length)
	if err != nil {
		return
	}

	// Then write string bytes
	_, err = w.Write([]byte(s.Value))
	if err != nil {
		return
	}
	n += int64(length)

	return
}
485913
func (l *List) WriteTo(w io.Writer) (n int64, err error) {
	var nn int64

	// Write TagType prefix
	tt := types.Int8(l.Typ)
	if nn, err = tt.WriteTo(w); err != nil {
		return
	}
	n += nn

	length := types.Int32(len(l.Value))
	if nn, err = length.WriteTo(w); err != nil {
		return
	}
	n += nn

	for _, tag := range l.Value {
		if nn, err = tag.WriteTo(w); err != nil {
			return
		}
		n += nn
	}

	return
}
1336300
func (f Float) WriteTo(w io.Writer) (int64, error) {
	written, err := fmt.Fprintf(w, "%f", f)
	return int64(written), err
}
487565
func (p *KubernetesPath) WriteTo(out io.Writer) (int64, error) {
	return 0, fmt.Errorf("KubernetesPath::WriteTo not supported")
}
1172198
func (sel *selector) WriteTo(w io.Writer) (int64, error) {
	return sel.writeTo(w, nil)
}
125177
func (i Int) WriteTo(w io.Writer) (int64, error) {
	written, err := fmt.Fprintf(w, "%d", i)
	return int64(written), err
}
828407
func WriteSliceArray(lst [][]byte, buf *goetty.ByteBuf) {
	buf.WriteByte('*')
	if len(lst) == 0 {
		buf.Write(NullArray)
		buf.Write(Delims)
	} else {
		buf.Write(goetty.StringToSlice(strconv.Itoa(len(lst))))
		buf.Write(Delims)

		for i := 0; i < len(lst); i++ {
			WriteBulk(lst[i], buf)
		}
	}
}
389794
func (b *ByteBuffer) WriteTo(w io.Writer) (int64, error) {
	n, err := w.Write(b.B)
	return int64(n), err
}
550884
func (s *Store) WriteTo(w io.Writer) (n int64, err error) {
	s.mtx.RLock()
	defer s.mtx.RUnlock()

	return s.writeTo(w)
}
1208646
func (f *File) WriteTo(w io.Writer) (int64, error) {
	return f.WriteToIndent(w, "")
}
1280358
func (b *Builder) WriteTo(w Writer) error {
	switch b.optype {
	case condType:
		return b.cond.WriteTo(w)
	case selectType:
		return b.selectWriteTo(w)
	case insertType:
		return b.insertWriteTo(w)
	case updateType:
		return b.updateWriteTo(w)
	case deleteType:
		return b.deleteWriteTo(w)
	}

	return ErrNotSupportType
}
882203
func (t *Tree) WriteTo(w io.Writer) (int64, error) {
	return t.writeTo(w, "", "", 0, false)
}
191464
func (dec *declaration) writeTo(w io.Writer, params map[string]string) (int64, error) {
	bf := new(bytes.Buffer)

	bf.WriteString(dec.property)
	bf.WriteString(colon)

	for i, v := range strings.Split(dec.value, space) {
		if i > 0 {
			bf.WriteString(space)
		}

		for j, w := range strings.Split(v, comma) {
			if j > 0 {
				bf.WriteString(comma)
			}

			if strings.HasPrefix(w, dollarMark) {
				// Writing to the bytes.Buffer never returns an error.
				dec.writeParamTo(bf, strings.TrimPrefix(w, dollarMark), params)
			} else {
				bf.WriteString(w)
			}
		}
	}

	bf.WriteString(semicolon)

	n, err := w.Write(bf.Bytes())

	return int64(n), 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
}
985539
func (not Not) WriteTo(w Writer) error {
	if _, err := fmt.Fprint(w, "NOT "); err != nil {
		return err
	}
	switch not[0].(type) {
	case condAnd, condOr:
		if _, err := fmt.Fprint(w, "("); err != nil {
			return err
		}
	case Eq:
		if len(not[0].(Eq)) > 1 {
			if _, err := fmt.Fprint(w, "("); err != nil {
				return err
			}
		}
	case Neq:
		if len(not[0].(Neq)) > 1 {
			if _, err := fmt.Fprint(w, "("); err != nil {
				return err
			}
		}
	}

	if err := not[0].WriteTo(w); err != nil {
		return err
	}

	switch not[0].(type) {
	case condAnd, condOr:
		if _, err := fmt.Fprint(w, ")"); err != nil {
			return err
		}
	case Eq:
		if len(not[0].(Eq)) > 1 {
			if _, err := fmt.Fprint(w, ")"); err != nil {
				return err
			}
		}
	case Neq:
		if len(not[0].(Neq)) > 1 {
			if _, err := fmt.Fprint(w, ")"); err != nil {
				return err
			}
		}
	}

	return nil
}