-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
修复BV AV转换函数,原代码非64位平台编译错误 #94
base: master
Are you sure you want to change the base?
Conversation
这里有几个很纠结的地方,首先我们很多接口其实没有管32位机的问题,这个要不要考虑上,而且会不会发生breaking changes? 要不改一下 build:
- runs-on: ubuntu-latest
+ runs-on: ${{ matrix.os }}
+
+ strategy:
+ matrix:
+ os: [ubuntu-latest, ubuntu-32bit]
steps: 如果有其它问题的话,其实仅这一个改动意义不大 |
试了一下,Github还不支持32位系统编译。这就很麻烦了,感觉 |
你看,换了几种写法,也难以进行32位机的测试。有办法验证32位机是否能够跑通吗? |
对go不是很熟悉,搞了半天复现不了编译问题,是在引用本repo时发现的,用的goreleaser/goreleaser-action@v6
|
两个问题:
|
misc.go
Outdated
xorCode = 0x1552356C4CDB | ||
maxAid int64 = 1 << 51 | ||
alphabet = "FcwAPNKTMug3GV5Lj7EJnHpWsx4tb8haYeviqBz6rkCy12mUSDQX9RdoZf" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么这个 maxAid
要加 int64
,上面这个 xorCode
不需要加, 0x1552356C4CDB
显然至少要6个字节,也超过了32位机的int
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 5 to 12 in 5e8ece7
func TestAvBv(t *testing.T) { | |
if Av2Bv(111298867365120) != "BV1L9Uoa9EUx" { | |
t.Fail() | |
} | |
if 111298867365120 != Bv2Av("BV1L9Uoa9EUx") { | |
t.Fail() | |
} | |
} |
这个也得改,这传进去的这么大一个整数,在32位机也没法作为int
传入。
618dd72
to
62dbe7b
Compare
看了下gorelease文档:https://goreleaser.com/customization/builds/go/ |
// Bv2Av 将bv号转换为av号,传入的bv号格式为"BV1xxxxxxxxx",前面的"BV"不区分大小写。
func Bv2Av(bvid string) int64 {
if len(bvid) != 12 {
panic("bvid 格式错误: " + bvid)
}
const (
xorCode = 0x1552356C4CDB
maskCode = 1<<51 - 1
alphabet = "FcwAPNKTMug3GV5Lj7EJnHpWsx4tb8haYeviqBz6rkCy12mUSDQX9RdoZf"
)
var tmp = 0
for _, e := range []int{9, 7, 5, 6, 4, 8, 3, 10, 11} {
idx := (strings.IndexByte(alphabet, bvid[e]))
tmp = tmp*(len(alphabet)) + idx
}
return int64((tmp & maskCode) ^ xorCode)
} 这里如果这样改依然会报错:
应该是常量声明声明时自动提升为int64 |
你把函数参数给改了,不就breaking change了吗?如果非要所有函数全支持32位机,建议新增v3版本。 |
更改类型为int64