Documentation
¶
Overview ¶
Package jsonio owns streamio's JSON output path: encoding canonical record.Records as JSON documents, and decoding NDJSON back into them.
It writes JSON tokens straight to a jsontext.Encoder rather than marshalling a map, since reflection over a per-row map is the dominant cost this path avoids.
JSON value-rendering helpers, kept beside the encoder so every JSON-producing path renders a given value the same way.
Index ¶
- Constants
- Variables
- func AppendFloat(dst []byte, f float64, bitSize int) []byte
- func Date(days int64) string
- func NewDecoder(cfg options.Config, src options.Source) (formatio.RecordDecoder, error)
- func NewEncoder(_ options.Config) (formatio.RecordEncoder, error)
- func NewRawSource(cfg options.Config, src options.Source) (formatio.RawSource, error)
- func TimestampMicros(v int64) string
- func TimestampMillis(v int64) string
- func TimestampNanos(v int64) string
- func WriteFloat(enc *jsontext.Encoder, f float64, bitSize int) error
- type ObjectDecoder
Constants ¶
const ( Bits32 = 32 Bits64 = 64 )
Bits32 and Bits64 select the precision WriteFloat and AppendFloat format at.
Variables ¶
var ( // ErrNotObject reports a line whose top-level value isn't a JSON object. ErrNotObject = errors.New("jsonio: document is not a JSON object") // ErrUnexpectedToken reports a token that cannot appear where it did, which means the document // isn't well-formed for this decoder's object contract. ErrUnexpectedToken = errors.New("jsonio: unexpected token") )
Errors a JSON document can fail to decode with. They are deliberately specific about what this decoder accepts, because the honest answer is "an object, arbitrarily nested" rather than "maybe malformed".
var ErrNonFinite = errors.New("json: unsupported value: non-finite float")
ErrNonFinite is returned for NaN and ±Inf, which have no JSON number representation.
Functions ¶
func AppendFloat ¶
AppendFloat formats f exactly as encoding/json's floatEncoder does and appends it to dst.
func NewDecoder ¶
NewDecoder opens src as a stream of canonical records. Lines are parsed as JSON tokens rather than through reflection, so a scalar field costs no boxing and no map insert.
NewDecoder does not take ownership of src.Reader; the caller closes it, if it needs closing, once done with every decoder Split hands out.
func NewEncoder ¶
func NewEncoder(_ options.Config) (formatio.RecordEncoder, error)
NewEncoder returns a JSON encoder for canonical records. cfg is unused; nothing about JSON output is configurable.
func NewRawSource ¶
NewRawSource opens src for raw passthrough: each dispatched document is one line, handed to the sink as-is. NewRawSource does not take ownership of src.Reader; the caller closes it, if it needs closing, once done with the returned source.
func TimestampMicros ¶
TimestampMicros renders an epoch timestamp in microseconds as an ISO-8601 instant.
func TimestampMillis ¶
TimestampMillis renders an epoch timestamp in milliseconds as an ISO-8601 instant.
func TimestampNanos ¶
TimestampNanos renders an epoch timestamp in nanoseconds as an ISO-8601 instant.
Types ¶
type ObjectDecoder ¶
type ObjectDecoder struct {
// contains filtered or unexported fields
}
ObjectDecoder decodes one flat JSON object document at a time into canonical records, reusable across many lines without per-line allocation.
func NewObjectDecoder ¶
func NewObjectDecoder() *ObjectDecoder
NewObjectDecoder returns a reusable flat-object JSON decoder.