Files
kopia/repo/content/index_encode_util.go
Jarek Kowalski 9e861c9e05 Implemented index v2 builder and parser (#1028)
* content: added GetCompressionHeaderID and GetEncryptionKeyID to content.info

Both must be zero in index v1 but will be non-zero in index v2 to
support in-content compression and key rotation in the future.

* content: cleaned up index v1 code

* content: added index v2 implementation

* content: updated index test to verify that we're able to store all supported values in all Info fields

* content: optimized sorting of content.Info by content ID using bucket sort and parallelization

For 10M contents this reduces sort time from 10s to ~2s

* content: fixed a bunch of off-by-one errors in index v2, added tests

* content: fixed test failures due to increased validation

* content: plumbed through index version (currently hardcoded to v1) in content manager
2021-05-07 09:56:27 -07:00

29 lines
810 B
Go

package content
func decodeBigEndianUint48(d string) int64 {
_ = d[5] // early bounds check
return int64(d[0])<<40 | int64(d[1])<<32 | int64(d[2])<<24 | int64(d[3])<<16 | int64(d[4])<<8 | int64(d[5])
}
func decodeBigEndianUint32(d string) uint32 {
_ = d[3] // early bounds check
return uint32(d[0])<<24 | uint32(d[1])<<16 | uint32(d[2])<<8 | uint32(d[3])
}
func decodeBigEndianUint24(d string) uint32 {
_ = d[2] // early bounds check
return uint32(d[0])<<16 | uint32(d[1])<<8 | uint32(d[2])
}
func decodeBigEndianUint16(d string) uint16 {
_ = d[1] // early bounds check
return uint16(d[0])<<8 | uint16(d[1])
}
func encodeBigEndianUint24(b []byte, v uint32) {
_ = b[2] // early bounds check
b[0] = byte(v >> 16) // nolint:gomnd
b[1] = byte(v >> 8) // nolint:gomnd
b[2] = byte(v)
}