-
Notifications
You must be signed in to change notification settings - Fork 188
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
Generate request body struct #30
Conversation
Running all the tests in the same cargo workspace allows test runners to avoid recompiling dependencies every time. This allows us to drop parallel tests which seemed to be causing OOMs.
To enable serialization & deserialization, we generate synthetic structs representing the request body. Currently, the serialization method returns a stub, however, in a subsequent PR, serde will be used to generate actual request bodies.
91538fd
to
c7b9c09
Compare
@@ -52,6 +62,27 @@ abstract class HttpProtocolGenerator( | |||
} | |||
} | |||
|
|||
open fun toBodyImpl(implBlockWriter: RustWriter, inputShape: StructureShape, inputBody: StructureShape?) { | |||
if (inputBody != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if this is null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the body is an empty string / empty vec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(to clarify, this code isn't the final code, just a placeholder until all the serialization code lands)
Then the body-checking part of the protocol tests will be enabled
// TODO: use serde to serialize the body | ||
if (inputBody != null) { | ||
write("let _ = self.body();") | ||
} | ||
write("String::new()") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're not going to handle this now, maybe replace this with unimplmented!()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would normally, but for testing purposes I wanted to actually call this method from the protocol tests and I want the protocol tests to keep passing. Rest assured it will be replaced with real code shortly.
} | ||
} | ||
} | ||
implBlockWriter.rustBlock("pub fn build_body(&self) -> String") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that the return type should be a String
. I can imagine several non-UTF-8 inputs and sources; I think that a Vec<u8>
can work here?
If not a Vec<u8>
, bytes::Bytes
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's an interesting thought—I don't have especially strong feelings. Will probably stay away from bytes::Bytes
for the moment, although I think we may end up there (or somewhere similar eventually).
My thinking today is that for protocols that are guaranteed to return UTF-8 data, we might as well indicate that. (eg. that way you know these bytes are safe to print, etc.)
}.mapNotNull { | ||
it.body |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you leave a comment describing what does .mapNotNull
does? Is it a monadic bind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a kotlin built in that is equivalent to map { xyz }.filter { it != null }
Issue #, if available: #29
Currently stacked on #28 but will be unstacked once that lands.
Description of changes:
This PR is split into 2 commits:
LibRs
generator to support generating private modulesTo enable serialization & deserialization, we generate synthetic structs representing the request body. Currently, the serialization method returns a stub, however, in a subsequent PR, serde will be used to generate actual request bodies.
Full output can be viewed in the build artifact, but as an example:
Inside the operation impl:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.