-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
x/mobile/bind: support slices of supported structs #13445
Comments
It will not be impossible and eventually it should be supported. I don't know anyone who's currently working on this problem. |
yeah this is the most frustrating issue for me right now |
Do you have any ideas when this will be done? What I could do? I tried and failed using: https://golang.org/pkg/container/list/ as an alternative |
+1 |
This is stopping me from using gomobile in anything worthwhile at the moment |
@scisci - If you don't mind can you please share across a gist on how you handle the problem currently as said? My requirement would be to return an array/slice of custom modal class objects with 4 string properties. |
hi @ioArchman, I made a quick repo here: https://github.com/scisci/go-mobile-collection If you think it can work for you, you will probably want to fork it and modify the render.go function to add/remove the methods you want on your collection wrapper. Feel free to make a comment on the project if you have any questions. Its pretty directly adapted from another tutorial on go generics, which you can find here http://www.onebigfluke.com/2014/12/generic-programming-go-generate.html Keep in mind, I don't consider this a good solution. It feels hacky working with a wrapper on the objective-c/swift side, but it does work. Really would prefer something that feels more natural. |
Thanks @scisci. Will look into this and try utilizing for now. Agreed on your last point too. |
hi @hyangah, do you have any hints on how this would be technically implemented in case someone wanted to attempt it from outside the gomobile team? |
👍 |
This is very limiting. |
Is this still on the road map? I found this library and would like to use it, but this issue may be keep me from using gomobile. |
It seems this is a show-stopper for many people. Are there any plans to support this? |
I just ran into this, and it would be great to be able to support slices. |
Just linking the stack overflow question here : https://stackoverflow.com/questions/44382115/golang-gomobile-tool-for-cross-platform-slices-of-struct-return-type |
have any update for this issue? |
Will there be any news? |
Currently no one is working on the x/mobile project and adding this feature is not a small project. Not ideal but need to work around by writing a wrapper package for binding, or using what @scisci mentioned for now. |
Does the project have a future? |
It's community supported at this point, so its future depends on you. There are others from the community working on it, but not full time. |
Anyone currently working on this? If not, could you give some pointers where to start with this? |
As a really slow and dumb bypass, you could serialize the data into JSON, pass the string and unserialize it on the other side. Use this only as a last resort, though. |
A workaround from my real project. Maybe will helpful for someone.
Android side:
|
A workaround with
Usage in go:
On Android you can use this extension to convert it to a
|
Is there any news? I was very surprised that this isn't implemented by default, I need to make very ugly workarounds to make my binding work. |
Is there any news? |
Adds code generation for supporting slices of structs in gobind. Fixes golang/go#13445 NOTE: This PR isn't quite done yet, I'm having some trouble getting the testing environment set up. It seems like the default test environment is a bit outdated? In any case, could I use this PR's CI to iterate on test failures? Open to other suggestions as well.
I've implemented most of the work required for slices of structs here: golang/mobile#101 I could certainly use some help on the final stretch though, especially if you've managed to get the gobind test environment working correctly. In particular, I think the last bits necessary are to:
|
Change https://go.dev/cl/583196 mentions this issue: |
@kevmo314 Hi, I’m willing to help finish the work on the Objective-C side. Could you provide me with some guidance on how to collaborate? |
@makivlach thank you, i fixed my code in gomobile |
I also encountered this issue, and due to this problem, I might not be able to use gomobile to achieve the functionality I want. |
I'm not sure this is helpful for this thread as I think it's solely about structs, but maybe gives a light to someone? Just as an idea, if it's an array of strings, one could put it all in the same string and separate each by a special character, like "|". Or a non-printable one, like the null character. If it's numbers that's worse - but can still be done. With a byte array. You convert the numbers to bytes and you know each number has for example 4 bytes. Then you can divide them back to ints in whatever language you're using Go with. And to separate, you could use a combination of bytes that won't be a number for sure (for example 5 random bytes - if the numbers are 4 bytes, you'd use 5 bytes to separate). Also works for random bytes. I separated a stream of bytes (output of a shell command: the exit code, stdout and stderr all sent in the same byte array out of Go to Java) by a random big array of bytes (50 random bytes I think?). Then in Java I just got the first 4 bytes and converted to int and separated the rest with the byte array and the first was the stdout and the 2nd the stderr. Specifically for structs, an idea is to have a function add a new struct to a Go-internal array. So you'd have a function with as many parameters as the struct and that function adds to a Go array. Each struct must have an ID (or use its index). Then there's a getter for the struct by its ID. That's how I'm doing with an array of structs. Maybe this can help someone (?). |
@Edw590 This approach feels somewhat like what protobuf does, doesn’t it? 🤔 But still interesting though. |
FWIW we're just using gomobile to start GRPC server, and then generate stubs for Swift side to talk with Go code using GRPC. This solved so many issues it is not even funny (e.g. gomobile default of 'if field is not supported, we ignore it' bit us in the ass so many times.. same also with some name mangling issues). We get all datatsructures protobuf supports too ;-) |
@fingon Cool solution! Have you tested the overhead (both CPU and RAM) of running an additional gRPC server compared to using pure Gomobile? |
It is quite performant. We have also backup plan of defining GRPC channel which just calls the gomobile'd function (instead of using TCP+HTTP/2) with arbitrary byte arrays to avoid networking, but so far it has not been necessary. We have heavy Go backend + lightweight Swift (and eventually Android) UI. |
Just want to know if it will ever be possible to support slices of supported. I currently have to write a wrapper object around an array to pass it back and forth between IOS and Go.
The text was updated successfully, but these errors were encountered: