MCPcopy Create free account
hub / github.com/tendermint/tendermint / encodeReflectInterface

Function encodeReflectInterface

libs/json/encoder.go:215–238  ·  view source on GitHub ↗
(w io.Writer, rv reflect.Value)

Source from the content-addressed store, hash-verified

213}
214
215func encodeReflectInterface(w io.Writer, rv reflect.Value) error {
216 // Get concrete value and dereference pointers.
217 for rv.Kind() == reflect.Ptr || rv.Kind() == reflect.Interface {
218 if rv.IsNil() {
219 return writeStr(w, "null")
220 }
221 rv = rv.Elem()
222 }
223
224 // Look up the name of the concrete type
225 name := typeRegistry.name(rv.Type())
226 if name == "" {
227 return fmt.Errorf("cannot encode unregistered type %v", rv.Type())
228 }
229
230 // Write value wrapped in interface envelope
231 if err := writeStr(w, fmt.Sprintf(`{"type":%q,"value":`, name)); err != nil {
232 return err
233 }
234 if err := encodeReflect(w, rv); err != nil {
235 return err
236 }
237 return writeStr(w, "}")
238}
239
240func encodeStdlib(w io.Writer, v interface{}) error {
241 // Doesn't stream the output because that adds a newline, as per:

Callers 2

encodeFunction · 0.85
encodeReflectFunction · 0.85

Calls 4

writeStrFunction · 0.85
encodeReflectFunction · 0.85
nameMethod · 0.80
TypeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…