encoding

package
v0.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MIME类型
	MIMEJSON              = "application/json"
	MIMEHTML              = "text/html"
	MIMEXML               = "application/xml"
	MIMEXML2              = "text/xml"
	MIMEPlain             = "text/plain"
	MIMEPOSTForm          = "application/x-www-form-urlencoded"
	MIMEMultipartPOSTForm = "multipart/form-data"
	MIMEPROTOBUF          = "application/x-protobuf"
	MIMEYAML              = "application/x-yaml"
	MIMEYAML2             = "text/yaml"
	MIMETOML              = "application/toml"
	MIMETOML2             = "text/toml"
	MIMEMSGPACK           = "application/msgpack"
	MIMEMSGPACK2          = "application/x-msgpack"
	MIMECBOR              = "application/cbor"
	MIMECBOR2             = "application/x-cbor"
	MIMEBSON              = "application/bson"
)

常见的内容类型常量

Variables

This section is empty.

Functions

func Clone

func Clone(src interface{}) interface{}

Clone 克隆一个对象

func CopyReader

func CopyReader(reader io.Reader, writers ...io.Writer) error

CopyReader 将reader内容复制到多个writers

func DeepCopy

func DeepCopy(src, dst interface{}) error

DeepCopy 使用gob编码进行深拷贝

func MarshalBson

func MarshalBson(v interface{}) ([]byte, error)

MarshalBson 将对象序列化为BSON字节数组

func MarshalCbor

func MarshalCbor(v interface{}) ([]byte, error)

MarshalCbor 将对象序列化为CBOR字节数组

func MarshalJSON

func MarshalJSON(v interface{}) ([]byte, error)

MarshalJSON 将对象序列化为JSON字节数组

func MarshalMsgPack

func MarshalMsgPack(v interface{}) ([]byte, error)

MarshalMsgPack 将对象序列化为MessagePack字节数组

func MarshalProto

func MarshalProto(v interface{}) ([]byte, error)

MarshalProto 将对象序列化为Proto字节数组

func MarshalToString

func MarshalToString(codec Codec, v interface{}) (string, error)

MarshalToString 将对象序列化为字符串

func MarshalToml

func MarshalToml(v interface{}) ([]byte, error)

MarshalToml 将对象序列化为TOML字节数组

func MarshalYAML

func MarshalYAML(v interface{}) ([]byte, error)

MarshalYAML 将对象序列化为YAML字节数组

func RegisterCodec

func RegisterCodec(codec Codec)

RegisterCodec 注册一个编解码器

func UnmarshalBson

func UnmarshalBson(data []byte, v interface{}) error

UnmarshalBson 将BSON字节数组反序列化为对象

func UnmarshalCbor

func UnmarshalCbor(data []byte, v interface{}) error

UnmarshalCbor 将CBOR字节数组反序列化为对象

func UnmarshalFromString

func UnmarshalFromString(codec Codec, data string, v interface{}) error

UnmarshalFromString 从字符串反序列化对象

func UnmarshalJSON

func UnmarshalJSON(data []byte, v interface{}) error

UnmarshalJSON 将JSON字节数组反序列化为对象

func UnmarshalMsgPack

func UnmarshalMsgPack(data []byte, v interface{}) error

UnmarshalMsgPack 将MessagePack字节数组反序列化为对象

func UnmarshalProto

func UnmarshalProto(data []byte, v interface{}) error

UnmarshalProto 将Proto字节数组反序列化为对象

func UnmarshalToml

func UnmarshalToml(data []byte, v interface{}) error

UnmarshalToml 将TOML字节数组反序列化为对象

func UnmarshalYAML

func UnmarshalYAML(data []byte, v interface{}) error

UnmarshalYAML 将YAML字节数组反序列化为对象

Types

type Codec

type Codec interface {
	// Marshal 将对象序列化为字节数组
	Marshal(v interface{}) ([]byte, error)
	// Unmarshal 将字节数组反序列化为对象
	Unmarshal(data []byte, v interface{}) error
	// Name 返回编解码器的名称
	Name() string
}

Codec 定义了编解码器的接口

func GetCodec

func GetCodec(name string) Codec

GetCodec 根据名称获取编解码器

func GetCodecForContentType

func GetCodecForContentType(contentType string) Codec

GetCodecForContentType 根据内容类型获取相应的编解码器

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL