MCPcopy
hub / github.com/uber-go/zap / encodeReflected

Method encodeReflected

zapcore/json_encoder.go:167–177  ·  view source on GitHub ↗

Only invoke the standard JSON encoder if there is actually something to encode; otherwise write JSON null literal directly.

(obj interface{})

Source from the content-addressed store, hash-verified

165// Only invoke the standard JSON encoder if there is actually something to
166// encode; otherwise write JSON null literal directly.
167func (enc *jsonEncoder) encodeReflected(obj interface{}) ([]byte, error) {
168 if obj == nil {
169 return nullLiteralBytes, nil
170 }
171 enc.resetReflectBuf()
172 if err := enc.reflectEnc.Encode(obj); err != nil {
173 return nil, err
174 }
175 enc.reflectBuf.TrimNewline()
176 return enc.reflectBuf.Bytes(), nil
177}
178
179func (enc *jsonEncoder) AddReflected(key string, obj interface{}) error {
180 valueBytes, err := enc.encodeReflected(obj)

Callers 2

AddReflectedMethod · 0.95
AppendReflectedMethod · 0.95

Calls 4

resetReflectBufMethod · 0.95
TrimNewlineMethod · 0.80
BytesMethod · 0.80
EncodeMethod · 0.65

Tested by

no test coverage detected