add MarshalJSON function to implement the interface MarshalJSON for json.Marshal for gtype

This commit is contained in:
John
2019-09-29 15:59:09 +08:00
parent b830f9b96d
commit 47e74d27bf
21 changed files with 342 additions and 20 deletions

View File

@ -9,6 +9,7 @@ package gbase64
import (
"encoding/base64"
"github.com/gogf/gf/util/gconv"
)
// Encode encodes bytes with BASE64 algorithm.
@ -32,7 +33,7 @@ func EncodeString(src string) string {
// EncodeToString encodes bytes to string with BASE64 algorithm.
func EncodeToString(src []byte) string {
return string(Encode(src))
return gconv.UnsafeBytesToStr(Encode(src))
}
// DecodeString decodes string with BASE64 algorithm.
@ -43,5 +44,5 @@ func DecodeString(str string) ([]byte, error) {
// DecodeString decodes string with BASE64 algorithm.
func DecodeToString(str string) (string, error) {
b, err := DecodeString(str)
return string(b), err
return gconv.UnsafeBytesToStr(b), err
}

View File

@ -135,7 +135,7 @@ func LeEncodeInt8(i int8) []byte {
}
func LeEncodeUint8(i uint8) []byte {
return []byte{byte(i)}
return []byte{i}
}
func LeEncodeInt16(i int16) []byte {