Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Periodically flush the buf to the Writer. #78

Open
abourget opened this issue Oct 3, 2018 · 1 comment · May be fixed by #133
Open

Periodically flush the buf to the Writer. #78

abourget opened this issue Oct 3, 2018 · 1 comment · May be fixed by #133
Assignees
Labels
enhancement New feature or request

Comments

@abourget
Copy link

abourget commented Oct 3, 2018

Hi and thanks for the lib.

My goal is to start pushing JSON to an io.Writer while it's being JIT encoded. I noticed that EncodeObject calls enc.Write() and manages the error, that MarshalJSONObject doesn't return an error and that when calling enc.Write() myself (from within a MarshalJSONObject() func), there's no place to bubble up the error.

Surely I'm doing something a bit off here.. but I simply want to flush the buf between rows (say I have 200,000 such rows, which are objects). I also wonder how the buf would handle the getPreviousRune if I were to Write() before my Array is closed.

any tips would help, thanks a lot!

@abourget
Copy link
Author

abourget commented Oct 3, 2018

What I'm currently doing:

	enc.AddArrayKey("rows", gojay.EncodeArrayFunc(func(enc *gojay.Encoder) {
		lastIdx := len(r.Rows) - 1
		for idx, row := range r.Rows {
			enc.EncodeObject(row) // this flushes objects in between..
			if idx != lastIdx {
				enc.AppendByte(',')
			}
		}
	}))

which seems to work :)

@francoispqt francoispqt self-assigned this Oct 18, 2018
@francoispqt francoispqt added the enhancement New feature or request label Oct 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants