// encode is a helper function to encode a chunk of data into various formats
// input data is copied
176552
func encode(span uint32, format Format, data []byte) []byte {
	switch format {
	case FormatStandardGoTszWithSpan, FormatGoTszLongWithSpan:
		buf := new(bytes.Buffer)
		binary.Write(buf, binary.LittleEndian, format)

		spanCode, ok := RevChunkSpans[span]
		if !ok {
			// it's probably better to panic than to persist the chunk with a wrong length
			panic(fmt.Sprintf("Chunk span invalid: %d", span))
		}
		binary.Write(buf, binary.LittleEndian, spanCode)
		buf.Write(data)
		return buf.Bytes()
	case FormatStandardGoTsz:
		buf := new(bytes.Buffer)
		binary.Write(buf, binary.LittleEndian, format)
		buf.Write(data)
		return buf.Bytes()
	}
	return nil
}
1111503
func (oc *OutputChange) Encode() (*OutputChangeSrc, error) {
	cs, err := oc.Change.Encode(cty.DynamicPseudoType)
	if err != nil {
		return nil, err
	}
	return &OutputChangeSrc{
		Addr:      oc.Addr,
		ChangeSrc: *cs,
		Sensitive: oc.Sensitive,
	}, err
}
207994
func (e *Encoder) Encode(in interface{}) (*dynamodb.AttributeValue, error) {
	av := &dynamodb.AttributeValue{}
	if err := e.encode(av, reflect.ValueOf(in), tag{}); err != nil {
		return nil, err
	}

	return av, nil
}
294657
func encode(s string) string {
	r := s
	for _, tr := range codecValues {
		if strings.Index(r, tr.decoded) >= 0 {
			r = strings.Replace(r, tr.decoded, tr.encoded, -1)
		}
	}
	return r
}
128023
func (u *UploadRequest) Encode(w io.Writer) error {
	e := newUlReqEncoder(w)
	return e.Encode(u)
}
823782
func (this Map) Encode() (BSON, error) {
	b, err := encodeMap("", this)
	if err != nil {
		return nil, err
	}
	return b, nil
}
1023902
func (r *UploadPackResponse) Encode(w io.Writer) (err error) {
	if r.isShallow {
		if err := r.ShallowUpdate.Encode(w); err != nil {
			return err
		}
	}

	if err := r.ServerResponse.Encode(w); err != nil {
		return err
	}

	defer ioutil.CheckClose(r.r, &err)
	_, err = io.Copy(w, r.r)
	return err
}
767295
func (v Values) Encode(w io.Writer) error {
	//return yaml.NewEncoder(w).Encode(v)
	out, err := yaml.Marshal(v)
	if err != nil {
		return err
	}
	_, err = w.Write(out)
	return err
}
273495
func (f *Values) Encode() string {
	var buf bytes.Buffer
	for _, v := range f.values {
		if buf.Len() > 0 {
			buf.WriteByte('&')
		}
		buf.WriteString(url.QueryEscape(v.Key))
		buf.WriteString("=")
		buf.WriteString(url.QueryEscape(v.Value))
	}
	return buf.String()
}
1180375
func encode(e encoder, metricRegistry metrics.Registry) ([]byte, error) {
	if e == nil {
		return nil, nil
	}

	var prepEnc prepEncoder
	var realEnc realEncoder

	err := e.encode(&prepEnc)
	if err != nil {
		return nil, err
	}

	if prepEnc.length < 0 || prepEnc.length > int(MaxRequestSize) {
		return nil, PacketEncodingError{fmt.Sprintf("invalid request size (%d)", prepEnc.length)}
	}

	realEnc.raw = make([]byte, prepEnc.length)
	realEnc.registry = metricRegistry
	err = e.encode(&realEnc)
	if err != nil {
		return nil, err
	}

	return realEnc.raw, nil
}
852125
func Encode(data interface{}) string {
	switch v := data.(type) {
	case string:
		return EncodeString(v)
	case int:
		return EncodeInt(v)
	case []interface{}:
		return EncodeList(v)
	case map[string]interface{}:
		return EncodeDict(v)
	default:
		panic("invalid type when encode")
	}
}
1303477
func Encode(w http.ResponseWriter, req *http.Request) {
	val := func(s string) int {
		v, _ := strconv.Atoi(req.FormValue(s))
		return v
	}

	l := coding.Level(val("l"))
	v := coding.Version(val("v"))
	enc := coding.String(req.FormValue("t"))
	m := coding.Mask(val("m"))

	p, err := coding.NewPlan(v, l, m)
	if err != nil {
		panic(err)
	}
	cc, err := p.Encode(enc)
	if err != nil {
		panic(err)
	}

	c := &qr.Code{Bitmap: cc.Bitmap, Size: cc.Size, Stride: cc.Stride, Scale: 8}
	w.Header().Set("Content-Type", "image/png")
	w.Header().Set("Cache-Control", "public, max-age=3600")
	w.Write(c.PNG())
}
1009454
func encode(i interface{}, w http.ResponseWriter) {
	w.Header().Add("Content-Type", "application/json")

	enc := json.NewEncoder(w)
	err := enc.Encode(i)
	// Problems encoding
	if err != nil {
		LoggingClient.Error("Error encoding the data: " + err.Error())
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
}
866235
func (d *dataEncoder) encode(data []byte) (*bitset.Bitset, error) {
	d.data = data
	d.actual = nil
	d.optimised = nil

	if len(data) == 0 {
		return nil, errors.New("no data to encode")
	}

	// Classify data into unoptimised segments.
	d.classifyDataModes()

	// Optimise segments.
	err := d.optimiseDataModes()
	if err != nil {
		return nil, err
	}

	// Encode data.
	encoded := bitset.New()
	for _, s := range d.optimised {
		d.encodeDataRaw(s.data, s.dataMode, encoded)
	}

	return encoded, nil
}
69744
func Encode(charset int, utf_8 []byte) (latin []byte, success int, err error) {
	return converters[charset].Encode(utf_8)
}
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
}
1325587
func (e *Encoder) Encode(payloads ...[]byte) error {
	for _, p := range payloads {
		if err := e.encodeLine(p); err != nil {
			return err
		}
	}

	return nil
}