Conversation
| flags.StringVar(&opts.source, "source", ".", "package path for source structs") | ||
|
|
||
| // TODO: make this a positional arg, set a Usage func to document it | ||
| flags.StringVar(&opts.moduleWorkDir, "modworkdir", "", "module working directory to run from") |
There was a problem hiding this comment.
Needed this so the E2E test could use it after converting internal/e2e into a submodule.
| // S4 Workload // for testing struct-to-ptr for slices | ||
| // T1 timestamp.Timestamp // for testing struct-to-struct for time | ||
| // T2 *timestamp.Timestamp // for testing ptr-to-ptr for time | ||
| T3 *timestamp.Timestamp // for testing ptr-to-struct for time |
There was a problem hiding this comment.
This is only handling pointer-protobufs to non-pointer-stdlib conversions for now, which is the most common.
| // S4 *Workload // for testing struct-to-ptr for slices | ||
| // T1 time.Time // for testing struct-to-struct for time | ||
| // T2 *time.Time // for testing ptr-to-ptr for time | ||
| T3 time.Time // for testing ptr-to-struct for time |
There was a problem hiding this comment.
This is the target side of the conversion.
| } | ||
| } | ||
|
|
||
| func astAssignMulti(left, right []ast.Expr) ast.Stmt { |
There was a problem hiding this comment.
Variation of astAssign that works for generating foo, bar := gir, zim instead of just foo := gir
| case special.ProtobufDuration && special.ProtobufDirection == DirFrom: | ||
| // pointer-to-struct | ||
| return newAssignMultiStmtUserFunc( | ||
| []ast.Expr{left, &ast.Ident{Name: "_"}}, |
There was a problem hiding this comment.
We specifically ignore the error here by assigning to the blank identifier.
There was a problem hiding this comment.
Also in 2 more functions below.
| rawKind, ok := computeAssignment(field.Type(), sourceField.SourceType) | ||
| if !ok { | ||
| assignErrFn(nil) | ||
| rawKind, err := computeAssignment(field.Type(), sourceField.SourceType, imports) |
There was a problem hiding this comment.
I really should've had this return an error instead of a boolean the first time, so i fixed that since i found it useful to return a real error in the case where you are using protobufs but not in the exact way this PR handles.
| sourceField.ConvertFuncName(DirFrom), | ||
| kind.Direct, | ||
| kind.Convert, | ||
| kind.Special.ReverseDirection(), |
There was a problem hiding this comment.
We always generate both the TO and FROM functions at the same time, so when we apply the protobuf conversion in reverse we have to flip the direction so the function we use switches as well.
| packages.NeedFiles | | ||
| packages.NeedCompiledGoFiles | | ||
| packages.NeedImports | | ||
| packages.NeedModule | |
There was a problem hiding this comment.
TODO: I was going to figure out how to use this attribute to determine protobuf versions so the generated code could freely switch to different conversion functions if needed.
| return false | ||
| } | ||
|
|
||
| func isAnyProtobufTimeOrDuration(types ...types.Type) bool { |
There was a problem hiding this comment.
These are the key functions here. They infer if we should be trying the special casing of protobuf time/duration conversions.
| t.M8[k] = y | ||
| } | ||
| } | ||
| t.T3, _ = ptypes.Timestamp(s.T3) |
There was a problem hiding this comment.
examples of the generated code in action
dhiaayachi
left a comment
There was a problem hiding this comment.
I don't think this will be merged soon, please re-request a review if the status of this change.
Fixes #1