-
Notifications
You must be signed in to change notification settings - Fork 39
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
Add support for discriminated unions and optional data #6
base: master
Are you sure you want to change the base?
Conversation
Thanks for the PR. I'll review it this weekend. |
ping :) |
Hi, any chance to get this reviewed? I need to release libraries based on this, and I would like to avoid a permanent fork if possible at all. |
Ping. :) This is just what I need, but like rasky I'd rather use the main repo if possible. |
Ping again on this :) I've been using my fork with success in production, I think the modifications in this PR are correct. If you're concerned with styling, let me know. |
Can you redo this PR and I'll push for it to go in. |
Thanks @rasky for working on this. I'd love to see this PR land in the main repo. What is it that needs to be done here to get this in ? Thanks. |
The usage of absolute import paths in testsuite is not compatible with allowing a package to easily fork. One has to replace all global paths in test files. I tried to use relative import paths such as "../xdr2" but there appears to be a Go 1.5 bug for which the internal_test.go functions TstEncode/TstDecode are not exposed to tests.
Unions are represented by normal Go structs, using different struct tags to pinpoint the union discriminant, and to select the various cases. Since more struct tags were required, I introduced a new general tag called "xdr" with key/value options, and thus changed the previous "xdropaque" struct tag into the new canonical name form `xdr:"opaque=false"`, while retaining the previous form for backward compatibility.
In Go, they are expressed through indirection: a pointer to the actualy data, that can be nil to express that the field is missing. The field must be marked with the new tag option "optional", because otherwise it is automatically indirected as per default behaviour of marshallers.
Hi, I've rebased the PR and also completed coverage (100%). I would appreciate if you could merge this PR @marcopeereboom @davecgh |
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 am mostly ok with this diff. Some minor nits.
@davecgh can you have a peek too?
@@ -14,14 +14,12 @@ | |||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |||
*/ | |||
|
|||
package xdr_test | |||
package xdr |
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 am sure @davecgh has a reason to split test from package. Seems like a gratuitous change.
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 point is that this style of testing makes forking impossible, because of the absolute import path used to import the xdr2
package. And unfortunately, you can't use relative imports in this context.
So for instance, the CI would be unable to test this pull request because it would use the upstream version of the xdr2
package, rather than the version in this branch.
xdr2/tag_test.go
Outdated
@@ -0,0 +1,45 @@ | |||
/* | |||
* Copyright (c) 2012-2014 Dave Collins <[email protected]> |
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.
Pretty sure @davecgh didn't write this :-) Date is wrong to boot.
xdr2/tag.go
Outdated
@@ -0,0 +1,73 @@ | |||
/* | |||
* Copyright (c) 2012-2014 Dave Collins <[email protected]> |
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.
Wrong author and date.
xdr2/tag_test.go
Outdated
@@ -0,0 +1,45 @@ | |||
/* | |||
* Copyright (c) 2012-2014 Dave Collins <[email protected]> |
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.
Wrong author and date.
I've updated the copyrights. |
👍 ran into the need for this recently, would be great to have it merged. cc @fdawg4l |
I spoke to @davecgh about this and we want it if it becomes xdr3. xdr2 API is set in stone and we don't want to modify it. |
Can you please clarify how the API is modified? AFAICT it's retro compatible in pure go 1 sense |
any news? I need xdr3 package and i need to distinglish between string and string pointer.
|
I will look at this soon. Remind me again if I forget. |
@marcopeereboom ping... |
@davecgh can you merge this on create xdr3 ? I'm really need this pr and it sit in this repo 2 years... |
I still don’t see why xdr3 is needed for a perfectly backward compatible PR. |
ok @davecgh please merge it, or if you don't interests in this package add unmaintained info to readme . |
Commit 7592fd7 makes use of the `xdr:"union"` and `xdr:"unioncase=N"` annotations that were submitted in a pull request that has not been merged upstream to davecgh/go-xdr: davecgh/go-xdr#6 Without support for these annotations, the code crashes at runtime. Signed-off-by: Anders Kaseorg <[email protected]>
Commit 7592fd7 makes use of the `xdr:"union"` and `xdr:"unioncase=N"` annotations that were submitted in a pull request that has not been merged upstream to davecgh/go-xdr: davecgh/go-xdr#6 Without support for these annotations, the code is unable to parse a valid FSINFO reply. Signed-off-by: Anders Kaseorg <[email protected]>
Commit 7592fd7 makes use of the `xdr:"union"` and `xdr:"unioncase=N"` annotations that were submitted in a pull request that has not been merged upstream to davecgh/go-xdr: davecgh/go-xdr#6 Without support for these annotations, the code is unable to parse a valid FSINFO reply. Signed-off-by: Anders Kaseorg <[email protected]>
bumpity humpidy dump |
This PR adds support for:
In both cases, the code relies on struct tags to convey the required metadata information. Please see the individual commits for more information.