ReadJSONNumberBytes tries to read a number from 'b' and return the value and the remaining bytes. Possible errors: - [ErrShortBytes] (too few bytes) - TypeError (not a number (int/float))
(b []byte)
| 1388 | // - [ErrShortBytes] (too few bytes) |
| 1389 | // - TypeError (not a number (int/float)) |
| 1390 | func ReadJSONNumberBytes(b []byte) (number json.Number, o []byte, err error) { |
| 1391 | if len(b) < 1 { |
| 1392 | return "", nil, ErrShortBytes |
| 1393 | } |
| 1394 | if i, o, err := ReadInt64Bytes(b); err == nil { |
| 1395 | return json.Number(strconv.FormatInt(i, 10)), o, nil |
| 1396 | } |
| 1397 | f, o, err := ReadFloat64Bytes(b) |
| 1398 | if err == nil { |
| 1399 | return json.Number(strconv.FormatFloat(f, 'f', -1, 64)), o, nil |
| 1400 | } |
| 1401 | return "", nil, TypeError{Method: NumberType, Encoded: getType(b[0])} |
| 1402 | } |
searching dependent graphs…