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)
| 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. |
| 1064 | func (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). |