Package-level declarations

Types

Link copied to clipboard

What to do when an object is given the same field name twice.

Link copied to clipboard
class JsonParseException(message: String, val offset: Int, val line: Int, val column: Int) : VariantException

JSON input is malformed.

Link copied to clipboard
class JsonParser(maxDepth: Int = DEFAULT_MAX_JSON_DEPTH)

Parses JSON text straight into the Variant encoding.

Link copied to clipboard

A Variant value has no JSON representation.

Link copied to clipboard
class Variant(val metadata: VariantMetadata, segment: MemorySegment, val offset: Long = 0)

A view over one encoded Variant value.

Link copied to clipboard

The two-bit basic_type field that opens every Variant value byte.

Link copied to clipboard
class VariantBuilder(val dictionary: VariantDictionaryBuilder = VariantDictionaryBuilder(), duplicateFields: DuplicateFieldPolicy = DuplicateFieldPolicy.LAST_WINS)

Encodes Variant values.

Link copied to clipboard

Builds a dictionary by interning field names, and encodes it once the values that use it are written.

Link copied to clipboard

Base class for every failure raised by the Variant codec.

Link copied to clipboard
class VariantFormatException(message: String, val offset: Long = -1, cause: Throwable? = null) : VariantException

The bytes are not a Variant value this implementation can read.

Link copied to clipboard

What a value means, independent of how many bytes it took to say it.

Link copied to clipboard

The string dictionary half of a Variant: every field name used by the values that reference it.

Link copied to clipboard
class VariantNode(val location: VariantPath, val value: Variant)

A value together with where it is — RFC 9535's node: "the pair of a value along with its location within the query argument".

Link copied to clipboard
class VariantPath(val steps: List<VariantPathStep>)

A location inside a document, as a list of steps from the root.

Link copied to clipboard
sealed interface VariantPathStep

One step of a VariantPath: into an object field, or into an array element.

Link copied to clipboard

The primitive type ids carried in the upper six bits of a value header byte when VariantBasicType.PRIMITIVE is in effect.

Link copied to clipboard

A well-formed value was asked for a type it does not hold — longValue() on a string, or a field lookup on an array.

Properties

Link copied to clipboard
const val DEFAULT_MAX_JSON_DEPTH: Int = 1000

Nesting depth a document may reach before the parser gives up.

Link copied to clipboard
const val DEFAULT_SUMMARY_LIMIT: Int = 8

Top-level children a summary shows before eliding the rest.

Link copied to clipboard
const val MAX_DECIMAL_PRECISION: Int = 38

Widest decimal the encoding can hold: decimal16 carries an int128 unscaled value.

Link copied to clipboard
const val MAX_DECIMAL_SCALE: Int = 38

The specification fixes the scale byte's range at [0, 38].

Link copied to clipboard
const val SUMMARY_VALUE_LIMIT: Int = 64

Characters of any one string or field name a summary shows before eliding the rest.

Functions

Link copied to clipboard
fun Variant.appendJsonSummaryTo(out: StringBuilder, limit: Int = DEFAULT_SUMMARY_LIMIT)

Appends toJsonSummaryString to out, avoiding an intermediate String.

Link copied to clipboard

Appends Variant.toJsonString to out, avoiding an intermediate String.

Link copied to clipboard

Renders this value as JSON text.

Link copied to clipboard
fun Variant.toJsonSummaryString(limit: Int = DEFAULT_SUMMARY_LIMIT): String

The first limit top-level children, with everything below them elided.

Link copied to clipboard

One line describing this value's shape and size, whatever it holds and however large it is.

Link copied to clipboard
fun variantPathOf(vararg fields: String): VariantPath

Convenience for building a path from field names: variantPathOf("user", "name").