collab-common 0.0.7

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

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

/// TODO: docs
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SessionResponse {
    requested_by: PeerId,
    sent_by: PeerId,
    session: Session,
}

impl SessionResponse {
    /// Returns the [`Session`].
    #[inline(always)]
    pub fn into_session(self) -> Session {
        self.session
    }

    /// Creates a new `SessionResponse` message.
    #[cfg(feature = "__client")]
    #[inline(always)]
    pub fn new(
        requested_by: PeerId,
        sent_by: PeerId,
        session: Session,
    ) -> Self {
        Self { requested_by, sent_by, session }
    }

    /// Returns the [`PeerId`] of the peer that requested the [`Session`].
    #[inline(always)]
    pub fn requested_by(&self) -> PeerId {
        self.requested_by
    }

    /// Returns the [`PeerId`] of the peer that sent the [`Session`].
    #[inline(always)]
    pub fn sent_by(&self) -> PeerId {
        self.sent_by
    }

    /// Returns the [`Session`].
    #[inline(always)]
    pub fn session(&self) -> &Session {
        &self.session
    }
}

impl ShouldCompress for SessionResponse {
    #[inline]
    fn should_compress(&self) -> bool {
        true
    }
}