Documentation
¶
Overview ¶
Package jpact provides JSON compaction with selectable drivers.
It exposes a small Compactor interface for streaming JSON compaction and convenience helpers that default to the internal driver.
Usage:
c := jpact.New()
if err := c.CompactWriter(w, r, 0); err != nil {
// handle error
}
// Choose the jsonv2 driver.
c = jpact.New(jpact.WithDriver(jpact.DriverJSONv2))
The maxBytes parameter limits the number of bytes read from the input stream; values <= 0 disable the limit.
The package-level helpers (CompactWriter/CompactToBuffer) are always routed to the internal driver and do not mutate any package-level state.
Example ¶
input := `{"a": 1, "b": [true, false, null]}`
var out bytes.Buffer
compactor := New()
_ = compactor.CompactWriter(&out, strings.NewReader(input), 0)
Example (PackageHelpers) ¶
input := `{"a": 1}`
var out bytes.Buffer
_ = CompactWriter(&out, strings.NewReader(input), 0)
Example (WithDriver) ¶
input := `{"a": 1}`
var out bytes.Buffer
compactor := New(WithDriver(DriverJSONv2))
_ = compactor.CompactWriter(&out, strings.NewReader(input), 0)
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompactToBuffer ¶
CompactToBuffer compacts JSON into memory using the default internal driver.
Types ¶
type Compactor ¶
type Compactor interface {
CompactWriter(w io.Writer, r io.Reader, maxBytes int64) error
CompactToBuffer(r io.Reader, maxBytes int64) ([]byte, error)
}
Compactor compacts JSON streams.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package compactor provides the internal JSON compaction implementation.
|
Package compactor provides the internal JSON compaction implementation. |
|
internal
|
|
|
compactortest
Package compactortest provides shared test helpers for jpact compactors.
|
Package compactortest provides shared test helpers for jpact compactors. |
|
Package jsonv2compactor provides a JSON compactor backed by a json v2 tokenizer.
|
Package jsonv2compactor provides a JSON compactor backed by a json v2 tokenizer. |
|
internal/jsonv2
Package jsonv2 contains the tokenizer adapted from the Go json v2 implementation.
|
Package jsonv2 contains the tokenizer adapted from the Go json v2 implementation. |
Click to show internal directories.
Click to hide internal directories.