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

Function array2Json

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

Source from the content-addressed store, hash-verified

271}
272
273func array2Json(src *bufio.Reader, dst io.Writer) {
274 dst.Write([]byte{'['})
275 pb := readByte(src)
276 major := pb & maskOutAdditionalType
277 minor := pb & maskOutMajorType
278 if major != majorTypeArray {
279 panic(fmt.Errorf("Major type is: %d in array2Json", major))
280 }
281 len := 0
282 unSpecifiedCount := false
283 if minor == additionalTypeInfiniteCount {
284 unSpecifiedCount = true
285 } else {
286 length := decodeIntAdditionalType(src, minor)
287 len = int(length)
288 }
289 for i := 0; unSpecifiedCount || i < len; i++ {
290 if unSpecifiedCount {
291 pb, e := src.Peek(1)
292 if e != nil {
293 panic(e)
294 }
295 if pb[0] == majorTypeSimpleAndFloat|additionalTypeBreak {
296 readByte(src)
297 break
298 }
299 }
300 cbor2JsonOneObject(src, dst)
301 if unSpecifiedCount {
302 pb, e := src.Peek(1)
303 if e != nil {
304 panic(e)
305 }
306 if pb[0] == majorTypeSimpleAndFloat|additionalTypeBreak {
307 readByte(src)
308 break
309 }
310 dst.Write([]byte{','})
311 } else if i+1 < len {
312 dst.Write([]byte{','})
313 }
314 }
315 dst.Write([]byte{']'})
316}
317
318func map2Json(src *bufio.Reader, dst io.Writer) {
319 pb := readByte(src)

Callers 2

cbor2JsonOneObjectFunction · 0.85
TestDecodeArrayFunction · 0.85

Calls 4

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

Tested by 1

TestDecodeArrayFunction · 0.68