encoding

原文:https://pkg.go.dev/encoding@go1.23.0

Package encoding defines interfaces shared by other packages that convert data to and from byte-level and textual representations. Packages that check for these interfaces include encoding/gob, encoding/json, and encoding/xml. As a result, implementing an interface once can make a type useful in multiple encodings. Standard types that implement these interfaces include time.Time and net.IP. The interfaces come in pairs that produce and consume encoded data.

encoding包定义了其他包共享的接口,这些接口用于将数据转换为字节级和文本表示形式,以及将数据从字节级和文本表示形式转换回来。检查这些接口的包括 encoding/gob、encoding/json 和 encoding/xml。因此,实现一次接口可以使一个类型在多种编码中变得有用。实现这些接口的标准类型包括 time.Time 和 net.IP。这些接口成对出现,用于生成和消费编码数据。

常量

This section is empty.

变量

This section is empty.

函数

This section is empty.

类型

type BinaryMarshaler

1
2
3
type BinaryMarshaler interface {
	MarshalBinary() (data []byte, err error)
}

BinaryMarshaler is the interface implemented by an object that can marshal itself into a binary form.

​ BinaryMarshaler 是一个接口,由一个对象实现,该对象可以将自身编组为二进制形式。

MarshalBinary encodes the receiver into a binary form and returns the result.

​ MarshalBinary 将接收者编码为二进制形式,并返回结果。

type BinaryUnmarshaler

1
2
3
type BinaryUnmarshaler interface {
	UnmarshalBinary(data []byte) error
}

BinaryUnmarshaler is the interface implemented by an object that can unmarshal a binary representation of itself.

​ BinaryUnmarshaler 是一个接口,由一个对象实现,该对象可以解组自身的二进制表示形式。

UnmarshalBinary must be able to decode the form generated by MarshalBinary. UnmarshalBinary must copy the data if it wishes to retain the data after returning.

​ UnmarshalBinary 必须能够解码由 MarshalBinary 生成的形式。如果希望在返回后保留数据,UnmarshalBinary 必须复制数据。

type TextMarshaler

1
2
3
type TextMarshaler interface {
	MarshalText() (text []byte, err error)
}

TextMarshaler is the interface implemented by an object that can marshal itself into a textual form.

​ TextMarshaler 是一个接口,由一个对象实现,该对象可以将自身编组为文本形式。

MarshalText encodes the receiver into UTF-8-encoded text and returns the result.

​ MarshalText 将接收者编码为 UTF-8 编码的文本,并返回结果。

type TextUnmarshaler

1
2
3
type TextUnmarshaler interface {
	UnmarshalText(text []byte) error
}

TextUnmarshaler is the interface implemented by an object that can unmarshal a textual representation of itself.

​ TextUnmarshaler 是一个接口,由一个对象实现,该对象可以解组自身的文本表示形式。

UnmarshalText must be able to decode the form generated by MarshalText. UnmarshalText must copy the text if it wishes to retain the text after returning.

​ UnmarshalText 必须能够解码由 MarshalText 生成的形式。如果希望在返回后保留文本,UnmarshalText 必须复制文本。

最后修改 October 10, 2024: 更新 (a4b8f85)