Checkpoint
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
use bitcode::{Decode, Encode};
|
||||
|
||||
/// Represents a message in the Nye wire protocol.
|
||||
#[derive(Debug, Clone, Encode, Decode)]
|
||||
pub struct StreamMessage {
|
||||
/// The unique identifier of the stream, used to correlate requests and responses.
|
||||
pub stream_id: u64,
|
||||
|
||||
/// The type of the message, represented as a string.
|
||||
pub data: Message,
|
||||
}
|
||||
|
||||
/// Represents the data contained in a message in the Nye wire protocol.
|
||||
#[derive(Debug, Clone, Encode, Decode)]
|
||||
pub enum Message {
|
||||
/// Represents a request message in the Nye wire protocol.
|
||||
Request(MessageRequest),
|
||||
|
||||
/// Represents a response message in the Nye wire protocol.
|
||||
Response(MessageResponse),
|
||||
}
|
||||
|
||||
impl Message {
|
||||
/// Returns the kind of the message.
|
||||
///
|
||||
/// Returns:
|
||||
/// [`MessageKind`] - the kind of the message.
|
||||
pub fn kind(&self) -> MessageKind {
|
||||
match self {
|
||||
Message::Request(request) => MessageKind::Request(request.kind()),
|
||||
Message::Response(response) => MessageKind::Response(response.kind()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents the kind of a message in the Nye wire protocol.
|
||||
#[derive(Debug, Clone, Encode, Decode, PartialEq, Eq)]
|
||||
pub enum MessageKind {
|
||||
Request(MessageRequestKind),
|
||||
Response(MessageResponseKind),
|
||||
}
|
||||
|
||||
/// Represents a request message in the Nye wire protocol.
|
||||
///
|
||||
/// Only sent from the client to the daemon.
|
||||
#[derive(Debug, Clone, Encode, Decode)]
|
||||
pub enum MessageRequest {
|
||||
Setup,
|
||||
}
|
||||
|
||||
impl MessageRequest {
|
||||
/// Returns the kind of the message request.
|
||||
///
|
||||
/// Returns:
|
||||
/// [`MessageRequestKind`] - the kind of the message request.
|
||||
pub fn kind(&self) -> MessageRequestKind {
|
||||
match self {
|
||||
MessageRequest::Setup => MessageRequestKind::Setup,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MessageRequest> for Message {
|
||||
fn from(request: MessageRequest) -> Self {
|
||||
Message::Request(request)
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents the kind of a message request in the Nye wire protocol.
|
||||
#[derive(Debug, Clone, Encode, Decode, PartialEq, Eq)]
|
||||
pub enum MessageRequestKind {
|
||||
Setup,
|
||||
}
|
||||
|
||||
/// Represents a response message in the Nye wire protocol.
|
||||
///
|
||||
/// Only sent from the daemon to the client.
|
||||
#[derive(Debug, Clone, Encode, Decode)]
|
||||
pub enum MessageResponse {
|
||||
Setup,
|
||||
}
|
||||
|
||||
impl MessageResponse {
|
||||
/// Returns the kind of the message response.
|
||||
///
|
||||
/// Returns:
|
||||
/// [`MessageResponseKind`] - the kind of the message response.
|
||||
pub fn kind(&self) -> MessageResponseKind {
|
||||
match self {
|
||||
MessageResponse::Setup => MessageResponseKind::SetupFinished,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MessageResponse> for Message {
|
||||
fn from(response: MessageResponse) -> Self {
|
||||
Message::Response(response)
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents the kind of a message response in the Nye wire protocol.
|
||||
#[derive(Debug, Clone, Encode, Decode, PartialEq, Eq)]
|
||||
pub enum MessageResponseKind {
|
||||
SetupFinished,
|
||||
}
|
||||
Reference in New Issue
Block a user