forked from apache/cassandra-gocql-driver
-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathmarshal_ints_64bit.go
More file actions
28 lines (26 loc) · 1.03 KB
/
marshal_ints_64bit.go
File metadata and controls
28 lines (26 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//go:build (amd64 || arm64 || ppc64 || ppc64le || mips64 || mips64le || s390x || riscv64 || loong64) && !gocql_32bit
package varint
func encInt(v int) []byte {
if v <= maxInt8 && v >= minInt8 {
return []byte{byte(v)}
}
if v <= maxInt16 && v >= minInt16 {
return []byte{byte(v >> 8), byte(v)}
}
if v <= maxInt24 && v >= minInt24 {
return []byte{byte(v >> 16), byte(v >> 8), byte(v)}
}
if v <= maxInt32 && v >= minInt32 {
return []byte{byte(v >> 24), byte(v >> 16), byte(v >> 8), byte(v)}
}
if v <= maxInt40 && v >= minInt40 {
return []byte{byte(v >> 32), byte(v >> 24), byte(v >> 16), byte(v >> 8), byte(v)}
}
if v <= maxInt48 && v >= minInt48 {
return []byte{byte(v >> 40), byte(v >> 32), byte(v >> 24), byte(v >> 16), byte(v >> 8), byte(v)}
}
if v <= maxInt56 && v >= minInt56 {
return []byte{byte(v >> 48), byte(v >> 40), byte(v >> 32), byte(v >> 24), byte(v >> 16), byte(v >> 8), byte(v)}
}
return []byte{byte(v >> 56), byte(v >> 48), byte(v >> 40), byte(v >> 32), byte(v >> 24), byte(v >> 16), byte(v >> 8), byte(v)}
}