preview

package
v0.2.49 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Meta

type Meta struct {
	Truncated           bool `json:"truncated"`
	ApproxOriginalBytes int  `json:"approxOriginalBytes"`
	ApproxReturnedBytes int  `json:"approxReturnedBytes"`
}

Meta describes the compaction outcome.

func Compact

func Compact(v interface{}, opts Options) (interface{}, Meta, error)

Compact reduces v to fit within opts.BudgetBytes where possible. It returns a new value; the input is not modified. When the result exceeds the budget even after compaction, it is returned best-effort with Meta.Truncated=true.

type Options

type Options struct {
	// BudgetBytes is the target maximum serialized JSON size (approximate).
	BudgetBytes int
	// MaxString clamps string lengths (runes). 0 disables string trimming.
	MaxString int
	// MaxArray keeps only first N items and summarizes the rest. 0 disables array compaction.
	MaxArray int
	// PreserveKeys are object keys that should not be summarized when choosing a largest key.
	PreserveKeys []string
	// LowValueKeys are candidates to summarize first when sizes are similar (e.g., "log", "html", "debug").
	LowValueKeys []string
}

Options controls compaction thresholds.

Jump to

Keyboard shortcuts

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