MCPcopy
hub / github.com/grpc-ecosystem/grpc-gateway / NewEncoder

Method NewEncoder

runtime/marshal_jsonpb.go:193–203  ·  view source on GitHub ↗

NewEncoder returns an Encoder which writes JSON stream into "w".

(w io.Writer)

Source from the content-addressed store, hash-verified

191
192// NewEncoder returns an Encoder which writes JSON stream into "w".
193func (j *JSONPb) NewEncoder(w io.Writer) Encoder {
194 return EncoderFunc(func(v interface{}) error {
195 if err := j.marshalTo(w, v); err != nil {
196 return err
197 }
198 // mimic json.Encoder by adding a newline (makes output
199 // easier to read when it contains multiple encoded items)
200 _, err := w.Write(j.Delimiter())
201 return err
202 })
203}
204
205func unmarshalJSONPb(data []byte, unmarshaler protojson.UnmarshalOptions, v interface{}) error {
206 d := json.NewDecoder(bytes.NewReader(data))

Callers 2

TestJSONPbEncoderFunction · 0.95
TestJSONPbEncoderFieldsFunction · 0.95

Calls 3

marshalToMethod · 0.95
DelimiterMethod · 0.95
EncoderFuncFuncType · 0.85

Tested by 2

TestJSONPbEncoderFunction · 0.76
TestJSONPbEncoderFieldsFunction · 0.76