// EncodeToValues encodes dst as a form and returns it as Values.
182269
func EncodeToValues(dst interface{}) (url.Values, error) {
	v := reflect.ValueOf(dst)
	n, err := encodeToNode(v, false)
	if err != nil {
		return nil, err
	}
	vs := n.values(defaultDelimiter, defaultEscape)
	return vs, nil
}
857516
func encodeByteSlice(v reflect.Value) (interface{}, error) {
	var b []byte
	if !v.IsNil() {
		b = v.Bytes()
	}

	dst := make([]byte, base64.StdEncoding.EncodedLen(len(b)))
	base64.StdEncoding.Encode(dst, b)

	return map[string]interface{}{
		"$reql_type$": "BINARY",
		"data":        string(dst),
	}, nil
}
36483
func (iv InsertValues) EncodeSQL(buf *strings.Builder) {
	for i, rows := range iv {
		if i != 0 {
			buf.WriteString(", ")
		}
		buf.WriteByte('(')
		for j, bv := range rows {
			if j != 0 {
				buf.WriteString(", ")
			}
			bv.EncodeSQL(buf)
		}
		buf.WriteByte(')')
	}
}
1152131
func (e Encoder) Encode(dst interface{}) error {
	v := reflect.ValueOf(dst)
	n, err := encodeToNode(v, e.z)
	if err != nil {
		return err
	}
	s := n.values(e.d, e.e).Encode()
	l, err := io.WriteString(e.w, s)
	switch {
	case err != nil:
		return err
	case l != len(s):
		return errors.New("could not write data completely")
	}
	return nil
}
1015769
func (Encoder) AppendTimes(dst []byte, vals []time.Time, format string) []byte {
	switch format {
	case timeFormatUnix:
		return appendUnixTimes(dst, vals)
	case timeFormatUnixMs:
		return appendUnixMsTimes(dst, vals)
	}
	if len(vals) == 0 {
		return append(dst, '[', ']')
	}
	dst = append(dst, '[')
	dst = append(vals[0].AppendFormat(append(dst, '"'), format), '"')
	if len(vals) > 1 {
		for _, t := range vals[1:] {
			dst = append(t.AppendFormat(append(dst, ',', '"'), format), '"')
		}
	}
	dst = append(dst, ']')
	return dst
}
388375
func (pp *Pubrec) Encode(dst []byte) (int, error) {
	return identifiedEncode(dst, pp.ID, PUBREC)
}
1076923
func (c *ChannelsInfoCall) FromValues(v url.Values) error {
	var tmp ChannelsInfoCall
	if raw := strings.TrimSpace(v.Get("channel")); len(raw) > 0 {
		tmp.channel = raw
	}
	if raw := strings.TrimSpace(v.Get("include_locale")); len(raw) > 0 {
		parsed, err := strconv.ParseBool(raw)
		if err != nil {
			return errors.Wrap(err, `failed to parse boolean value "include_locale"`)
		}
		tmp.includeLocale = parsed
	}
	*c = tmp
	return nil
}
488462
func (cp *Connect) Encode(dst []byte) (int, error) {
	total := 0

	// encode header
	n, err := headerEncode(dst[total:], 0, cp.len(), cp.Len(), CONNECT)
	total += n
	if err != nil {
		return total, err
	}

	// set default version byte
	if cp.Version == 0 {
		cp.Version = Version311
	}

	// check version byte
	if cp.Version != Version311 && cp.Version != Version31 {
		return total, makeError(cp.Type(), "unsupported protocol version %d", cp.Version)
	}

	// write version string, length has been checked beforehand
	if cp.Version == Version311 {
		n, _ = writeLPBytes(dst[total:], version311Name, cp.Type())
		total += n
	} else if cp.Version == Version31 {
		n, _ = writeLPBytes(dst[total:], version31Name, cp.Type())
		total += n
	}

	// write version value
	dst[total] = cp.Version
	total++

	var connectFlags byte

	// set username flag
	if len(cp.Username) > 0 {
		connectFlags |= 128 // 10000000
	} else {
		connectFlags &= 127 // 01111111
	}

	// set password flag
	if len(cp.Password) > 0 {
		connectFlags |= 64 // 01000000
	} else {
		connectFlags &= 191 // 10111111
	}

	// set will flag
	if cp.Will != nil {
		connectFlags |= 0x4 // 00000100

		// check will topic length
		if len(cp.Will.Topic) == 0 {
			return total, makeError(cp.Type(), "will topic is empty")
		}

		// check will qos
		if !cp.Will.QOS.Successful() {
			return total, makeError(cp.Type(), "invalid will qos level %d", cp.Will.QOS)
		}

		// set will qos flag
		connectFlags = (connectFlags & 231) | (byte(cp.Will.QOS) << 3) // 231 = 11100111

		// set will retain flag
		if cp.Will.Retain {
			connectFlags |= 32 // 00100000
		} else {
			connectFlags &= 223 // 11011111
		}

	} else {
		connectFlags &= 251 // 11111011
	}

	// check client id and clean session
	if len(cp.ClientID) == 0 && !cp.CleanSession {
		return total, makeError(cp.Type(), "clean session must be 1 if client id is zero length")
	}

	// set clean session flag
	if cp.CleanSession {
		connectFlags |= 0x2 // 00000010
	} else {
		connectFlags &= 253 // 11111101
	}

	// write connect flags
	dst[total] = connectFlags
	total++

	// write keep alive
	binary.BigEndian.PutUint16(dst[total:], cp.KeepAlive)
	total += 2

	// write client id
	n, err = writeLPString(dst[total:], cp.ClientID, cp.Type())
	total += n
	if err != nil {
		return total, err
	}

	// write will topic and payload
	if cp.Will != nil {
		n, err = writeLPString(dst[total:], cp.Will.Topic, cp.Type())
		total += n
		if err != nil {
			return total, err
		}

		n, err = writeLPBytes(dst[total:], cp.Will.Payload, cp.Type())
		total += n
		if err != nil {
			return total, err
		}
	}

	if len(cp.Username) == 0 && len(cp.Password) > 0 {
		return total, makeError(cp.Type(), "password set without username")
	}

	// write username
	if len(cp.Username) > 0 {
		n, err = writeLPString(dst[total:], cp.Username, cp.Type())
		total += n
		if err != nil {
			return total, err
		}
	}

	// write password
	if len(cp.Password) > 0 {
		n, err = writeLPString(dst[total:], cp.Password, cp.Type())
		total += n
		if err != nil {
			return total, err
		}
	}

	return total, nil
}
607707
func (Encoder) AppendInts(dst []byte, vals []int) []byte {
	if len(vals) == 0 {
		return append(dst, '[', ']')
	}
	dst = append(dst, '[')
	dst = strconv.AppendInt(dst, int64(vals[0]), 10)
	if len(vals) > 1 {
		for _, val := range vals[1:] {
			dst = strconv.AppendInt(append(dst, ','), int64(val), 10)
		}
	}
	dst = append(dst, ']')
	return dst
}
152967
func ConvertToURLValues(data map[string]string) string {
	v := url.Values{}

	for key, val := range data {
		v.Set(key, val)
	}

	return v.Encode()
}
400619
func encodeKeyValue(w io.Writer, p map[string]string) error {
	for k, v := range p {
		if err := writeKeyValuePair(w, k, v); err != nil {
			return err
		}
	}
	return nil
}
641636
func encodeManagedFields(managedFields fieldpath.ManagedFields) (encodedManagedFields []metav1.ManagedFieldsEntry, err error) {
	// Sort the keys so a predictable order will be used.
	managers := []string{}
	for manager := range managedFields {
		managers = append(managers, manager)
	}
	sort.Strings(managers)

	encodedManagedFields = []metav1.ManagedFieldsEntry{}
	for _, manager := range managers {
		versionedSet := managedFields[manager]
		v, err := encodeManagerVersionedSet(manager, versionedSet)
		if err != nil {
			return nil, fmt.Errorf("error encoding versioned set for %v: %v", manager, err)
		}
		encodedManagedFields = append(encodedManagedFields, *v)
	}
	return sortEncodedManagedFields(encodedManagedFields)
}
880326
func EncodeValue(sc *stmtctx.StatementContext, b []byte, v ...types.Datum) ([]byte, error) {
	return encode(sc, b, v, false, false)
}
771666
func formValues(r *http.Request) (map[string]interface{}, *search.Options) {
	fv := make(map[string]interface{})
	var options search.Options

	fv["searchterm"] = r.FormValue("searchterm")
	options.SearchTerm = r.FormValue("searchterm")

	if r.FormValue("google") == "on" {
		fv["google"] = "checked"
		options.Google = true
	} else {
		fv["google"] = ""
	}

	if r.FormValue("bing") == "on" {
		fv["bing"] = "checked"
		options.Bing = true
	} else {
		fv["bing"] = ""
	}

	if r.FormValue("blekko") == "on" {
		fv["blekko"] = "checked"
		options.Blekko = true
	} else {
		fv["blekko"] = ""
	}

	if r.FormValue("first") == "on" {
		fv["first"] = "checked"
		options.First = true
	} else {
		fv["first"] = ""
	}

	return fv, &options
}
40853
func encodeHeaders(hs map[string]string) []byte {
	if len(hs) == 0 {
		return []byte{0, 0} // nh = 2
	}

	size := 2 // nh:2
	for k, v := range hs {
		size += len(k) + 2 // k~2
		size += len(v) + 2 // v~2
	}

	out := make([]byte, size)

	i := 2
	binary.BigEndian.PutUint16(out, uint16(len(hs))) // nh:2
	for k, v := range hs {
		i += _putStr16(k, out[i:]) // k~2
		i += _putStr16(v, out[i:]) // v~2
	}

	return out
}
82994
func (e Encoder) AppendDurations(dst []byte, vals []time.Duration, unit time.Duration, useInt bool) []byte {
	if len(vals) == 0 {
		return append(dst, '[', ']')
	}
	dst = append(dst, '[')
	dst = e.AppendDuration(dst, vals[0], unit, useInt)
	if len(vals) > 1 {
		for _, d := range vals[1:] {
			dst = e.AppendDuration(append(dst, ','), d, unit, useInt)
		}
	}
	dst = append(dst, ']')
	return dst
}
1065761
func nakedEncode(dst []byte, t Type) (int, error) {
	// encode header
	return headerEncode(dst, 0, 0, nakedLen(), t)
}