// EncodeJSONP encodes a data as jsonp
545299
func (enc *HTTPEncoder) EncodeJSONP(callback string, model Model) error {
	setContentType(enc.writer, ContentJSONP)

	data, _ := json.Marshal(model)
	_, err := fmt.Fprintf(enc.writer, "%s(%s)", callback, string(data))
	if err != nil {
		http.Error(enc.writer, fmt.Sprintf("Unable to encode '%v' as JSON for javascript func %s: %s", model, callback, err.Error()), http.StatusInternalServerError)
	}
	return err
}
123078
func EncodeBytes(data []byte) string {
	mt := http.DetectContentType(data)
	// http.DetectContentType may add spurious spaces between ; and a parameter.
	// The canonical way is to not have them.
	cleanedMt := strings.Replace(mt, "; ", ";", -1)

	return New(data, cleanedMt).String()
}
640869
func (v *RPC) GetEncoding() (o string) {
	if v != nil {
		o = v.Encoding
	}
	return
}
966925
func (enc *HTTPEncoder) EncodeJSON(model Model) error {
	setContentType(enc.writer, ContentJSON)

	err := json.NewEncoder(enc.writer).Encode(model)
	if err != nil {
		http.Error(enc.writer, fmt.Sprintf("Unable to encode '%v' as JSON data: %s", model, err.Error()), http.StatusInternalServerError)
	}
	return err
}
1288500
func base64Encode(data []byte) string {
	// Check whether the data is already Base64 encoded; don't double-encode
	if isBase64Encoded(data) {
		return string(data)
	}
	// data has not been encoded encode and return
	return base64.StdEncoding.EncodeToString(data)
}
45463
func encode(data interface{}) ([]byte, error) {
	if data == nil {
		return nil, nil
	}
	buf := bytes.NewBuffer([]byte{})
	enc := gob.NewEncoder(buf)
	if err := enc.Encode(data); err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}
1169149
func (jd *JSONDecoder) Encode(data []*FileDataEntry) ([]byte, error) {
	// Convert to json-specific structure
	var jsonFileEntries []jsonFileEntry
	for _, dataEntry := range data {
		jsonFileEntries = append(jsonFileEntries, jsonFileEntry{
			Key:   dataEntry.Key,
			Value: dataEntry.Value,
		})
	}
	// Encode to type specific structure
	jsonFile := &jsonFile{Data: jsonFileEntries}
	return json.Marshal(jsonFile)
}
990748
func (this *Response) Jsonp(i interface{}, s ...int) {

	req := this.req
	app := this.app

	// If we were given a status, us it.
	if len(s) == 1 {
		this.StatusCode = s[0]
	}

	body := this.json(i)

	if cb, ok := req.Query[app.Get("jsonp callback name")]; ok {
		this.ContentType("text/javascript")
		body = cb + " && " + cb + "(" + body + ");"
	}

	this.Send(body)
}
14358
func EncodeJSONRequest(_ context.Context, msg *nats.Msg, request interface{}) error {
	b, err := json.Marshal(request)
	if err != nil {
		return err
	}

	msg.Data = b

	return nil
}
961322
func EncoderFromJSON(js json.RawMessage) (encoders.Encoder, error) {
	tmp := struct {
		Type string `json:"encoder"`
	}{}
	if err := json.Unmarshal(js, &tmp); err != nil {
		return nil, err
	} else if res := EncoderDecoderFromString(tmp.Type); res == nil {
		return nil, fmt.Errorf("encoder of type '%s' is not supported", tmp.Type)
	} else {
		return res, UnmarshalAndStart(res, js)
	}
}
956541
func mapEncoder(c martini.Context, w http.ResponseWriter, r *http.Request) {
	// Get the format extension
	matches := rxExt.FindStringSubmatch(r.URL.Path)
	ft := ".json"
	if len(matches) > 1 {
		// Rewrite the URL without the format extension
		l := len(r.URL.Path) - len(matches[1])
		if strings.HasSuffix(r.URL.Path, "/") {
			l--
		}
		r.URL.Path = r.URL.Path[:l]
		ft = matches[1]
	}
	// Inject the requested encoder
	switch ft {
	// Add cases for other formats
	default:
		c.MapTo(jsonEncoder{}, (*encoder)(nil))
		w.Header().Set("Content-Type", "application/json")
	}
}
214291
func JsonToSexp(json []byte, env *Zlisp) (Sexp, error) {
	iface, err := JsonToGo(json)
	if err != nil {
		return nil, err
	}
	return GoToSexp(iface, env)
}
274451
func EncodeURLParamMap(m *URLParamMap) string {

	parameters := url.Values{}

	for k, v := range *m {
		l := len(v)
		for x := 0; x < l; x++ {
			parameters.Add(k, v[x])
		}

	}

	qEncoded := parameters.Encode()
	return string(qEncoded)

}
1080431
func encodeRegexp(buf *bytes.Buffer, name string, val Regexp) error {
	// type
	if err := buf.WriteByte(_REGEXP); err != nil {
		return err
	}

	// name
	if err := writeCstring(buf, name); err != nil {
		return err
	}

	// regex
	if err := writeCstring(buf, val.Pattern); err != nil {
		return err
	}

	// options
	return writeCstring(buf, val.Options)
}
875875
func (e *JSONEncoder) EncodeInfo(res *InfoResult) ([]byte, error) {
	return json.Marshal(res)
}
475772
func EncodeJSON(w io.Writer, i *Iterator) error {
	r := make(Record)

	// Open paren.
	if _, err := w.Write([]byte{'['}); err != nil {
		return err
	}

	var c int
	enc := json.NewEncoder(w)

	delim := []byte{',', '\n'}

	for i.Next() {
		if c > 0 {
			if _, err := w.Write(delim); err != nil {
				return err
			}
		}

		c++

		if err := i.Scan(r); err != nil {
			return err
		}

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

	// Close paren.
	if _, err := w.Write([]byte{']'}); err != nil {
		return err
	}

	return nil
}
1260974
func (e *JSONEncoder) EncodeUnsubscribe(res *UnsubscribeResult) ([]byte, error) {
	return json.Marshal(res)
}