()
| 541 | } |
| 542 | |
| 543 | public uint ReadVarUInt32() |
| 544 | { |
| 545 | byte[] storage = _storage; |
| 546 | int cursor = _cursor; |
| 547 | int length = _length; |
| 548 | if (cursor >= length) |
| 549 | { |
| 550 | throw new OutOfBoundsException(cursor, 1, length); |
| 551 | } |
| 552 | |
| 553 | byte first = storage[cursor]; |
| 554 | if ((first & 0x80) == 0) |
| 555 | { |
| 556 | _cursor = cursor + 1; |
| 557 | return first; |
| 558 | } |
| 559 | |
| 560 | cursor += 1; |
| 561 | uint result = (uint)(first & 0x7F); |
| 562 | int shift = 7; |
| 563 | while (true) |
| 564 | { |
| 565 | if (cursor >= length) |
| 566 | { |
| 567 | throw new OutOfBoundsException(cursor, 1, length); |
| 568 | } |
| 569 | |
| 570 | byte b = storage[cursor]; |
| 571 | cursor += 1; |
| 572 | result |= (uint)(b & 0x7F) << shift; |
| 573 | if ((b & 0x80) == 0) |
| 574 | { |
| 575 | _cursor = cursor; |
| 576 | return result; |
| 577 | } |
| 578 | |
| 579 | shift += 7; |
| 580 | if (shift > 28) |
| 581 | { |
| 582 | throw new EncodingException("varuint32 overflow"); |
| 583 | } |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | public ulong ReadVarUInt64() |
| 588 | { |
no outgoing calls