| 271 | } |
| 272 | |
| 273 | func 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 | |
| 318 | func map2Json(src *bufio.Reader, dst io.Writer) { |
| 319 | pb := readByte(src) |