Documentation
¶
Overview ¶
Package run drives the encoder: it compiles the opcodes of a value, sets up the runtime context and runs the VM which the options choose. The v1 and the v2 json packages encode through it.
Index ¶
- Constants
- func Code(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]byte, error)
- func Encode(ctx *encoder.RuntimeContext, v any) ([]byte, error)
- func EncodeIndent(ctx *encoder.RuntimeContext, v any, prefix, indent string) ([]byte, error)
- func EncodeOf[T any](ctx *encoder.RuntimeContext, v *T) ([]byte, error)
- func IndentCode(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, ...) ([]byte, error)
Constants ¶
const MaxReusedValueSize = 4096
MaxReusedValueSize is the size of the largest value which EncodeOf, and the decoding of a value by its type, copy to a value they reuse. Every runtime context in the pool keeps such a value, so a large one is left to the GC.
Variables ¶
This section is empty.
Functions ¶
func Code ¶
Code runs the opcodes of a value, which ctx is set up for, by the VM of the options of ctx.
func Encode ¶
func Encode(ctx *encoder.RuntimeContext, v any) ([]byte, error)
Encode appends v to the buffer of ctx as JSON, with a comma after it, by the options of ctx. On an error, it returns the output written before the error with it, which the v2 json package finds the place of the error by.
func EncodeIndent ¶
EncodeIndent is Encode with the indentation and the prefix of each line.
func EncodeOf ¶
func EncodeOf[T any](ctx *encoder.RuntimeContext, v *T) ([]byte, error)
EncodeOf encodes the value at v, as Encode encodes it, without the copy of the value to the heap which an interface value of it would be: it is copied to a value in the heap which is reused ( see encoder.OpcodeSet.TakeValue ). A value which an interface value holds directly is encoded by Encode.
func IndentCode ¶
func IndentCode(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, prefix, indent string) ([]byte, error)
IndentCode is Code with the indentation and the prefix of each line.
Types ¶
This section is empty.