serialize

package
v0.0.0-...-8cff0bb Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalJSON

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

MarshalJSON 便捷函数,直接使用JSON序列化

func MarshalProto

func MarshalProto(obj proto.Message) ([]byte, error)

MarshalProto 便捷函数,直接使用Proto序列化

func MarshalProtoToJSON

func MarshalProtoToJSON(msg proto.Message) ([]byte, error)

MarshalProtoToJSON 便捷函数,将Proto消息序列化为JSON

func UnmarshalJSON

func UnmarshalJSON(data []byte, obj any) error

UnmarshalJSON 便捷函数,直接使用JSON反序列化

func UnmarshalJSONToProto

func UnmarshalJSONToProto(data []byte, msg proto.Message) error

UnmarshalJSONToProto 便捷函数,将JSON反序列化为Proto消息

func UnmarshalProto

func UnmarshalProto(data []byte, obj proto.Message) error

UnmarshalProto 便捷函数,直接使用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) GetFormat

func (s *Serializer) GetFormat() SerializeFormat

GetFormat 获取当前序列化格式

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

Jump to

Keyboard shortcuts

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