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

Method WriteTaggedInt64

go/fory/buffer.go:1064–1079  ·  view source on GitHub ↗

WriteTaggedInt64 writes int64 using tagged encoding. If value is in [-1073741824, 1073741823], encode as 4 bytes: ((value as i32) << 1). Otherwise write as 9 bytes: 0b1 | little-endian 8 bytes i64.

(value int64)

Source from the content-addressed store, hash-verified

1062// If value is in [-1073741824, 1073741823], encode as 4 bytes: ((value as i32) << 1).
1063// Otherwise write as 9 bytes: 0b1 | little-endian 8 bytes i64.
1064func (b *ByteBuffer) WriteTaggedInt64(value int64) {
1065 const halfMinIntValue int64 = -1073741824 // INT32_MIN / 2
1066 const halfMaxIntValue int64 = 1073741823 // INT32_MAX / 2
1067 if value >= halfMinIntValue && value <= halfMaxIntValue {
1068 b.WriteInt32(int32(value) << 1)
1069 } else {
1070 b.grow(9)
1071 b.data[b.writerIndex] = 0b1
1072 if isLittleEndian {
1073 *(*int64)(unsafe.Pointer(&b.data[b.writerIndex+1])) = value
1074 } else {
1075 binary.LittleEndian.PutUint64(b.data[b.writerIndex+1:], uint64(value))
1076 }
1077 b.writerIndex += 9
1078 }
1079}
1080
1081// ReadTaggedInt64 reads int64 using tagged encoding.
1082// If bit 0 is 0, return value >> 1 (arithmetic shift).

Callers 6

WriteDataMethod · 0.45
writeRemainingFieldMethod · 0.45
writeOptionFastFunction · 0.45
writeInt64ListValuesFunction · 0.45

Calls 4

WriteInt32Method · 0.95
growMethod · 0.95
int32Function · 0.50
uint64Function · 0.50

Tested by 1