collab-common 0.0.7

Code shared by collab's client and server
Documentation
use serde::{Deserialize, Serialize};

use crate::encode::ShouldCompress;
use crate::{ClientMessage, PeerId};

/// TODO: docs
#[derive(Debug, Serialize, Deserialize)]
pub enum ServerMessage {
    /// Sent by the server when after a new peer joined the session. This is
    /// sent to all the peers except the one that joined.
    PeerJoined(PeerId),

    /// Sent by the server to inform the remaining peers that a peer has left
    /// the session.
    PeerLeft(PeerId),

    /// TODO: docs
    Relayed(ClientMessage),

    /// TODO: docs
    SessionStateRequest {
        /// TODO: docs
        requested_by: PeerId,
    },
}

impl ShouldCompress for ServerMessage {
    #[inline]
    fn should_compress(&self) -> bool {
        match self {
            Self::Relayed(client_msg) => client_msg.should_compress(),
            _ => false,
        }
    }
}

impl AsRef<ServerMessage> for ServerMessage {
    #[inline]
    fn as_ref(&self) -> &Self {
        self
    }
}