schema

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatCanonical

func FormatCanonical(s *Schema, path, formatOverride string) ([]byte, error)

FormatCanonical returns canonical YAML or JSON bytes for a schema (stable field order preserved). formatOverride is json|yaml|"" (inferred from path extension when empty).

func FormatDiff

func FormatDiff(d DiffResult) string

FormatDiff returns a human-readable diff.

func GenerateGo

func GenerateGo(s *Schema, pkg string) (string, error)

GenerateGo emits idiomatic ParseX code with bounds checks and typed errors.

func GenerateKaitai

func GenerateKaitai(s *Schema) (string, error)

GenerateKaitai emits a Kaitai Struct (.ksy) YAML definition from a Wiretap schema.

func GenerateWiresharkLua

func GenerateWiresharkLua(s *Schema, protoName string) (string, error)

GenerateWiresharkLua emits a stub Lua dissector for Wireshark.

func MarshalJSON

func MarshalJSON(s *Schema) ([]byte, error)

MarshalJSON serializes a schema as indented JSON.

func MarshalYAML

func MarshalYAML(s *Schema) ([]byte, error)

MarshalYAML serializes a schema.

func Validate

func Validate(s *Schema) []error

Validate checks structural consistency of the schema AST.

Types

type AnnOverlay

type AnnOverlay struct {
	Offset int
	Length int
	Kind   string
	Label  string
	Note   string
}

AnnOverlay is a minimal annotation overlay for MergeAnnotations (avoids project import).

type DiffChange

type DiffChange struct {
	Path   string `json:"path"`
	Kind   string `json:"kind"` // added|removed|changed
	Before string `json:"before,omitempty"`
	After  string `json:"after,omitempty"`
}

DiffChange describes one schema difference.

type DiffResult

type DiffResult struct {
	Changes []DiffChange `json:"changes"`
}

DiffResult holds schema comparison.

func Diff

func Diff(a, b *Schema) DiffResult

Diff compares two schemas field-by-field (deterministic).

type Field

type Field struct {
	Name        string         `yaml:"name" json:"name"`
	Offset      *int           `yaml:"offset,omitempty" json:"offset,omitempty"`
	Length      int            `yaml:"length,omitempty" json:"length,omitempty"`
	Type        string         `yaml:"type" json:"type"` // u8,u16,u32,u64,i8,...,bytes,string,bitfield,checksum,struct,array
	Endian      string         `yaml:"endian,omitempty" json:"endian,omitempty"`
	Encoding    string         `yaml:"encoding,omitempty" json:"encoding,omitempty"`
	Value       string         `yaml:"value,omitempty" json:"value,omitempty"` // expected constant hex
	Description string         `yaml:"description,omitempty" json:"description,omitempty"`
	Confidence  string         `yaml:"confidence,omitempty" json:"confidence,omitempty"`
	Evidence    string         `yaml:"evidence,omitempty" json:"evidence,omitempty"`
	Children    []Field        `yaml:"fields,omitempty" json:"fields,omitempty"`
	Meta        map[string]any `yaml:"meta,omitempty" json:"meta,omitempty"`
}

Field is one schema node (may contain children for nested structures).

type LintIssue

type LintIssue struct {
	Severity string // warning | info
	Path     string
	Message  string
}

LintIssue is a non-fatal schema quality finding.

func Lint

func Lint(s *Schema) []LintIssue

Lint returns quality warnings beyond structural Validate errors. It does not invent protocol facts — only flags schema hygiene problems.

func (LintIssue) String

func (i LintIssue) String() string

type Schema

type Schema struct {
	Name    string  `yaml:"name" json:"name"`
	Version string  `yaml:"version,omitempty" json:"version,omitempty"`
	Endian  string  `yaml:"endian,omitempty" json:"endian,omitempty"` // le|be|mixed
	Fields  []Field `yaml:"fields" json:"fields"`
	Notes   string  `yaml:"notes,omitempty" json:"notes,omitempty"`
}

Schema is a nested protocol schema AST.

func InferFromHypotheses

func InferFromHypotheses(name string, constants []struct {
	Start, End int
	Value      byte
}, hyps []wt.Hypothesis) *Schema

InferFromHypotheses builds a schema from high-confidence hypotheses + constants. Prefers typed fields over opaque ints, deconflicts overlaps, and may emit nested header structs / arrays.

func LoadFile

func LoadFile(path string, format string) (*Schema, error)

LoadFile loads a schema from path, selecting codec by extension or format override.

func MergeAnnotations

func MergeAnnotations(s *Schema, anns []AnnOverlay) *Schema

MergeAnnotations merges annotation overlays into a schema as trusted field overlays.

func UnmarshalAuto

func UnmarshalAuto(b []byte, format string) (*Schema, error)

UnmarshalAuto parses JSON or YAML. format is json|yaml|"" (auto).

func UnmarshalJSON

func UnmarshalJSON(b []byte) (*Schema, error)

UnmarshalJSON parses a schema from JSON.

func UnmarshalYAML

func UnmarshalYAML(b []byte) (*Schema, error)

UnmarshalYAML parses a schema from YAML.

Jump to

Keyboard shortcuts

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