Documentation
¶
Overview ¶
Package encoding 提供围绕 encoding.TextMarshaler 和 encoding.TextUnmarshaler 的通用文本编解码辅助。
常见入口:
- 用 MarshalText 统一把常见标量、[]byte 或实现了 encoding.TextMarshaler 的值编码为文本。
- 用 UnmarshalText 把文本解码回目标值,支持指针和 reflect.Value。
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MarshalText ¶
MarshalText 将常见标量、[]byte 或实现 encoding.TextMarshaler 的值编码为文本。
Example ¶
package main
import (
"fmt"
"github.com/octohelm/x/encoding"
)
func main() {
data, err := encoding.MarshalText([]byte("hi"))
if err != nil {
panic(err)
}
fmt.Println(string(data))
}
Output: aGk=
func UnmarshalText ¶
UnmarshalText 将文本解码到目标值,支持指针、reflect.Value 和 encoding.TextUnmarshaler。
Example ¶
package main
import (
"fmt"
"github.com/octohelm/x/encoding"
)
func main() {
var text string
if err := encoding.UnmarshalText(&text, []byte("hello")); err != nil {
panic(err)
}
fmt.Println(text)
}
Output: hello
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.