jsonspan

package
v0.1.1 Latest Latest
Warning

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

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

Documentation

Overview

Package jsonspan extracts the exact byte span of a value inside a single-line JSON object, walking JSON syntax (strings, escapes, nesting) without ever parse-and-reserializing. It exists because the span rule (docs/export-format-v1.md §1.2) makes raw byte spans load-bearing: the bytes that were signed are the bytes that must come back out, verbatim.

The Week-1 export tests carry an intentionally independent copy of this scanner (internal/exportv1/span_test.go); this package is the production version used by the Week-2 log envelope and export bridge.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractTopLevelValue

func ExtractTopLevelValue(line []byte, key string) ([]byte, error)

ExtractTopLevelValue returns the exact byte span of the value for key in the top-level JSON object encoded by line. The returned slice aliases line; callers must not modify it.

func TopLevelSpan

func TopLevelSpan(line []byte, key string) (int, int, error)

TopLevelSpan returns the half-open byte offsets [start, end) of the value for key in the top-level JSON object encoded by line. Offsets, rather than the aliased slice ExtractTopLevelValue returns, are what a splicer needs: the MCP proxy rebuilds a tools/call line around the params._meta span and must copy every other byte through untouched.

Types

type Field

type Field struct {
	Name       string
	Start, End int
}

Field is one member of a JSON object: its decoded name and the byte span of its raw value.

func TopLevelKeys

func TopLevelKeys(line []byte) ([]Field, error)

TopLevelKeys returns the keys of the top-level JSON object encoded by line, in the order they appear, each paired with its value's byte span. The proxy uses it to build a payload's field-digest manifest without re-serializing any value (Q37).

Jump to

Keyboard shortcuts

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