UnsafePutVarUint32 writes an unsigned VarUint32 at the given offset without advancing writerIndex. Caller must have called Reserve(8) to ensure capacity (8 for bulk uint64 write). Returns the number of bytes written (1-5).
(offset int, value uint32)
| 724 | // Caller must have called Reserve(8) to ensure capacity (8 for bulk uint64 write). |
| 725 | // Returns the number of bytes written (1-5). |
| 726 | func (b *ByteBuffer) UnsafePutVarUint32(offset int, value uint32) int { |
| 727 | if value>>7 == 0 { |
| 728 | b.data[offset] = byte(value) |
| 729 | return 1 |
| 730 | } |
| 731 | if value>>14 == 0 { |
| 732 | encoded := uint16((value&0x7F)|0x80) | uint16(value>>7)<<8 |
| 733 | if isLittleEndian { |
| 734 | *(*uint16)(unsafe.Pointer(&b.data[offset])) = encoded |
| 735 | } else { |
| 736 | b.data[offset] = byte(encoded) |
| 737 | b.data[offset+1] = byte(encoded >> 8) |
| 738 | } |
| 739 | return 2 |
| 740 | } |
| 741 | if value>>21 == 0 { |
| 742 | encoded := uint32((value&0x7F)|0x80) | |
| 743 | uint32(((value>>7)&0x7F)|0x80)<<8 | |
| 744 | uint32(value>>14)<<16 |
| 745 | if isLittleEndian { |
| 746 | *(*uint32)(unsafe.Pointer(&b.data[offset])) = encoded |
| 747 | } else { |
| 748 | b.data[offset] = byte(encoded) |
| 749 | b.data[offset+1] = byte(encoded >> 8) |
| 750 | b.data[offset+2] = byte(encoded >> 16) |
| 751 | } |
| 752 | return 3 |
| 753 | } |
| 754 | if value>>28 == 0 { |
| 755 | encoded := uint32((value&0x7F)|0x80) | |
| 756 | uint32(((value>>7)&0x7F)|0x80)<<8 | |
| 757 | uint32(((value>>14)&0x7F)|0x80)<<16 | |
| 758 | uint32(value>>21)<<24 |
| 759 | if isLittleEndian { |
| 760 | *(*uint32)(unsafe.Pointer(&b.data[offset])) = encoded |
| 761 | } else { |
| 762 | binary.LittleEndian.PutUint32(b.data[offset:], encoded) |
| 763 | } |
| 764 | return 4 |
| 765 | } |
| 766 | encoded := uint64((value&0x7F)|0x80) | |
| 767 | uint64(((value>>7)&0x7F)|0x80)<<8 | |
| 768 | uint64(((value>>14)&0x7F)|0x80)<<16 | |
| 769 | uint64(((value>>21)&0x7F)|0x80)<<24 | |
| 770 | uint64(value>>28)<<32 |
| 771 | if isLittleEndian { |
| 772 | *(*uint64)(unsafe.Pointer(&b.data[offset])) = encoded |
| 773 | } else { |
| 774 | binary.LittleEndian.PutUint64(b.data[offset:], encoded) |
| 775 | } |
| 776 | return 5 |
| 777 | } |
| 778 | |
| 779 | // UnsafePutVarInt64 writes a zigzag-encoded varint64 at the given offset without advancing writerIndex. |
| 780 | // Caller must have called Reserve() to ensure capacity. |