encoding

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterCodec

func RegisterCodec(codec Codec)

RegisterCodec 注册编解码器,供所有传输客户端和服务器使用。

Types

type Codec

type Codec interface {
	// Name 返回编解码器名称,用作传输时的内容类型标识。
	// 返回值必须静态不变。
	Name() string
	// Marshal 将 v 序列化为字节数组。
	Marshal(v any) ([]byte, error)
	// Unmarshal 将字节数组反序列化到 v。
	Unmarshal(data []byte, v any) error
}

Codec 定义编解码接口,用于序列化和反序列化消息。 实现必须线程安全,方法可能被并发调用。

func GetCodec

func GetCodec(contentSubtype string) Codec

GetCodec 根据内容子类型获取已注册的编解码器,未注册则返回 nil。

content-subtype 应为小写。

Directories

Path Synopsis
Package proto 定义 protobuf 编解码器。
Package proto 定义 protobuf 编解码器。

Jump to

Keyboard shortcuts

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