cbor
CBOR(Concise Binary Object Representation)是一种轻量级的数据交换格式,类似于JSON,但它以二进制形式表示数据,而不是文本形式。CBOR设计用于在网络上传输数据时减少数据的大小和复杂性,同时保持良好的可读性和可扩展性。
package main
import (
"encoding/hex"
"fmt"
"github.com/fxamacker/cbor/v2"
)
func main() {
b, _ := cbor.Marshal("hello world")
fmt.Println(hex.EncodeToString(b))
cborBytes, _ := hex.DecodeString(hex.EncodeToString(b))
s := ""
cbor.Unmarshal(cborBytes, &s)
fmt.Printf("%s", s)
}