byteschema

package
v1.10.0-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package byteschema projects decoded byte lengths into JSON string constraints for the standard padded base64 language accepted by the built-in JSON codec.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bounds

type Bounds struct {
	// Minimum is the inclusive lower decoded length, or nil if unbounded.
	Minimum *int
	// Maximum is the inclusive upper decoded length, or nil if unbounded.
	Maximum *int
}

Bounds holds inclusive decoded byte lengths. Nil endpoints are unbounded.

func Intersect

func Intersect(bounds []Bounds) Bounds

Intersect conjoins an occurrence's decoded length bounds before projection. The returned endpoints are owned copies. Negative and inconsistent endpoints are retained so Project can distinguish vacuous lower bounds and empty ranges.

type Branch

type Branch struct {
	// Pattern uses syntax shared by ECMA-262 and Go regular expressions.
	Pattern string
	// MinLength is the inclusive encoded character lower bound.
	MinLength int
	// MaxLength is the inclusive encoded upper bound, or nil if unbounded.
	MaxLength *int
}

Branch combines an anchored base64 grammar with encoded character bounds. Unused padding bits are unrestricted, matching the actual JSON decoder.

type Constraint

type Constraint struct {
	// Unsatisfiable means no nonnegative decoded length satisfies the bounds.
	// Emit an unsatisfiable schema such as not:{}, never an empty anyOf.
	Unsatisfiable bool
	// ForbiddenPattern must be negated, for example with JSON Schema not.
	// This excludes line terminators despite ECMA-262 end-anchor semantics.
	ForbiddenPattern string
	// Branches are alternatives ordered by decoded length modulo three.
	Branches []Branch
}

Constraint describes a conjunction of an excluded-character check and a disjunction of residue branches. It applies only to present JSON strings; callers own type, nullability, metadata and other schema constraints.

func Project

func Project(minimum, maximum *int) (Constraint, error)

Project converts decoded byte bounds to a constant-size string constraint. A nil minimum means zero; a negative minimum is vacuous. A nil maximum is unbounded; a negative maximum or contradictory range is unsatisfiable. Returned storage is owned by the caller. Errors identify encoded bounds that cannot be represented exactly by both Go int and JSON number validators; callers must add the affected schema occurrence's path.

Jump to

Keyboard shortcuts

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