Closed DevasiaThomas closed 2 years ago
I will look into it
I think I have found the problem, assuming that you were using the bincode
binary encoding (which is the default one). There's good news and bad news.
The bad news is that the problem, unfortunately, is caused by bincode
not supporting tagging with #[serde(tag = "type")]
macro (the issue can be found here).
However, the good news is that if you change the encoding to json and disable the default bincode format, you will get this functionality. The change is really simple, in all of your crates that uses toy-rpc
, make sure to disable the default features (actually the only default feature is "serde_bincode"
) and add "serde_json"
to the list of features. Below are some examples
[dependencies.toy-rpc]
version = "0.8.4"
default-features = false # Make sure default feature is disabled everywhere
[dependencies.toy-rpc]
version = "0.8.4"
default-features = false # Make sure default feature is disabled everywhere
features = [ "serde_json", "tokio_runtime", "server", "anyhow" ] # Add "serde_json" to features
[dependencies.toy-rpc]
version = "0.8.4"
default-features = false # Make sure default feature is disabled everywhere
features = [ "serde_json", "tokio_runtime", "client"] # Add "serde_json" to features
@minghuaw Thank you for the answer and your suggestion :) Moving from bincode to json seems a like a loss within the rust ecosystem and hence I ended up writing custom deserializers to support the externally tagged variants and ended up adding an identifying fields that weren't enums to help deserialize. Nevertheless, I hope this thread helps others :)
btw @minghuaw can you DM me on linkedIn (its on my profile) Didn't see a private contact method on yours :)
@DevasiaThomas do you mind using email instead? I don't check my LinkedIn that often. My email address is: michael.wu1107@gmail.com
Hi @minghuaw :)
Using the Consumer service in the examples, if I try to send an enum that looks like this
things are fine, but as soon as I add/remove tagging to the enum as described here, it fails to work.. I can't tell if the connection dropped or some parsing error happened. it's very silent.
The reason I am using tagging is because downstream I have to serialize to json(and java libraries don't know what externally tagged representations are - I have to create container classes :D) and I don't really want to maintain different versions of the protocol tbh.