marshal

package
v1.1.4-rc Latest Latest
Warning

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

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

Documentation

Overview

Package marshal provides optimized marshaling for DynamoDB

Package marshal provides safe marshaling for DynamoDB without unsafe operations

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetGlobalConfig

func SetGlobalConfig(config Config)

SetGlobalConfig sets the global marshaler configuration

func ValidateConfig

func ValidateConfig(config Config) error

ValidateConfig validates marshaler configuration for security compliance

Types

type Config

type Config struct {
	// MarshalerType specifies which marshaler to use (default: safe)
	MarshalerType MarshalerType `json:"marshaler_type" yaml:"marshaler_type"`

	// AllowUnsafeMarshaler must be explicitly set to true to enable unsafe operations
	// This flag is not serialized to prevent accidental persistence
	AllowUnsafeMarshaler bool `json:"-" yaml:"-"`

	// RequireExplicitUnsafeAck requires explicit acknowledgment of security risks
	RequireExplicitUnsafeAck bool `json:"require_explicit_unsafe_ack" yaml:"require_explicit_unsafe_ack"`

	// WarnOnUnsafeUsage logs warnings when unsafe marshaler is used
	WarnOnUnsafeUsage bool `json:"warn_on_unsafe_usage" yaml:"warn_on_unsafe_usage"`
}

Config holds marshaler configuration with security defaults

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a secure default configuration

func GetGlobalConfig

func GetGlobalConfig() Config

GetGlobalConfig returns the current global configuration

type Marshaler

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

Marshaler provides high-performance marshaling to DynamoDB AttributeValues

func New

func New(converter *pkgTypes.Converter) *Marshaler

New creates a new optimized marshaler. If a converter is provided it will be consulted for custom type conversions during marshaling.

func (*Marshaler) ClearCache

func (m *Marshaler) ClearCache()

ClearCache removes all cached struct marshalers. This is useful when new custom converters are registered and previously compiled functions need to be rebuilt.

func (*Marshaler) MarshalItem

func (m *Marshaler) MarshalItem(model any, metadata *model.Metadata) (map[string]types.AttributeValue, error)

MarshalItem marshals a model to DynamoDB AttributeValues using cached reflection

type MarshalerFactory

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

MarshalerFactory creates marshalers with security controls

func NewMarshalerFactory

func NewMarshalerFactory(config Config) *MarshalerFactory

NewMarshalerFactory creates a new factory with the given configuration

func (*MarshalerFactory) NewMarshaler

func (f *MarshalerFactory) NewMarshaler() (MarshalerInterface, error)

NewMarshaler creates a marshaler based on configuration

func (*MarshalerFactory) NewMarshalerWithAcknowledgment

func (f *MarshalerFactory) NewMarshalerWithAcknowledgment(ack *SecurityAcknowledgment) (MarshalerInterface, error)

NewMarshalerWithAcknowledgment creates a marshaler with explicit security acknowledgment

func (*MarshalerFactory) WithConverter

func (f *MarshalerFactory) WithConverter(converter *pkgTypes.Converter) *MarshalerFactory

WithConverter sets the converter used for creating unsafe marshalers.

func (*MarshalerFactory) WithNowFunc

func (f *MarshalerFactory) WithNowFunc(now func() time.Time) *MarshalerFactory

type MarshalerInterface

type MarshalerInterface interface {
	MarshalItem(model any, metadata *model.Metadata) (map[string]types.AttributeValue, error)
}

MarshalerInterface defines the common interface for all marshalers

type MarshalerType

type MarshalerType string

MarshalerType defines the type of marshaler to use

const (
	// SafeMarshalerType uses reflection-based marshaling (RECOMMENDED)
	SafeMarshalerType MarshalerType = "safe"

	// UnsafeMarshalerType uses unsafe pointer operations (DEPRECATED)
	// Will be removed in v2.0
	UnsafeMarshalerType MarshalerType = "unsafe"
)

type SafeMarshaler

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

SafeMarshaler provides memory-safe marshaling implementation without unsafe operations This is the default marshaler and should be used in production environments

func NewSafeMarshaler

func NewSafeMarshaler() *SafeMarshaler

NewSafeMarshaler creates a new safe marshaler (recommended for production)

func NewSafeMarshalerWithConverter

func NewSafeMarshalerWithConverter(converter *pkgTypes.Converter) *SafeMarshaler

NewSafeMarshalerWithConverter creates a safe marshaler that consults the provided converter for registered custom type conversions.

func (*SafeMarshaler) MarshalItem

func (m *SafeMarshaler) MarshalItem(model any, metadata *model.Metadata) (map[string]types.AttributeValue, error)

MarshalItem safely marshals a model to DynamoDB AttributeValues using only reflection This implementation prioritizes security over performance but is still highly optimized

type SecurityAcknowledgment

type SecurityAcknowledgment struct {
	DeveloperSignature              string
	Timestamp                       int64
	AcknowledgeMemoryCorruptionRisk bool
	AcknowledgeSecurityVulnerable   bool
	AcknowledgeDeprecationWarning   bool
}

SecurityAcknowledgment represents explicit acknowledgment of unsafe marshaler risks

func CreateSecurityAcknowledgment

func CreateSecurityAcknowledgment(developerSignature string) *SecurityAcknowledgment

CreateSecurityAcknowledgment creates a security acknowledgment for unsafe marshaler usage

type SecurityStats

type SecurityStats struct {
	CurrentConfig    Config
	UnsafeUsageCount int64
	SecurityWarnings int64
}

SecurityStats contains security monitoring information

func GetSecurityStats

func GetSecurityStats() SecurityStats

GetSecurityStats returns security-related statistics

Jump to

Keyboard shortcuts

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