Documentation
¶
Overview ¶
Package codec provides high-performance encoding/decoding using hyperpb.
Index ¶
- Variables
- func ClearPools()
- type Codec
- func (c *Codec) Descriptor() protoreflect.MessageDescriptor
- func (c *Codec) Marshal(msg protobuf.Message) ([]byte, error)
- func (c *Codec) MarshalToJSON(msg protobuf.Message) ([]byte, error)
- func (c *Codec) NewMessage() protobuf.Message
- func (c *Codec) ReleaseMessage(msg protobuf.Message)
- func (c *Codec) Unmarshal(data []byte) (protobuf.Message, error)
- func (c *Codec) UnmarshalFromJSON(data []byte) (protobuf.Message, error)
- type Decoder
- func (d *Decoder) Decode(data []byte) (*hyperpb.Message, error)
- func (d *Decoder) DecodeInto(data []byte, msg protobuf.Message) error
- func (d *Decoder) DecodeJSON(data []byte) (*hyperpb.Message, error)
- func (d *Decoder) Descriptor() protoreflect.MessageDescriptor
- func (d *Decoder) GetMessage() *hyperpb.Message
- func (d *Decoder) PutMessage(msg *hyperpb.Message)
- type DecoderOptions
- type Encoder
- type EncoderOptions
- type GlobalPools
- type MessagePool
- type Options
- type PoolStats
Constants ¶
This section is empty.
Variables ¶
var DefaultDecoderOptions = DecoderOptions{ EnablePooling: true, InitialPoolSize: 10, AllowUnknownFields: false, EnablePGO: false, }
DefaultDecoderOptions are the default options for decoders.
Functions ¶
Types ¶
type Codec ¶
type Codec struct {
// contains filtered or unexported fields
}
Codec provides high-level encoding/decoding operations.
func New ¶
func New(md protoreflect.MessageDescriptor, opts Options) (*Codec, error)
New creates a new codec for the given message descriptor.
func (*Codec) Descriptor ¶
func (c *Codec) Descriptor() protoreflect.MessageDescriptor
Descriptor returns the message descriptor.
func (*Codec) MarshalToJSON ¶
MarshalToJSON encodes a message to JSON.
func (*Codec) NewMessage ¶
NewMessage creates a new message instance.
func (*Codec) ReleaseMessage ¶
ReleaseMessage returns a message to the pool.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder handles decoding protobuf format to Go values using hyperpb.
func NewDecoder ¶
func NewDecoder(md protoreflect.MessageDescriptor, opts DecoderOptions) (*Decoder, error)
NewDecoder creates a new decoder for the given message descriptor.
func (*Decoder) DecodeInto ¶
DecodeInto unmarshals bytes into an existing message.
func (*Decoder) DecodeJSON ¶
DecodeJSON unmarshals JSON to a protobuf message.
func (*Decoder) Descriptor ¶
func (d *Decoder) Descriptor() protoreflect.MessageDescriptor
Descriptor returns the message descriptor.
func (*Decoder) GetMessage ¶
GetMessage returns a message from the pool or creates a new one.
func (*Decoder) PutMessage ¶
PutMessage returns a message to the pool.
type DecoderOptions ¶
type DecoderOptions struct {
// EnablePooling enables message pooling for better performance
EnablePooling bool
// InitialPoolSize sets the initial pool size
InitialPoolSize int
// AllowUnknownFields allows unknown fields in the input
AllowUnknownFields bool
// EnablePGO enables profile-guided optimization
EnablePGO bool
}
DecoderOptions configures the decoder.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder handles encoding Go values to protobuf format using hyperpb.
func NewEncoder ¶
func NewEncoder(md protoreflect.MessageDescriptor, opts EncoderOptions) (*Encoder, error)
NewEncoder creates a new encoder for the given message descriptor.
func (*Encoder) Descriptor ¶
func (e *Encoder) Descriptor() protoreflect.MessageDescriptor
Descriptor returns the message descriptor.
func (*Encoder) EncodeJSON ¶
EncodeJSON marshals a protobuf message to JSON.
func (*Encoder) GetMessage ¶
GetMessage returns a message from the pool or creates a new one.
func (*Encoder) PutMessage ¶
PutMessage returns a message to the pool.
type EncoderOptions ¶
type EncoderOptions struct {
// EnablePooling enables message pooling for better performance
EnablePooling bool
// InitialPoolSize sets the initial pool size
InitialPoolSize int
}
EncoderOptions configures the encoder.
type GlobalPools ¶
type GlobalPools struct {
// contains filtered or unexported fields
}
GlobalPools manages pools for all message types.
type MessagePool ¶
type MessagePool struct {
// contains filtered or unexported fields
}
MessagePool manages a pool of reusable messages.
func GetPool ¶
func GetPool(md protoreflect.MessageDescriptor) (*MessagePool, error)
GetPool returns a pool for the given message descriptor.
func NewMessagePool ¶
func NewMessagePool(md protoreflect.MessageDescriptor) (*MessagePool, error)
NewMessagePool creates a new message pool.
func (*MessagePool) Get ¶
func (p *MessagePool) Get() *hyperpb.Message
Get retrieves a message from the pool.
func (*MessagePool) Put ¶
func (p *MessagePool) Put(msg *hyperpb.Message)
Put returns a message to the pool.
func (*MessagePool) Stats ¶
func (p *MessagePool) Stats() PoolStats
Stats returns the current pool statistics.