diff options
author | Runxi Yu <me@runxiyu.org> | 2025-03-23 12:01:36 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-03-23 12:01:36 +0800 |
commit | 71559a48afc860d124b4ddfeb8df752b22a25053 (patch) | |
tree | a163ec0a7c0d811bf39ab8e943ee76a87a95ef41 | |
parent | Reorganize README (diff) | |
download | powxy-71559a48afc860d124b4ddfeb8df752b22a25053.tar.gz powxy-71559a48afc860d124b4ddfeb8df752b22a25053.tar.zst powxy-71559a48afc860d124b4ddfeb8df752b22a25053.zip |
Separate validateBitZeros into a separate file
-rw-r--r-- | bitwise.go | 21 | ||||
-rw-r--r-- | bitwise_test.go (renamed from main_test.go) | 0 | ||||
-rw-r--r-- | main.go | 20 |
3 files changed, 21 insertions, 20 deletions
diff --git a/bitwise.go b/bitwise.go new file mode 100644 index 0000000..b9b6f47 --- /dev/null +++ b/bitwise.go @@ -0,0 +1,21 @@ +package main + +func validateBitZeros(bs []byte, n uint) bool { + q := n / 8 + r := n % 8 + + for i := uint(0); i < q; i++ { + if bs[i] != 0 { + return false + } + } + + if r > 0 { + mask := byte(0xFF << (8 - r)) + if bs[q]&mask != 0 { + return false + } + } + + return true +} diff --git a/main_test.go b/bitwise_test.go index 394d407..394d407 100644 --- a/main_test.go +++ b/bitwise_test.go @@ -197,23 +197,3 @@ func proxyRequest(writer http.ResponseWriter, request *http.Request) { func stringToBytes(s string) (bytes []byte) { return unsafe.Slice(unsafe.StringData(s), len(s)) } - -func validateBitZeros(bs []byte, n uint) bool { - q := n / 8 - r := n % 8 - - for i := uint(0); i < q; i++ { - if bs[i] != 0 { - return false - } - } - - if r > 0 { - mask := byte(0xFF << (8 - r)) - if bs[q]&mask != 0 { - return false - } - } - - return true -} |