1
0
mirror of https://github.com/fumiama/unibase2n.git synced 2026-06-20 10:20:24 +08:00

finish decode

This commit is contained in:
源文雨
2022-10-01 20:37:33 +08:00
parent aff58aa75e
commit 4cf8ba580a
4 changed files with 347 additions and 13 deletions

10
base.go
View File

@@ -2,6 +2,7 @@ package unibase2n
import (
"errors"
"math/bits"
)
// Base has an encoding buffer thus should not be copied.
@@ -46,11 +47,14 @@ func (bs Base) check() error {
if offe > 0x10000 {
return ErrOffsetOverflow
}
if bits.OnesCount8(bit) == 1 { // 2的幂永无offset, 无需管til (1/2/4/8)
return nil
}
tile := uint32(til) // [til, tile)
if bit > 8 && bit%2 == 0 {
tile += uint32(bit / 2)
if bit > 4 && bit%2 == 0 {
tile += uint32(bit / 2) // 6 10 12 14
} else {
tile += uint32(bit)
tile += uint32(bit) // 3 5 7 9 11 13 15
}
if tile > 0x10000 {
return ErrTailOverflow