Documentation
¶
Overview ¶
Package payload enforces bounded resource use before source decoding.
Index ¶
Constants ¶
const ( // MaxBytes bounds one provider or catalog source JSON payload. MaxBytes = 16 << 20 // MaxJSONNestingDepth bounds object/array nesting before JSON decode. MaxJSONNestingDepth = 64 )
Variables ¶
This section is empty.
Functions ¶
func ValidateJSON ¶
ValidateJSON enforces source byte and nesting limits before decoding.
Types ¶
type QuarantineError ¶
type QuarantineError struct {
// Collection identifies the affected source collection.
Collection string
// Report describes the usable and quarantined records.
Report RecordReport
}
QuarantineError reports a partial result with usable records and quarantined malformed or excess siblings.
func (*QuarantineError) Unwrap ¶
func (e *QuarantineError) Unwrap() error
Unwrap exposes the first record error for standard errors.Is/errors.As use.
type RecordIssue ¶
type RecordIssue struct {
// Subject identifies the record within its collection.
Subject string
// Err is the typed decode or validation failure.
Err error
}
RecordIssue describes one malformed member of an otherwise valid collection. Subject is a stable collection-relative identity and never contains raw input.
type RecordReport ¶
type RecordReport struct {
// Accepted is the number of successfully decoded records.
Accepted int
// Rejected includes malformed and excess records.
Rejected int
// Issues contains bounded details for malformed records.
Issues []RecordIssue
// Truncated reports that excess records were not decoded.
Truncated bool
}
RecordReport describes bounded per-record decoding.
func DecodeJSONArray ¶
func DecodeJSONArray[T any](data json.RawMessage, collection string, limit int) ([]T, RecordReport, error)
DecodeJSONArray requires a valid JSON array envelope, then decodes each member independently. It decodes at most max records.
func DecodeJSONObject ¶
func DecodeJSONObject[T any](data json.RawMessage, collection string, limit int) (map[string]T, RecordReport, error)
DecodeJSONObject requires a valid JSON object envelope, then decodes values independently in sorted key order. It decodes at most max records.
func (RecordReport) Err ¶
func (r RecordReport) Err(collection string) error
Err returns a typed partial-result error when the report contains quarantined records.
type UnknownJSONField ¶
type UnknownJSONField struct {
Path string `json:"path" yaml:"path"`
Checksum string `json:"checksum" yaml:"checksum"`
}
UnknownJSONField is reviewable evidence for one additive source field that was not promoted into the typed schema.
func FingerprintValue ¶
func FingerprintValue(path string, value any) UnknownJSONField
FingerprintValue returns path/digest evidence for an unrecognized typed value.
func UnknownJSONFields ¶
func UnknownJSONFields(data []byte, schema any, prefix string) ([]UnknownJSONField, error)
UnknownJSONFields returns deterministic path/digest evidence for top-level JSON members not declared by schema. Raw values are intentionally omitted.