refactor(deps): replace github.com/golang/protobuf with google.golang.org/protobuf

This commit is contained in:
hax0r31337 2023-08-10 04:43:34 +00:00 committed by yuhan6665
parent e584b71b60
commit f67167bb3b
37 changed files with 63 additions and 46 deletions

View file

@ -6,10 +6,10 @@ import (
"strconv"
"strings"
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/app/router"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/platform/filesystem"
"google.golang.org/protobuf/proto"
)
type RouterRulesConfig struct {
@ -245,6 +245,23 @@ func loadSite(file, code string) ([]*router.Domain, error) {
return SiteCache[index].Domain, nil
}
func DecodeVarint(buf []byte) (x uint64, n int) {
for shift := uint(0); shift < 64; shift += 7 {
if n >= len(buf) {
return 0, 0
}
b := uint64(buf[n])
n++
x |= (b & 0x7F) << shift
if (b & 0x80) == 0 {
return x, n
}
}
// The number is too large to represent in a 64-bit value.
return 0, 0
}
func find(data, code []byte) []byte {
codeL := len(code)
if codeL == 0 {
@ -255,7 +272,7 @@ func find(data, code []byte) []byte {
if dataL < 2 {
return nil
}
x, y := proto.DecodeVarint(data[1:])
x, y := DecodeVarint(data[1:])
if x == 0 && y == 0 {
return nil
}