// Encode an arbitrary value as a pretty XML string. Note: there are no guarantees.
977194
func XmlIndent(v interface{}, prefix, indent string, rootTag ...string) ([]byte, error) {
	if reflect.TypeOf(v).Kind() == reflect.Struct {
		return xml.MarshalIndent(v, prefix, indent)
	}

	var err error
	s := new(string)
	p := new(pretty)
	p.indent = indent
	p.padding = prefix

	var rt string
	if len(rootTag) == 1 {
		rt = rootTag[0]
	} else {
		rt = DefaultRootTag
	}

	var ss string
	var b []byte

	switch v.(type) {

	case []interface{}:
		ss = "<" + rt + ">\n"
		p.Indent()
		for _, vv := range v.([]interface{}) {
			switch vv.(type) {
			case map[string]interface{}:
				m := vv.(map[string]interface{})
				if len(m) == 1 {
					for tag, val := range m {

						err = mapToXmlIndent(true, s, tag, val, p)
					}
				} else {
					p.start = 1 // we're 1 tag in to the doc
					err = mapToXmlIndent(true, s, "element", vv, p)
					*s += "\n"
				}
			case []map[string]interface{}:
				*s += p.padding + "<element>\n" + p.padding
				for _, vvv := range vv.([]map[string]interface{}) {
					err = mapToXmlIndent(true, s, "element", vvv, p)
					*s += "\n"
					if err != nil {
						break
					}
				}
				*s += "</element>\n"
			default:
				p.start = 0
				err = mapToXmlIndent(true, s, "element", vv, p)
			}
			if err != nil {
				break
			}
		}
		ss += *s + "</" + rt + ">"
		b = []byte(ss)
	case map[string]interface{}:
		b, err = anyxmlIndent(v.(map[string]interface{}), prefix, indent, rootTag...)
	case []map[string]interface{}:
		for _, vv := range v.([]map[string]interface{}) {
			b, err = anyxmlIndent(vv, prefix, indent, rootTag...)
			ss += (string(b) + "\n")
			if err != nil {
				break
			}
		}
		b = []byte(ss)
	default:
		err = mapToXmlIndent(true, s, rt, v, p)
		b = []byte(*s)
	}

	return b, err
}
802542
func encodeKeyValue(k, v string) (string, string) {
	k = strings.ToLower(k)
	if strings.HasSuffix(k, binHdrSuffix) {
		val := base64.StdEncoding.EncodeToString([]byte(v))
		v = string(val)
	}
	return k, v
}
924916
func (enc *Encoding) EncodeToString(b []byte) string {
	n := new(big.Int)
	r := new(big.Int)
	n.SetBytes(b)
	var result []byte
	for n.Cmp(zero) > 0 {
		n, r = n.DivMod(n, enc.base, r)
		result = append([]byte{enc.alphabet[r.Int64()]}, result...)
	}
	return string(result)
}
657476
func (enc *Encoder) Encode(v interface{}) error {
	if enc.err != nil {
		return enc.err
	}
	e := newEncodeState(enc.canonical)
	err := e.marshal(v)
	if err != nil {
		return err
	}

	if !enc.canonical {
		// Terminate each value with a newline.
		// This makes the output look a little nicer
		// when debugging, and some kind of space
		// is required if the encoded value was a number,
		// so that the reader knows there aren't more
		// digits coming.
		e.WriteByte('\n')
	}

	if _, err = enc.w.Write(e.Bytes()); err != nil {
		enc.err = err
	}
	encodeStatePool.Put(e)
	return err
}
706460
func (v Value) EncodeASCII(b BinWriter) {
	switch {
	case v.typ == Null:
		b.Write(nullstr)
	case v.IsQuoted() || v.typ == Bit:
		encodeBytesASCII(v.val, b)
	default:
		b.Write(v.val)
	}
}
969453
func (e StringEncoder) Encode(data interface{}, out *goetty.ByteBuf) error {
	msg, _ := data.(string)
	bytes := []byte(msg)
	out.WriteInt(len(bytes))
	out.Write(bytes)
	return nil
}
821600
func encodeResponse(response interface{}) []byte {
	var bytesBuffer bytes.Buffer
	bytesBuffer.WriteString(xml.Header)
	e := xml.NewEncoder(&bytesBuffer)
	e.Encode(response)
	return bytesBuffer.Bytes()
}
764093
func (s ISO88595) Encode() []byte {
	e := charmap.ISO8859_5.NewEncoder()
	es, _, err := transform.Bytes(e, s)
	if err != nil {
		return s
	}
	return es
}
825266
func (r *RequestToken) Encode() string {
	values := url.Values{}
	values.Set("oauth_token", r.token)
	values.Set("oauth_token_secret", r.secret)
	values.Set("oauth_callback_confirmed", strconv.FormatBool(r.callbackConfirmed))
	return values.Encode()
}
288503
func (s *Serializer) Encode(obj runtime.Object, w io.Writer) error {
	if s.options.Yaml {
		json, err := caseSensitiveJsonIterator.Marshal(obj)
		if err != nil {
			return err
		}
		data, err := yaml.JSONToYAML(json)
		if err != nil {
			return err
		}
		_, err = w.Write(data)
		return err
	}

	if s.options.Pretty {
		data, err := caseSensitiveJsonIterator.MarshalIndent(obj, "", "  ")
		if err != nil {
			return err
		}
		_, err = w.Write(data)
		return err
	}
	encoder := json.NewEncoder(w)
	return encoder.Encode(obj)
}
1059116
func (a *NodeAnnouncement) Encode(w io.Writer, pver uint32) error {
	return WriteElements(w,
		a.Signature,
		a.Features,
		a.Timestamp,
		a.NodeID,
		a.RGBColor,
		a.Alias,
		a.Addresses,
		a.ExtraOpaqueData,
	)
}
987195
func EncodeNode(node *Node) map[string]string {
	labels := make(map[string]string)
	encodeNode(labels, node.Name, node)
	return labels
}
1233717
func Encode(dst, src []byte) int {
	for i, v := range src {
		dst[i*2] = hextable[v>>4]
		dst[i*2+1] = hextable[v&0x0f]
	}

	return len(src) * 2
}
255253
func Encode(xs []float64, dim int) string {
	n := len(xs)
	ys := make([]int, n)
	for i := 0; i < n; i++ {
		ys[i] = int(1e5 * xs[i])
	}
	for i := n - 1; i >= dim; i-- {
		ys[i] -= ys[i-dim]
	}
	return EncodeInts(ys)
}
328542
func (encoder *IntLengthFieldBasedEncoder) Encode(data interface{}, out *ByteBuf) error {
	buf := NewByteBuf(32)

	if encoder.prepare != nil {
		err := encoder.prepare(data, out)
		if err != nil {
			return err
		}
	}

	err := encoder.base.Encode(data, buf)
	if err != nil {
		return err
	}

	out.WriteInt(buf.Readable())
	out.WriteByteBuf(buf)
	return nil
}
1214571
func (v TimestampValue) encode(w io.Writer) error {
	raw := rawValue{
		Type: v.valueType(),
	}

	msec := v.epochMilli()
	return raw.encodeScalar(w, msec)
}
1254007
func (c *UpdateFailHTLC) Encode(w io.Writer, pver uint32) error {
	return WriteElements(w,
		c.ChanID,
		c.ID,
		c.Reason,
	)
}