Documentation
¶
Overview ¶
Package outputlimit renders bounded output without splitting UTF-8 or CRLF.
Index ¶
- Constants
- Variables
- func BoundJSON(projected map[string]any, grant int, policy Policy, fallback JSONFallback) (map[string]any, int, error)
- func Marker(reason string, keptBytes, origBytes, keptLines, origLines int) string
- type Budget
- type JSONFallback
- type Policy
- type Report
- type Reservation
- type Writer
Constants ¶
const ( ReasonBytes = "bytes" ReasonLines = "lines" ReasonLineLength = "line_length" ReasonBudget = "budget" ReasonFile = "file" )
const DefaultPerSession = 400000
const MinimumBudgetGrant = 2000
Variables ¶
var ( ErrInvalidLimit = errors.New("outputlimit: invalid limit") ErrCounterOverflow = errors.New("outputlimit: counter overflow") )
Functions ¶
func BoundJSON ¶
func BoundJSON(projected map[string]any, grant int, policy Policy, fallback JSONFallback) (map[string]any, int, error)
BoundJSON serializes a result and returns a complete JSON-safe value whose final encoding fits both the call grant and policy. The returned byte count is the size consumers must charge to the session budget.
Types ¶
type Budget ¶
type Budget struct {
// contains filtered or unexported fields
}
Budget coordinates cumulative rendered output independently per session.
func NewBudget ¶
NewBudget constructs a per-session budget. Non-positive values use the package default.
type JSONFallback ¶
JSONFallback projects truncated JSON text into the consumer's wire shape. BoundJSON still owns the byte accounting and normative truncation report.
type Policy ¶
type Policy struct {
MaxBytes int `json:"max_bytes"`
MaxLines int `json:"max_lines"`
MaxLineBytes int `json:"max_line_bytes"`
HeadFraction float64 `json:"head_fraction"`
}
Policy controls source content retained in rendered output. Non-positive limits are disabled.
type Report ¶
type Report struct {
Truncated bool `json:"truncated"`
Reason string `json:"reason"`
OriginalBytes int `json:"original_bytes"`
OriginalLines int `json:"original_lines"`
KeptBytes int `json:"kept_bytes"`
KeptLines int `json:"kept_lines"`
}
Report describes source content removed from output. Marker bytes and aggregate separator bytes are not source content and are excluded.
type Reservation ¶
Reservation identifies one outstanding budget grant. IDs are unique within a Budget so concurrent calls can settle in completion order.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer retains bounded head and tail samples from a byte stream.
func NewWriter ¶
NewWriter constructs a writer whose dynamic buffers never exceed twice the policy's aggregate byte limit when MaxBytes is positive. A zero MaxBytes preserves the policy's unlimited-output meaning.
func (*Writer) Reset ¶
func (w *Writer) Reset()
Reset discards the captured stream and accounting state.