Documentation
¶
Overview ¶
Package codec provides high-performance encoding/decoding using hyperpb.
Index ¶
- Variables
- type Codec
- func (c *Codec) Descriptor() protoreflect.MessageDescriptor
- func (c *Codec) Marshal(msg protobuf.Message) ([]byte, error)
- func (c *Codec) MarshalStruct(source any) ([]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 Options
- type StructEncoder
Constants ¶
This section is empty.
Variables ¶
var DefaultDecoderOptions = DecoderOptions{ EnablePooling: true, InitialPoolSize: defaultPoolSize, AllowUnknownFields: false, EnablePGO: false, }
DefaultDecoderOptions are the default options for decoders.
Functions ¶
This section is empty.
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) MarshalStruct ¶ added in v0.3.0
MarshalStruct encodes a Go struct directly to protobuf binary.
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 Options ¶
type Options struct {
// EnablePooling enables message pooling
EnablePooling bool
// PoolSize sets the initial pool size
PoolSize int
// AllowUnknownFields allows unknown fields when decoding
AllowUnknownFields bool
}
Options configures codec behavior.
type StructEncoder ¶ added in v0.3.0
type StructEncoder struct {
// contains filtered or unexported fields
}
StructEncoder provides struct to protobuf encoding.
func NewStructEncoder ¶ added in v0.3.0
func NewStructEncoder(md protoreflect.MessageDescriptor) *StructEncoder
NewStructEncoder creates a new struct encoder.
func (*StructEncoder) EncodeStruct ¶ added in v0.3.0
func (se *StructEncoder) EncodeStruct(source any) ([]byte, error)
EncodeStruct encodes a Go struct directly to protobuf binary.