ReadInt64Bytes tries to read an int64 from 'b' and return the value and the remaining bytes. Possible errors: - [ErrShortBytes] (too few bytes) - [TypeError] (not a int)
(b []byte)
| 422 | // - [ErrShortBytes] (too few bytes) |
| 423 | // - [TypeError] (not a int) |
| 424 | func ReadInt64Bytes(b []byte) (i int64, o []byte, err error) { |
| 425 | if len(b) < 1 { |
| 426 | return 0, nil, ErrShortBytes |
| 427 | } |
| 428 | |
| 429 | lead := b[0] |
| 430 | b = b[1:] |
| 431 | if isfixint(lead) { |
| 432 | i = int64(rfixint(lead)) |
| 433 | o = b |
| 434 | return |
| 435 | } |
| 436 | if isnfixint(lead) { |
| 437 | i = int64(rnfixint(lead)) |
| 438 | o = b |
| 439 | return |
| 440 | } |
| 441 | |
| 442 | switch lead { |
| 443 | case mint8: |
| 444 | if len(b) < 1 { |
| 445 | err = ErrShortBytes |
| 446 | return |
| 447 | } |
| 448 | i = int64(int8(b[0])) |
| 449 | o = b[1:] |
| 450 | return |
| 451 | |
| 452 | case muint8: |
| 453 | if len(b) < 1 { |
| 454 | err = ErrShortBytes |
| 455 | return |
| 456 | } |
| 457 | i = int64(b[0]) |
| 458 | o = b[1:] |
| 459 | return |
| 460 | |
| 461 | case mint16: |
| 462 | if len(b) < 2 { |
| 463 | err = ErrShortBytes |
| 464 | return |
| 465 | } |
| 466 | i = int64(int16(big.Uint16(b))) |
| 467 | o = b[2:] |
| 468 | return |
| 469 | |
| 470 | case muint16: |
| 471 | if len(b) < 2 { |
| 472 | err = ErrShortBytes |
| 473 | return |
| 474 | } |
| 475 | i = int64(big.Uint16(b)) |
| 476 | o = b[2:] |
| 477 | return |
| 478 | |
| 479 | case mint32: |
| 480 | if len(b) < 4 { |
| 481 | err = ErrShortBytes |
searching dependent graphs…