MCPcopy
hub / github.com/tinylib/msgp / rwExtensionBytes

Function rwExtensionBytes

msgp/json_bytes.go:291–339  ·  view source on GitHub ↗
(w jsWriter, msg []byte, scratch []byte, depth int)

Source from the content-addressed store, hash-verified

289}
290
291func rwExtensionBytes(w jsWriter, msg []byte, scratch []byte, depth int) ([]byte, []byte, error) {
292 var err error
293 var et int8
294 et, err = peekExtension(msg)
295 if err != nil {
296 return msg, scratch, err
297 }
298
299 // if it's time.Time
300 if et == TimeExtension || et == MsgTimeExtension {
301 var tm time.Time
302 tm, msg, err = ReadTimeBytes(msg)
303 if err != nil {
304 return msg, scratch, err
305 }
306 bts, err := tm.MarshalJSON()
307 if err != nil {
308 return msg, scratch, err
309 }
310 _, err = w.Write(bts)
311 return msg, scratch, err
312 }
313
314 // if the extension is registered,
315 // use its canonical JSON form
316 if f, ok := extensionReg[et]; ok {
317 e := f()
318 msg, err = ReadExtensionBytes(msg, e)
319 if err != nil {
320 return msg, scratch, err
321 }
322 bts, err := json.Marshal(e)
323 if err != nil {
324 return msg, scratch, err
325 }
326 _, err = w.Write(bts)
327 return msg, scratch, err
328 }
329
330 // otherwise, write `{"type": <num>, "data": "<base64data>"}`
331 r := RawExtension{}
332 r.Type = et
333 msg, err = ReadExtensionBytes(msg, &r)
334 if err != nil {
335 return msg, scratch, err
336 }
337 scratch, err = writeExt(w, r, scratch)
338 return msg, scratch, err
339}
340
341func writeExt(w jsWriter, r RawExtension, scratch []byte) ([]byte, error) {
342 _, err := w.WriteString(`{"type":`)

Callers

nothing calls this directly

Calls 6

peekExtensionFunction · 0.85
ReadTimeBytesFunction · 0.85
ReadExtensionBytesFunction · 0.85
writeExtFunction · 0.85
MarshalJSONMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…