MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / encode

Function encode

libs/json/encoder.go:45–61  ·  view source on GitHub ↗
(w io.Writer, v interface{})

Source from the content-addressed store, hash-verified

43}
44
45func encode(w io.Writer, v interface{}) error {
46 // Bare nil values can't be reflected, so we must handle them here.
47 if v == nil {
48 return writeStr(w, "null")
49 }
50 rv := reflect.ValueOf(v)
51
52 // If this is a registered type, defer to interface encoder regardless of whether the input is
53 // an interface or a bare value. This retains Amino's behavior, but is inconsistent with
54 // behavior in structs where an interface field will get the type wrapper while a bare value
55 // field will not.
56 if typeRegistry.name(rv.Type()) != "" {
57 return encodeReflectInterface(w, rv)
58 }
59
60 return encodeReflect(w, rv)
61}
62
63func encodeReflect(w io.Writer, rv reflect.Value) error {
64 if !rv.IsValid() {

Callers 1

MarshalFunction · 0.85

Calls 5

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

Tested by

no test coverage detected