1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use crate::io::codec::RRCodec;
use crate::io::provider::{Description, EntryId, Path};
use crate::io::transport::{DirectId, Envelope, Origin, WideEnvelope};
use meio_protocol::Protocol;
use serde::{Deserialize, Serialize};

pub type ClientReqId = DirectId<ClientProtocol>;

#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct ClientProtocol;

impl Protocol for ClientProtocol {
    type ToServer = Envelope<Self, ClientRequest>;
    // TODO: Consider to disallow broadcasts and change to ordinary `Envelope`
    type ToClient = WideEnvelope<Self, ClientResponse>;
    type Codec = RRCodec;
}

impl Origin for ClientProtocol {}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ClientRequest {
    //SubscribeProviders { active: bool },
    //SubscribePaths { provider: EntryId, active: bool },
    ControlStream { path: Path, active: bool },
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ClientResponse {
    Declare(EntryId),
    // TODO: Replace to `State/Delta` meta stream
    Paths(Vec<Description>),
    State(Vec<u8>),
    Delta(Vec<u8>),
    /// Stream closed/finished.
    Done,
}