aboutsummaryrefslogtreecommitdiff
path: root/net/src/codec/websocket.rs
blob: 867681096da7ffbf51708c3b26f1b672a3ee33df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use crate::Result;
use async_tungstenite::tungstenite::Message;

pub trait WebSocketCodec:
    WebSocketDecoder<DeItem = Self::Item>
    + WebSocketEncoder<EnItem = Self::Item>
    + Send
    + Sync
    + 'static
    + Unpin
{
    type Item: Send + Sync;
}

pub trait WebSocketEncoder {
    type EnItem;
    fn encode(&self, src: &Self::EnItem) -> Result<Message>;
}

pub trait WebSocketDecoder {
    type DeItem;
    fn decode(&self, src: &Message) -> Result<Option<Self::DeItem>>;
}