MCPcopy
hub / github.com/rs/zerolog / map2Json

Function map2Json

internal/cbor/decode_stream.go:318–366  ·  view source on GitHub ↗
(src *bufio.Reader, dst io.Writer)

Source from the content-addressed store, hash-verified

316}
317
318func map2Json(src *bufio.Reader, dst io.Writer) {
319 pb := readByte(src)
320 major := pb & maskOutAdditionalType
321 minor := pb & maskOutMajorType
322 if major != majorTypeMap {
323 panic(fmt.Errorf("Major type is: %d in map2Json", major))
324 }
325 len := 0
326 unSpecifiedCount := false
327 if minor == additionalTypeInfiniteCount {
328 unSpecifiedCount = true
329 } else {
330 length := decodeIntAdditionalType(src, minor)
331 len = int(length)
332 }
333 dst.Write([]byte{'{'})
334 for i := 0; unSpecifiedCount || i < len; i++ {
335 if unSpecifiedCount {
336 pb, e := src.Peek(1)
337 if e != nil {
338 panic(e)
339 }
340 if pb[0] == majorTypeSimpleAndFloat|additionalTypeBreak {
341 readByte(src)
342 break
343 }
344 }
345 cbor2JsonOneObject(src, dst)
346 if i%2 == 0 {
347 // Even position values are keys.
348 dst.Write([]byte{':'})
349 } else {
350 if unSpecifiedCount {
351 pb, e := src.Peek(1)
352 if e != nil {
353 panic(e)
354 }
355 if pb[0] == majorTypeSimpleAndFloat|additionalTypeBreak {
356 readByte(src)
357 break
358 }
359 dst.Write([]byte{','})
360 } else if i+1 < len {
361 dst.Write([]byte{','})
362 }
363 }
364 }
365 dst.Write([]byte{'}'})
366}
367
368func decodeTagData(src *bufio.Reader) []byte {
369 pb := readByte(src)

Callers 2

cbor2JsonOneObjectFunction · 0.85
TestDecodeMapFunction · 0.85

Calls 4

readByteFunction · 0.85
decodeIntAdditionalTypeFunction · 0.85
cbor2JsonOneObjectFunction · 0.85
WriteMethod · 0.45

Tested by 1

TestDecodeMapFunction · 0.68