Documentation
¶
Index ¶
- func MarshalJSON(obj interface{}) ([]byte, error)
- func MarshalProto(obj proto.Message) ([]byte, error)
- func MarshalProtoToJSON(msg proto.Message) ([]byte, error)
- func UnmarshalJSON(data []byte, obj any) error
- func UnmarshalJSONToProto(data []byte, msg proto.Message) error
- func UnmarshalProto(data []byte, obj proto.Message) error
- type SerializeFormat
- type Serializer
- func (s *Serializer) GetFormat() SerializeFormat
- func (s *Serializer) Marshal(obj any) ([]byte, error)
- func (s *Serializer) MarshalBSON(obj any) ([]byte, error)
- func (s *Serializer) MarshalString(obj any) (string, error)
- func (s *Serializer) Unmarshal(data []byte, obj any) error
- func (s *Serializer) UnmarshalBSON(data []byte, obj any) error
- func (s *Serializer) UnmarshalString(encodedStr string, obj any) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MarshalProto ¶
MarshalProto 便捷函数,直接使用Proto序列化
func MarshalProtoToJSON ¶
MarshalProtoToJSON 便捷函数,将Proto消息序列化为JSON
func UnmarshalJSONToProto ¶
UnmarshalJSONToProto 便捷函数,将JSON反序列化为Proto消息
Types ¶
type SerializeFormat ¶
type SerializeFormat string
SerializeFormat 定义序列化格式
const ( // FormatProto 使用Protocol Buffers序列化 FormatProto SerializeFormat = "proto" // FormatJSON 使用JSON序列化 FormatJSON SerializeFormat = "json" )
func ParseSerializeFormat ¶
func ParseSerializeFormat(format string) SerializeFormat
type Serializer ¶
type Serializer struct {
// contains filtered or unexported fields
}
Serializer 提供序列化和反序列化功能
func NewSerializer ¶
func NewSerializer(format SerializeFormat) *Serializer
NewSerializer 创建一个新的序列化器
func (*Serializer) Marshal ¶
func (s *Serializer) Marshal(obj any) ([]byte, error)
Marshal 将对象序列化为字节数组
func (*Serializer) MarshalBSON ¶
func (s *Serializer) MarshalBSON(obj any) ([]byte, error)
func (*Serializer) MarshalString ¶
func (s *Serializer) MarshalString(obj any) (string, error)
func (*Serializer) Unmarshal ¶
func (s *Serializer) Unmarshal(data []byte, obj any) error
Unmarshal 将字节数组反序列化为对象
func (*Serializer) UnmarshalBSON ¶
func (s *Serializer) UnmarshalBSON(data []byte, obj any) error
func (*Serializer) UnmarshalString ¶
func (s *Serializer) UnmarshalString(encodedStr string, obj any) error
Click to show internal directories.
Click to hide internal directories.