MCPcopy Create free account
hub / github.com/segmentio/encoding / Append

Function Append

json/json.go:196–216  ·  view source on GitHub ↗

Append acts like Marshal but appends the json representation to b instead of always reallocating a new slice.

(b []byte, x any, flags AppendFlags)

Source from the content-addressed store, hash-verified

194// Append acts like Marshal but appends the json representation to b instead of
195// always reallocating a new slice.
196func Append(b []byte, x any, flags AppendFlags) ([]byte, error) {
197 if x == nil {
198 // Special case for nil values because it makes the rest of the code
199 // simpler to assume that it won't be seeing nil pointers.
200 return append(b, "null"...), nil
201 }
202
203 t := reflect.TypeOf(x)
204 p := (*iface)(unsafe.Pointer(&x)).ptr
205
206 cache := cacheLoad()
207 c, found := cache[typeid(t)]
208
209 if !found {
210 c = constructCachedCodec(t, cache)
211 }
212
213 b, err := c.encode(encoder{flags: flags}, b, p)
214 runtime.KeepAlive(x)
215 return b, err
216}
217
218// Escape is a convenience helper to construct an escaped JSON string from s.
219// The function escales HTML characters, for more control over the escape

Callers 6

encodeInterfaceMethod · 0.70
TestMainFunction · 0.70
MarshalFunction · 0.70
EncodeMethod · 0.70

Calls 4

cacheLoadFunction · 0.85
typeidFunction · 0.85
constructCachedCodecFunction · 0.85
encodeMethod · 0.80

Tested by 1

TestMainFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…