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

Method marshalTo

runtime/marshal_jsonpb.go:40–65  ·  view source on GitHub ↗
(w io.Writer, v interface{})

Source from the content-addressed store, hash-verified

38}
39
40func (j *JSONPb) marshalTo(w io.Writer, v interface{}) error {
41 p, ok := v.(proto.Message)
42 if !ok {
43 buf, err := j.marshalNonProtoField(v)
44 if err != nil {
45 return err
46 }
47 if j.Indent != "" {
48 b := &bytes.Buffer{}
49 if err := json.Indent(b, buf, "", j.Indent); err != nil {
50 return err
51 }
52 buf = b.Bytes()
53 }
54 _, err = w.Write(buf)
55 return err
56 }
57
58 b, err := j.MarshalOptions.Marshal(p)
59 if err != nil {
60 return err
61 }
62
63 _, err = w.Write(b)
64 return err
65}
66
67var (
68 // protoMessageType is stored to prevent constant lookup of the same type at runtime.

Callers 3

MarshalMethod · 0.95
marshalNonProtoFieldMethod · 0.95
NewEncoderMethod · 0.95

Calls 2

marshalNonProtoFieldMethod · 0.95
MarshalMethod · 0.65

Tested by

no test coverage detected