Need help for implementing multi-protocol in the same port (by using tokio)


Hello, I intend to implement a service that supports multi-protocol in the same port.
These protocols must contain HTTP+H2 and a binary protocol (for example ssh).
When a user sent a request, the application must detect which protocol is correct, after that suitable codec must be chosen.

I have no good idea how stream’s data can be check without polling.

I have an idea: I can implement one Encoder/Decoder for these protocols with an enum data type, but I’m sure it’s not really good idea.

enum StrangeProto {
    H1: http1,
    H2: http2,
    WebSocket: ws,
    Ssh: ssh,

impl Decoder for StrangeProto {
    type Item = Self;
    type Error = io::Error;



I will so thankful for your valuable comments.