Documentation ¶
Overview ¶
encodingiter defines iterator source/collector that corresponds to std library `encoding` and all its descendants (`encoding/*`)
Index ¶
- func CsvReader(r *csv.Reader) iter.Seq2[[]string, error]
- func Decode[V any, Dec interface{ ... }](dec Dec) iter.Seq2[V, error]
- func Encode[V any, Enc interface{ ... }](enc Enc, seq iter.Seq[V]) error
- func JsonDecoder(dec *json.Decoder) iter.Seq2[json.Token, error]
- func Write[V any](w io.Writer, marshaler func(v V, written int) ([]byte, error), seq iter.Seq[V]) (n int, er error)
- func Write2[K, V any](w io.Writer, marshaler func(k K, v V, written int) ([]byte, error), ...) (n int, er error)
- func WriteBinaryMarshaler[Enc encoding.BinaryMarshaler](w io.Writer, sep []byte, seq iter.Seq[Enc]) (n int, err error)
- func WriteTextMarshaler[Enc encoding.TextMarshaler](w io.Writer, sep []byte, seq iter.Seq[Enc]) (n int, err error)
- func XmlDecoder(dec *xml.Decoder) iter.Seq2[xml.Token, error]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CsvReader ¶
CsvReader returns an iterator over csv lines. Unlike JsonDecoder or XmlDecoder, the iterator does not stop on first error since it could yield csv.ErrFieldCount with partial record and continue to next line.
io.EOF is excluded from result.
func Decode ¶
Decode returns an iterator over consecutive decode results of dec.
The iterator stops if and only if dec returns io.EOF. Handling other errors is caller's responsibility. If the first error should stop the iterator, use hiter.LimitUntil, hiter.LimitAfter or even *errbox.Box.
func Encode ¶
Encode writes consecutive decode results of all values from seq. The first error stops the iteration.
func JsonDecoder ¶
JsonDecoder returns an iterator over json tokens. The first non-nil error encountered stops iteration after yielding it. io.EOF is excluded from result.
func Write ¶
func Write[V any](w io.Writer, marshaler func(v V, written int) ([]byte, error), seq iter.Seq[V]) (n int, er error)
Write writes all values from seq by marshaling it through marshaler. It returns the number of byte written to w. If marshaler or io.Writer returns an error it stops the iteration and the function returns the error with numbers of written bytes so far.
The marshaler receives each value from seq and accumulative number of bytes written.
func Write2 ¶
func WriteBinaryMarshaler ¶
func WriteBinaryMarshaler[Enc encoding.BinaryMarshaler](w io.Writer, sep []byte, seq iter.Seq[Enc]) (n int, err error)
WriteBinaryMarshaler writes all calling results of encoding.BinaryMarshaler.MarshalBinary from seq to w. It returns the number of bytes written to w and an error first encountered.
func WriteTextMarshaler ¶
func WriteTextMarshaler[Enc encoding.TextMarshaler](w io.Writer, sep []byte, seq iter.Seq[Enc]) (n int, err error)
WriteTextMarshaler writes all calling results of encoding.TextMarshaler.MarshalText from seq to w. It returns the number of bytes written to w and an error first encountered.
func XmlDecoder ¶
XmlDecoder returns an iterator over xml tokens. The first non-nil error encountered stops iteration after yielding it. io.EOF is excluded from result. The caller should call xml.CopyToken before going to next iteration if they need to retain tokens.
Types ¶
This section is empty.