MCPcopy Create free account
hub / github.com/aws/smithy-go / encode

Method encode

document/json/encoder.go:72–108  ·  view source on GitHub ↗
(vp valueProvider, rv reflect.Value, tag serde.Tag)

Source from the content-addressed store, hash-verified

70}
71
72func (e *Encoder) encode(vp valueProvider, rv reflect.Value, tag serde.Tag) error {
73 // Zero values are serialized as null, or skipped if omitEmpty.
74 if serde.IsZeroValue(rv) {
75 if tag.OmitEmpty {
76 return nil
77 }
78 return e.encodeZeroValue(vp, rv)
79 }
80
81 // Handle both pointers and interface conversion into types
82 rv = serde.ValueElem(rv)
83
84 switch rv.Kind() {
85 case reflect.Invalid:
86 if tag.OmitEmpty {
87 return nil
88 }
89 vp.GetValue().Null()
90 return nil
91
92 case reflect.Struct:
93 return e.encodeStruct(vp, rv)
94
95 case reflect.Map:
96 return e.encodeMap(vp, rv)
97
98 case reflect.Slice, reflect.Array:
99 return e.encodeSlice(vp, rv)
100
101 case reflect.Chan, reflect.Func, reflect.UnsafePointer:
102 // skip unsupported types
103 return nil
104
105 default:
106 return e.encodeScalar(vp, rv)
107 }
108}
109
110func (e *Encoder) encodeZeroValue(vp valueProvider, rv reflect.Value) error {
111 switch rv.Kind() {

Callers 4

EncodeMethod · 0.95
encodeStructMethod · 0.95
encodeMapMethod · 0.95
encodeSliceMethod · 0.95

Calls 9

encodeZeroValueMethod · 0.95
encodeStructMethod · 0.95
encodeMapMethod · 0.95
encodeSliceMethod · 0.95
encodeScalarMethod · 0.95
IsZeroValueFunction · 0.92
ValueElemFunction · 0.92
NullMethod · 0.80
GetValueMethod · 0.65

Tested by

no test coverage detected