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