1
0
mirror of https://github.com/fumiama/go-base16384.git synced 2026-06-10 21:24:39 +08:00

优化 api

This commit is contained in:
fumiama
2021-10-28 14:05:38 +08:00
parent b764251f95
commit 86dc5b5b23
3 changed files with 7 additions and 5 deletions

View File

@@ -3,6 +3,10 @@ base16384 interface of golang
## Functions ## Functions
### func EncodeString(b string) []byte
Encode string b to utf16be.
### func DecodeString(d []byte) string
Decode to string from encoded b.
### func Encode(b []byte) []byte ### func Encode(b []byte) []byte
Encode b to utf16be. Encode b to utf16be.
### func Decode(b []byte) []byte ### func Decode(b []byte) []byte
@@ -11,8 +15,6 @@ Decode from encoded b.
Display the result. Display the result.
### func UTF82utf16be(b []byte) ([]byte, error) ### func UTF82utf16be(b []byte) ([]byte, error)
Turn the result to its original coding form to decode. Turn the result to its original coding form to decode.
### func Free(b []byte)
Free memory allocated by encode / decode.
# Usage # Usage
## As package ## As package

View File

@@ -13,8 +13,8 @@ func EncodeString(s string) []byte {
return Encode(helper.StringToBytes(s)) return Encode(helper.StringToBytes(s))
} }
func DecodeString(s string) []byte { func DecodeString(d []byte) string {
return Decode(helper.StringToBytes(s)) return helper.BytesToString(Decode(d))
} }
func Encode(b []byte) (encd []byte) { func Encode(b []byte) (encd []byte) {

View File

@@ -13,7 +13,7 @@ func TestBase14(t *testing.T) {
d, err := UTF82utf16be(es) d, err := UTF82utf16be(es)
if string(d) == string(e) { if string(d) == string(e) {
if err == nil { if err == nil {
ds := string(Decode(d)) ds := DecodeString(d)
t.Log(ds) t.Log(ds)
if ds != teststr { if ds != teststr {
t.Fail() t.Fail()