mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 08:32:40 +08:00
更新库
This commit is contained in:
@ -9,6 +9,14 @@ const hexTable = "0123456789ABCDEF"
|
||||
|
||||
type BytesResult []byte
|
||||
|
||||
func FromString(s string) BytesResult {
|
||||
return (BytesResult)([]byte(s))
|
||||
}
|
||||
|
||||
func FromBytes(b []byte) BytesResult {
|
||||
return BytesResult(b)
|
||||
}
|
||||
|
||||
// FromHexString 从十六进制获取
|
||||
func FromHexString(s string) (BytesResult, error) {
|
||||
b, err := hex.DecodeString(s)
|
||||
|
@ -5,6 +5,8 @@ import (
|
||||
|
||||
"github.com/charlienet/go-mixed/bytesconv"
|
||||
"github.com/charlienet/go-mixed/rand"
|
||||
"golang.org/x/net/html/charset"
|
||||
"golang.org/x/text/encoding/unicode"
|
||||
)
|
||||
|
||||
func TestHexUppercase(t *testing.T) {
|
||||
@ -16,3 +18,20 @@ func TestHexUppercase(t *testing.T) {
|
||||
u := bytesconv.BytesResult(b).UppercaseHex()
|
||||
t.Log(u)
|
||||
}
|
||||
|
||||
func TestHexToBase64(t *testing.T) {
|
||||
v := "abc"
|
||||
|
||||
unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM)
|
||||
|
||||
t.Log(bytesconv.FromString(v).Base64())
|
||||
|
||||
b, _ := rand.RandBytes(43)
|
||||
t.Log(bytesconv.FromBytes(b).Base64())
|
||||
|
||||
c, n := charset.Lookup("utf8")
|
||||
|
||||
|
||||
t.Log(c, n)
|
||||
|
||||
}
|
||||
|
13
bytesconv/readme.md
Normal file
13
bytesconv/readme.md
Normal file
@ -0,0 +1,13 @@
|
||||
功能列表
|
||||
|
||||
1. 无内存消耗的字符串转字节数组,字节数组转字符串
|
||||
StringToBytes、BytesToString
|
||||
|
||||
2. 字节数组转换函数
|
||||
ByteResult
|
||||
From
|
||||
To
|
||||
|
||||
3. 对象的二进制序列化和反序列化
|
||||
Encode、Decode
|
||||
|
Reference in New Issue
Block a user