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

Method WriteTaggedUint64

go/fory/buffer.go:1118–1132  ·  view source on GitHub ↗

WriteTaggedUint64 writes uint64 using tagged encoding. If value is in [0, 0x7fffffff], encode as 4 bytes: ((value as u32) << 1). Otherwise write as 9 bytes: 0b1 | little-endian 8 bytes u64.

(value uint64)

Source from the content-addressed store, hash-verified

1116// If value is in [0, 0x7fffffff], encode as 4 bytes: ((value as u32) << 1).
1117// Otherwise write as 9 bytes: 0b1 | little-endian 8 bytes u64.
1118func (b *ByteBuffer) WriteTaggedUint64(value uint64) {
1119 const maxSmallValue uint64 = 0x7fffffff // INT32_MAX as u64
1120 if value <= maxSmallValue {
1121 b.WriteInt32(int32(value) << 1)
1122 } else {
1123 b.grow(9)
1124 b.data[b.writerIndex] = 0b1
1125 if isLittleEndian {
1126 *(*uint64)(unsafe.Pointer(&b.data[b.writerIndex+1])) = value
1127 } else {
1128 binary.LittleEndian.PutUint64(b.data[b.writerIndex+1:], value)
1129 }
1130 b.writerIndex += 9
1131 }
1132}
1133
1134// ReadTaggedUint64 reads uint64 using tagged encoding.
1135// If bit 0 is 0, return value >> 1.

Callers 6

WriteDataMethod · 0.80
writeRemainingFieldMethod · 0.80
writeOptionFastFunction · 0.80
writeUint64ListValuesFunction · 0.80

Calls 3

WriteInt32Method · 0.95
growMethod · 0.95
int32Function · 0.50

Tested by 1