encode.go
func (e *StreamEncoder) Encode(v interface{}) error {
	if err := e.Open(-1); err != nil {
		return err
	}

	if e.max >= 0 && e.cnt >= e.max {
		return fmt.Errorf("objconv: too many values sent to a stream encoder exceed the configured limit of %d", e.max)
	}

	if !e.oneshot && e.cnt != 0 {
		e.err = e.Emitter.EmitArrayNext()
	}

	if e.err == nil {
		e.err = (Encoder{
			Emitter:     e.Emitter,
			SortMapKeys: e.SortMapKeys,
		}).Encode(v)

		if e.cnt++; e.max >= 0 && e.cnt >= e.max {
			e.Close()
		}
	}

	return e.err
}
func (e *StreamEncoder) Encode(v interface{}) error {
	if err := e.Open(-1); err != nil {
		return err
	}

	if e.max >= 0 && e.cnt >= e.max {
		return fmt.Errorf("objconv: too many values sent to a stream encoder exceed the configured limit of %d", e.max)
	}

	if !e.oneshot && e.cnt != 0 {
		e.err = e.Emitter.EmitArrayNext()
	}

	if e.err == nil {
		e.err = (Encoder{
			Emitter:     e.Emitter,
			SortMapKeys: e.SortMapKeys,
		}).Encode(v)

		if e.cnt++; e.max >= 0 && e.cnt >= e.max {
			e.Close()
		}
	}

	return e.err
}
// Encode writes v to the stream, encoding it based on the emitter configured
// on e.