Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[从命令行解析bytes] #golang
// support "\x1a \xdf" "\x1a\xdf" "1a, df" "1a df"
func parseTagToBytes(tagStr string) []byte {
tagStr = strings.Replace(tagStr, ` \x`, " ", -1)
tagStr = strings.Replace(tagStr, `\x`, " ", -1)
tagStr = strings.Replace(tagStr, `, `, " ", -1)
tagStr = strings.TrimSpace(tagStr)
fmt.Println(tagStr)
tagSplit := strings.Split(tagStr, " ")
data := make([]byte, len(tagSplit))
for i := range tagSplit {
bigint := new(big.Int)
bigint.SetString(tagSplit[i], 16)
data[i] = bigint.Bytes()[0]
}
return data
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment