Comments (7)
I just looked into this, and am trying to figure out why I changed it previously in ugorji/go-msgpack#10 (ie https://github.com/ugorji/go-msgpack/commit/5d4be733d472935cbe3158b74990deebedba2a78)
@smw1218 do you have any thoughts? From looking again at the spec for like 30 minutes, it seems to me that @dgryski is right and I should not have made the changes previously. Can you point to what we may be missing? If not, I think the right fix is what was there in the first place (ie what @dgryski suggests).
from go.
I have a fix in for this, and have tested it with your sample at https://github.com/dgryski/trifles/tree/master/msgrpc
A few things about your sample so it would work:
- Call RPC functions as Echo.Echo123 and Echo.EchoStruct. Without a . in the rpc request serviceMethod, we get an ill-formed argument error on the Go side. I'm not sure how to make it work compatibly with Python msgpack (which seems less flexible in allowing configuring a prefix for service methods).
The fix probably wouldn't go in for a few days because I was in the middle of adding very good support and performant support for BinaryMarshaler. (Supporting something like a BinaryMarshaler typically has a significant cost, as it involves extra conversions of reflect.Value to interface{} at top of each recursive function).
from go.
Yeah, sorry about the state of the tests. I just commited my testing directory so I could have something to point you at -- both clients were set up to talk to the Python server. Too bad about the name-spacing issue though. I might see if there's a way to fix that from the Python side (just because I'm curious..)
from go.
In order to be compatible with both the msgpack spec and the net/rpc lib, I think you needed to do some type checking. If the type passed in is a slice just pass it through. If not, wrap it as before.
That way, if a server requires multiple positional parameters, it's possible to pass an array in Go. But if the user passes in a non-array then it will wrap it in order to follow the spec.
from go.
Perfect. Now I remember. The solution before wasn't robust enough. I think I finally see it fully.
We need to treat and handle the different calling conventions.
A Go Service requires that it only takes one argument. Services in other languages may take multiple arguments. However, msgpackrpc requires that the arguments get passed as an array.
The solution is to have a way for the calling client using our library to denote that a service taking more than one argument is being called explicitly.
The simple way, is to pass an argument of a specific type. I'm calling that type MsgpackSpecRpcMultiArgs.
package codec
type MsgpackSpecRpcMultiArgs []interface{}
Sample Code:
Calling a service in python:
def Echo123(self, msg1, msg2, msg3):
return ("1:%s 2:%s 3:%s" % (msg1, msg2, msg3))
Code using our library to call it:
var reply string
var args codec.MsgpackSpecRpcMultiArgs = []interface{}{"foo1", "foo2", "foo3"}
err = client.Call("Echo123", args, &reply)
fmt.Println("reply=", reply)
Within the codec, if the argument to client.Call is of type codec.MsgpackSpecRpcMultiArgs, we assume that you are calling a service method that takes multiple arguments and do not wrap the arguments in a slice of 1 again.
Thinking it through this way shows that services in other methods do not have the limitation of having a dot in their service name. Only Go RPC Server requires a dot.
I've tested this with changes to your code. Now I have
- cli-py.go (calling python service via go client)
- cli-go.go (calling go service via go client)
- cli-py.py (calling python service via python client)
- cli-go.py (calling go service via python client)
- srv.go (go service)
- srv.py (python service)
All iterations work.
I'd checkin the code when I do a push early next week. Please let me know if there is some urgency - I'm done but want to let the other refactoring I did stew for a bit.
from go.
There's no urgency from my end.
from go.
This is now fixed by commit c61e583
from go.
Related Issues (20)
- Coverity Scan - Logically Dead code HOT 1
- missing go.sum entry needed to verify package HOT 1
- Vulnerability Issue - CWE 74 External Control of File Name or Path HOT 3
- unable to restore original data while using map[string]interface{} HOT 1
- omitempty handling for arrays disagrees with the standard encoding/json HOT 2
- codec.MsgpackHandle.RawToString is confusingly named HOT 2
- Go 1.20 - invalid memory address or nil pointer dereference HOT 5
- Msgpack deserialization with codecgen produces wrong result HOT 3
- Unexpected encoding with interface{} key using Canonical and MapKeyAsString.
- Decoding a slice of structs encoded as arrays into a slice of structs without the same number of fields HOT 2
- Duplicate key inside of a map triggers a "cannot decode unsigned integer" msgpack decode error HOT 1
- Efficient direct conversion between supported formats? HOT 2
- Expose Handle.Name() in some form through Encoder and Decoder for use by codec.Selfer HOT 1
- `io.ErrUnexpectedEOF` should be returned instead of `io.EOF` when only partial data is present
- Add `DecodeOptions.IntType` and `DecodeOptions.FloatType` ? HOT 1
- Docs do not seem to mention case-sensitive field handling
- mem leak? HOT 1
- Tests use rand.Intn(1) for boolean rand, but always returns 0
- Decoder accepts indefinite-length CBOR strings containing chunks with mismatched major types HOT 1
- UTF-8 validation isn't applied to CBOR text strings nested inside an indefinite-length text string HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go.