mirror of
https://github.com/tsolomko/SWCompression.git
synced 2026-06-23 14:56:41 +00:00
33 lines
703 B
Swift
33 lines
703 B
Swift
// Copyright (c) 2026 Timofey Solomko
|
|
// Licensed under MIT License
|
|
//
|
|
// See LICENSE for license information
|
|
|
|
import BitByteData
|
|
|
|
extension LittleEndianByteReader {
|
|
|
|
func multiByteDecode() throws -> Int {
|
|
var i = 1
|
|
var result = self.byte().toInt()
|
|
if result <= 127 {
|
|
return result
|
|
}
|
|
result &= 0x7F
|
|
while true {
|
|
let byte = self.byte()
|
|
if i >= 9 || byte == 0x00 {
|
|
throw XZError.multiByteIntegerError
|
|
}
|
|
result += (byte.toInt() & 0x7F) << (7 * i)
|
|
i += 1
|
|
|
|
if byte & 0x80 == 0 {
|
|
break
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
|
|
}
|