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

Allow deserializing a request and serializing a response using streams #39

Open
ansman opened this issue Dec 14, 2019 · 5 comments · May be fixed by #41
Open

Allow deserializing a request and serializing a response using streams #39

ansman opened this issue Dec 14, 2019 · 5 comments · May be fixed by #41

Comments

@ansman
Copy link

ansman commented Dec 14, 2019

To avoid having to first create an intermediary JSON string it would be great if an InputStream/OutputStream could be used to parse requests and serialize responses. Seeing as you are using gson already it would likely be a minor change.

I'd be happy to open a PR if this is something you feel worth implementing.

@Fleker
Copy link
Member

Fleker commented Dec 16, 2019

I would be interested in seeing how this may be used.

@ansman
Copy link
Author

ansman commented Dec 16, 2019

val request = inputStream.use { app.createRequest(it) }
val response = app.handleRequest(request, headers).get()
outputStream.use { response.writeTo(it) }

That would be the rough outline.

@Fleker
Copy link
Member

Fleker commented Dec 16, 2019

Is there an advantage to doing this? I would like to see if there's a use case for it.

@ansman
Copy link
Author

ansman commented Dec 16, 2019

The advantage is to not having to first convert the whole body into a string and then parsing it as JSON. It would save memory and time. This is not a big issue as the bodies are likely pretty small but since it's already supported by Gson is seems beneficial to just expose it.

@Fleker
Copy link
Member

Fleker commented Dec 16, 2019

I guess if it's slightly more efficient that would be neat, as long as the API doesn't change and tests succeed a PR would be appreciated.

ansman added a commit to ansman/actions-on-google-java that referenced this issue Dec 17, 2019
ansman added a commit to ansman/actions-on-google-java that referenced this issue Dec 17, 2019
ansman added a commit to ansman/actions-on-google-java that referenced this issue Dec 17, 2019
ansman added a commit to ansman/actions-on-google-java that referenced this issue Dec 17, 2019
ansman added a commit to ansman/actions-on-google-java that referenced this issue Dec 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants