// EncoderFromJSON builds an encoder from json.
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)
	}
}
804817
func (f WithoutConversionCodecFactory) EncoderForVersion(serializer runtime.Encoder, version runtime.GroupVersioner) runtime.Encoder {
	return runtime.WithVersionEncoder{
		Version:     version,
		Encoder:     serializer,
		ObjectTyper: f.CodecFactory.scheme,
	}
}
1291268
func (c *V1) Encode(w io.Writer, prettify bool) error {
	encoder := json.NewEncoder(w)
	if prettify {
		encoder.SetIndent("", strings.Repeat(" ", 2))
	}
	return encoder.Encode(c)
}
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
}
1205387
func (w *Stream) Encode(m JSONMessage) error {
	return w.enc.Encode(m)
}
1157808
func (e *Encoder) Encode(v interface{}) error {
	val := reflect.ValueOf(v)
	return e.encode(val)
}
1230511
func (f CodecFactory) EncoderForVersion(encoder runtime.Encoder, gv runtime.GroupVersioner) runtime.Encoder {
	return f.CodecForVersions(encoder, nil, gv, nil)
}
1090055
func (e EncodedHeader) MarshalJSON() ([]byte, error) {
	buf, err := e.Base64Encode()
	if err != nil {
		return nil, errors.Wrap(err, "failed to base64 encode encoded header")
	}
	return json.Marshal(string(buf))
}
751059
func (b binaryEncoderDecoder) Encode(v interface{}) ([]byte, error) {
	buf := bytes.NewBuffer([]byte{})
	enc := gob.NewEncoder(buf)
	if err := enc.Encode(v); err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}
167441
func (e *Encoder) Encodef(format string, a ...interface{}) error {
	return e.EncodeString(
		fmt.Sprintf(format, a...),
	)
}
355960
func EncoderDecoderFromString(str string) encoders.EncoderDecoder {
	var res encoders.EncoderDecoder
	switch str {
	case "gzip":
		res = &gzip.Gzip{}
	case "aes":
		res = &aes.AES{}
	case "openpgp":
		res = &openpgp.OpenPGP{}
	}
	return res
}
1030168
func (marshaller *ProtoMarshaller) NewEncoder(writer io.Writer) Encoder {
	return EncoderFunc(func(value interface{}) error {
		buffer, err := marshaller.Marshal(value)
		if err != nil {
			return err
		}
		_, err = writer.Write(buffer)
		if err != nil {
			return err
		}

		return nil
	})
}
476301
func (m *Marshaller) Encode(obj interface{}, w io.Writer) error {
	m.writer.w = w
	err := m.marshal.Marshal(obj)
	m.writer.w = nil
	return err
}
775469
func EncodeJSONResponse(
	ctx context.Context,
	pub *amqp.Publishing,
	response interface{},
) error {
	b, err := json.Marshal(response)
	if err != nil {
		return err
	}
	pub.Body = b
	return nil
}
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
}
714165
func DefaultJSONEncoder() runtime.Encoder {
	return unstructured.JSONFallbackEncoder{Encoder: Codecs.LegacyCodec(Scheme.PrioritizedVersionsAllGroups()...)}
}
1172025
func NewEncoder(w io.Writer) *Encoder {
	return &Encoder{w: w, enc: json.NewEncoder(w)}
}