MCPcopy Create free account
hub / github.com/apache/fory / UnsafePutVarUint64

Method UnsafePutVarUint64

go/fory/buffer.go:790–905  ·  view source on GitHub ↗

UnsafePutVarUint64 writes an unsigned VarUint64 at the given offset without advancing writerIndex. Caller must have called Reserve(16) to ensure capacity (for bulk writes). Returns the number of bytes written (1-9).

(offset int, value uint64)

Source from the content-addressed store, hash-verified

788// Caller must have called Reserve(16) to ensure capacity (for bulk writes).
789// Returns the number of bytes written (1-9).
790func (b *ByteBuffer) UnsafePutVarUint64(offset int, value uint64) int {
791 if value>>7 == 0 {
792 b.data[offset] = byte(value)
793 return 1
794 }
795 if value>>14 == 0 {
796 encoded := uint16((value&0x7F)|0x80) | uint16(value>>7)<<8
797 if isLittleEndian {
798 *(*uint16)(unsafe.Pointer(&b.data[offset])) = encoded
799 } else {
800 b.data[offset] = byte(encoded)
801 b.data[offset+1] = byte(encoded >> 8)
802 }
803 return 2
804 }
805 if value>>21 == 0 {
806 encoded := uint32((value&0x7F)|0x80) |
807 uint32(((value>>7)&0x7F)|0x80)<<8 |
808 uint32(value>>14)<<16
809 if isLittleEndian {
810 *(*uint32)(unsafe.Pointer(&b.data[offset])) = encoded
811 } else {
812 b.data[offset] = byte(encoded)
813 b.data[offset+1] = byte(encoded >> 8)
814 b.data[offset+2] = byte(encoded >> 16)
815 }
816 return 3
817 }
818 if value>>28 == 0 {
819 encoded := uint32((value&0x7F)|0x80) |
820 uint32(((value>>7)&0x7F)|0x80)<<8 |
821 uint32(((value>>14)&0x7F)|0x80)<<16 |
822 uint32(value>>21)<<24
823 if isLittleEndian {
824 *(*uint32)(unsafe.Pointer(&b.data[offset])) = encoded
825 } else {
826 binary.LittleEndian.PutUint32(b.data[offset:], encoded)
827 }
828 return 4
829 }
830 if value>>35 == 0 {
831 encoded := uint64((value&0x7F)|0x80) |
832 uint64(((value>>7)&0x7F)|0x80)<<8 |
833 uint64(((value>>14)&0x7F)|0x80)<<16 |
834 uint64(((value>>21)&0x7F)|0x80)<<24 |
835 uint64(value>>28)<<32
836 if isLittleEndian {
837 *(*uint64)(unsafe.Pointer(&b.data[offset])) = encoded
838 } else {
839 binary.LittleEndian.PutUint64(b.data[offset:], encoded)
840 }
841 return 5
842 }
843 if value>>42 == 0 {
844 encoded := uint64((value&0x7F)|0x80) |
845 uint64(((value>>7)&0x7F)|0x80)<<8 |
846 uint64(((value>>14)&0x7F)|0x80)<<16 |
847 uint64(((value>>21)&0x7F)|0x80)<<24 |

Callers 2

UnsafePutVarInt64Method · 0.95
WriteDataMethod · 0.80

Calls 3

uint16Function · 0.50
uint32Function · 0.50
uint64Function · 0.50

Tested by

no test coverage detected