Conversation
achille-roussel
left a comment
There was a problem hiding this comment.
Looking great overall 👍
One last comment, what do you think about using a sub-command of objconv for the CLI? (objconv generate)?
I can see how a syntax like this could be convenient as well:
objconv generate github.com/segmentio/pkg.Type
It can output to stdout by default, then keep the overwrite with the -o option you have right now.
| v = int64(uv) | ||
| case objconv.Float: | ||
| var fv float64 | ||
| fv, err = p.ParseFloat() |
There was a problem hiding this comment.
Should we check that the fractional part is zero as well?
This could help => https://golang.org/pkg/math/#Modf
There was a problem hiding this comment.
Ah that's what the double cast was for: float64(int64(fv)) != fv. this also catches very large numbers that get clobbered on a cast to int64
| @@ -0,0 +1,235 @@ | |||
| package util | |||
There was a problem hiding this comment.
How about naming the package genutil? Seems like it could communicate a little better what it's intended to be used for?
Could be a good idea to add a doc.go with a package documentation stating that the functions are here to support generated code and should not be accessed directly.
| } | ||
|
|
||
| func (d *%[3]s) Decode() (%[4]s, error) { | ||
| return d.decode_%[5]s() |
There was a problem hiding this comment.
Is using a _ required here? golint usually complains about that.
| return walkType(typeObj.Type()), nil | ||
| } | ||
|
|
||
| func GenerateDecode(path string, typ string) { |
There was a problem hiding this comment.
How about having a signature based on io.Writer? Maybe something like this:
func WriteDecoder(w io.Writer, path, typ string) error
This adds a new
objconvgenentrypoint that generates a optimized decoder for a specific type. Since the decoder doesn't need to use reflection and can return all results by-value, it attains a significant speedup from the generic parsing.Since this is a prototype, I'd like to get some feedback on the approach I took. Any and all suggestions and feedback are welcome. This is a pretty big feature, so I'd like everyone to be on board with it.
Sample benchmark on a structure with strings, times, and nested arrays
What's supported right now:
time.TimeWhat's not supported right now:
time.Duration[]byte/[N]bytespecial caseWhat definitely needs to be done before this could be merged:
jsonandobjconvstruct tagsgoimports/gofmtitWhat would be nice to clean up before this is merged:
github.com/segmentio/objconv/generate/utilpackage