-
Notifications
You must be signed in to change notification settings - Fork 11
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
Consider having high-level interfaces #3
Comments
I like this idea but I'm not so sure how this could be achieved. I remember struggling with the fact that variable number of arguments & named arguments just didn't translate well to Rust. Looking at some python examples, I can see that RPC functions are simply python functions with decorations that do a bunch of magic that I assume are :
I really like this style as it offloads any validation from the API endusers. Do you think this is something that could be do-able in Rust ? Im thinking with macros, we might be able to generate code that does the "deserialization"/validation of WampArgs/KwArgs and call Rust RPC endpoints without them needing any WAMPisms tacked on ? The only downside is that Rust doesnt have KwArgs so we would still need to pass some dict as a parameter if the RPC endpoint uses named arguments. For simplifications at the call site, im guessing macros could also be used to convert regular Rust types into a vec of WampArgs. Maybe it could be done for KwArgs too... |
Hi guys, just had been looking around for WAMP and Rust, stumbled across the repo here (), and wanted to chime into this discussion .. comment .. rgd
WAMP as in AutobahnPython and Crossbar.io has 2 ways of avoiding serialization overhead:
The former feature is called "payload transparency", and instead of In Autobahn for client side, this is exposed via "payload codecs" Two higher level uses of above is
yes, Autobahn-Python features function decorators that can register/subscribe the python function, plus type check arguments and auto-map exception classes from/to WAMP error URIs AutobahnPython also includes experimental code for the Flatbuffers based WAMP messages stuff: https://github.com/crossbario/autobahn-python/tree/master/autobahn/wamp/flatbuffers Here is a WAMP Event as written as Flatbuffers: This code also illustrates the distinction of the serialization/parsing question between 1) application payload and 2) WAMP message itself In summary: If you combine Flatbuffers for WAMP messages plus Flatbuffers for application payload, you can have zero-serialization, zero-copy for RPC/PubSub app payload in Rust. And finally: using Flatbuffers for WAMP application payload definition also allows to specify the whole WAMP application interfaces with Procedures and Topics in Flatbuffers, eg https://github.com/wamp-proto/wamp-xbr/blob/master/work/schema/example1.fbs Now, I should probably add: this Flatbuffers stuff isn't in the WAMP spec, and is experimental. However, I think it demonstrates one option how we could evolve WAMP and implementations to support zero-copy/serialization and strongly typed interfaces in WAMP .. |
Payload transparency isn't in the spec for a reason. All participating clients need to be able to encode/decode the payload format independently. While this is a feature of Crossbar (A commercial product I might add) specifically, it doesn't make a lot of sense to create a generic wamp client library for use with a specific router, and which can only communicate with other clients using the same payload encoding. If a client using Flatbuffers could send/receive data transparently with one that wasn't as is the case with the serialization formats described in the spec that wouldn't be a problem, but as of now Crossbar.io is the only router I know of that has any amount of Flatbuffer support, and it is only through a technique that skirts the requirements of the router to be able to convert payloads between the different clients requested serialization types. (JSON/MsgPack). That doesn't really go to the original question which was about the user facing API. In that vein, I would say for the most part leave the API as low level as possible and allow users to implement higher level abstractions over it, as the library implementor cannot possibly foresee all applicable use cases. I could see maybe wrapping the payload in a struct rather than having it hang out in a generic tuple, but when it comes down to it, the users should be able to decide the data they are putting into Args, and KwArgs, because there is no telling what other clients they may be trying to interact with, and what expectations they might have for the payload structure. pub struct Payload(Option<WampArgs>, Option<WampKwArgs>);
impl Payload {
// Implement interface to interact with data in the Args, and KwArgs
}
async fn echo(input: Payload) -> Result<Payload, WampError> {
} |
Indeed that is one reason why WAMP is using negotiated serializers and router-side automatic re-serialization between clients using different serializers. Nothing is "free", so this capability has a price:
Because of 1a and 2., "payload transparency mode" is an additional and optional feature that we might add to WAMP. Which would make the price (1/2 above) paid disappear, or better: pay a different price;) which is:
crossbar - including this feature - is completely open-source these days https://github.com/crossbario/crossbar/blob/master/LICENSE
This is a formal specification of a user facing WAMP based API: https://github.com/wamp-proto/wamp-xbr/blob/master/work/schema/example1.fbs Using this you can generate payload bindings for dozens of languages in clients. Obviously, the router does not need that schema, as it doesn't touch or even interpret the app payload. I should probably add: if the router also had the FBS schema of the app payload traveling per URI, then the router could also auto-translate to dynamic serializers like JSON or CBOR from and to Flatbuffers. This would only work when no end-to-end encryption is also used of course. |
I think, we should be able to use
RawValue
instead of a parsedValue
(see #2), and thus avoid unnecessary deserialization (see https://github.com/pandaman64/serde-query/). I would also like to have a more high-level interface to kwargs, so instead of:I would prefer to have an option to write:
And from the caller side instead of:
use:
The text was updated successfully, but these errors were encountered: