codec

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package codec provides high-performance encoding/decoding using hyperpb.

Index

Constants

This section is empty.

Variables

View Source
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

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) Marshal

func (c *Codec) Marshal(msg protobuf.Message) ([]byte, error)

Marshal encodes a message to bytes.

func (*Codec) MarshalStruct added in v0.3.0

func (c *Codec) MarshalStruct(source any) ([]byte, error)

MarshalStruct encodes a Go struct directly to protobuf binary.

func (*Codec) MarshalToJSON

func (c *Codec) MarshalToJSON(msg protobuf.Message) ([]byte, error)

MarshalToJSON encodes a message to JSON.

func (*Codec) NewMessage

func (c *Codec) NewMessage() protobuf.Message

NewMessage creates a new message instance.

func (*Codec) ReleaseMessage

func (c *Codec) ReleaseMessage(msg protobuf.Message)

ReleaseMessage returns a message to the pool.

func (*Codec) Unmarshal

func (c *Codec) Unmarshal(data []byte) (protobuf.Message, error)

Unmarshal decodes bytes to a message.

func (*Codec) UnmarshalFromJSON

func (c *Codec) UnmarshalFromJSON(data []byte) (protobuf.Message, error)

UnmarshalFromJSON decodes JSON to a message.

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder handles decoding protobuf format to Go values using hyperpb.

func NewDecoder

NewDecoder creates a new decoder for the given message descriptor.

func (*Decoder) Decode

func (d *Decoder) Decode(data []byte) (*hyperpb.Message, error)

Decode unmarshals bytes to a protobuf message.

func (*Decoder) DecodeInto

func (d *Decoder) DecodeInto(data []byte, msg protobuf.Message) error

DecodeInto unmarshals bytes into an existing message.

func (*Decoder) DecodeJSON

func (d *Decoder) DecodeJSON(data []byte) (*hyperpb.Message, error)

DecodeJSON unmarshals JSON to a protobuf message.

func (*Decoder) Descriptor

func (d *Decoder) Descriptor() protoreflect.MessageDescriptor

Descriptor returns the message descriptor.

func (*Decoder) GetMessage

func (d *Decoder) GetMessage() *hyperpb.Message

GetMessage returns a message from the pool or creates a new one.

func (*Decoder) PutMessage

func (d *Decoder) PutMessage(msg *hyperpb.Message)

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

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) Encode

func (e *Encoder) Encode(msg protobuf.Message) ([]byte, error)

Encode marshals a protobuf message to bytes.

func (*Encoder) EncodeJSON

func (e *Encoder) EncodeJSON(msg protobuf.Message) ([]byte, error)

EncodeJSON marshals a protobuf message to JSON.

func (*Encoder) GetMessage

func (e *Encoder) GetMessage() *hyperpb.Message

GetMessage returns a message from the pool or creates a new one.

func (*Encoder) PutMessage

func (e *Encoder) PutMessage(msg *hyperpb.Message)

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.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns default codec options.

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.

Jump to

Keyboard shortcuts

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