codec

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2024 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 2 more Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContextKeyMessage = ContextKey("TRPC_MESSAGE")
	// ServiceSectionLength is the length of service section,
	// service name example: trpc.app.server.service
	ServiceSectionLength = 4
)

trpc context key data

Variables

This section is empty.

Functions

This section is empty.

Types

type CommonMeta

type CommonMeta map[interface{}]interface{}

CommonMeta is common meta message.

func (CommonMeta) Clone

func (c CommonMeta) Clone() CommonMeta

Clone returns a copied common meta message.

type ContextKey

type ContextKey string

ContextKey is trpc context key type, the specific value is judged by interface, the interface will both judge value and type. Defining a new type can avoid string value conflict.

type MetaData

type MetaData map[string][]byte

MetaData is request penetrate message.

func (MetaData) Clone

func (m MetaData) Clone() MetaData

Clone returns a copied meta data.

type Msg

type Msg interface {
	// WithLogger sets logger into context.
	WithLogger(interface{})
	// Logger returns logger from context.
	Logger() interface{}
}

Msg defines core message data for Multi-protocol, business protocol should set this message when packing and unpacking data.

func EnsureMessage

func EnsureMessage(ctx context.Context) (context.Context, Msg)

EnsureMessage returns context and message, if there is a message in context, returns the original one, if not, returns a new one.

func Message

func Message(ctx context.Context) Msg

Message returns the message of context.

func WithNewMessage

func WithNewMessage(ctx context.Context) (context.Context, Msg)

WithNewMessage creates a new empty message, retrieves it from the message pool, and associates it with the provided context.

Important: The returned message is obtained from a pool to optimize memory usage. Users are responsible for manually invoking codec.PutBackMessage(msg) after use. Failure to return the message to the pool doesn't result in a traditional memory leak, where memory is never reclaimed. Instead, it may lead to a gradual increase in memory footprint over time, as messages are not being recycled as efficiently. This can eventually lead to higher than normal memory consumption, although the memory may still be eventually released.

Jump to

Keyboard shortcuts

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