-
Notifications
You must be signed in to change notification settings - Fork 333
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
Need help - Ruby FFI and Go - Pointers and []Byte #542
Comments
I didn't know this would work with Go. This doesn't seem to be a particularly good path as you're disabling some of the protections provided by Go. I need to know more about your use case before I can provide much help. |
@tduehr Thanks for your response. We have developed some kind of workflow / state machine engine in ruby. In case that we won't re-develop all in Go again we are looking forward to just replace some intensive tasks in Go. Most of the time this means, we are running tasks from ruby in different queues handled by different ruby processes and want using "speedy" functions from Go. Let's say something like incoming request Rabbit Message Queues: A new message is posted to Queue A and then the first scripta process creates something like a CONFIG struct via Go function After that the binary dump of that CONFIG struct should be stored as messagebody to Queue B When scriptb processes the message, the messagebody should be instantiated again in another Go function to work with just instantiating the passed object. Hopefully you may understand what we are targetting |
Just to ensure - we already run this but need to convert for and back the Go object binary memory dump into a MIME encoded string. This consumes time and RAM. |
There is no way for FFI to know how large the memory allocated to a pointer on its own. If this is a data structure of some kind, you can define a subclass of |
From VarEncode there is no structure but |
That partially depends on they nature of the data in the array.
If it's a C string, then the pointer is fine and you can just call `read_string` off the pointer.
If there's another function you can call to obtain the length, it can be used as the argument to `read_string` to get a Ruby String containing the info.
Otherwise, you're best option is to modify the Go to accept `int*` and `byte**` to be set as part of the call.
|
Is is possible for you to give me a short code sample about |
I don't know how to pass by reference in Go. |
Hm ... that is just But how is that defined in Ruby? |
The argument to
|
for do the complementary work when passing from ruby: the ffi input type would be |
I am sorry to post such kind as question as an issue but hopefully some may take assist.
We do not know how to write a
go
(Golang) package that we can exchange binary data between Ruby and Go functions as arguments and results.Thanks to any help
Tom
The question is (partly) copied from StackExchange:
http://stackoverflow.com/questions/41204483/ruby-ffi-and-go-golang-how-to-get-and-set-a-binary-data-block-or-byte-array
sample.go:
sample.rb:
The text was updated successfully, but these errors were encountered: