use crate::{
errors::ParseError,
udp::{
agent::{agent_update::AgentUpdate, coarse_location_update::CoarseLocationUpdate},
chat::chat_from_simulator::ChatFromSimulator,
core::disable_simulator::DisableSimulator,
},
ui::{
camera_position::CameraPosition, chat_from_viewer::ChatFromUI, errors::SessionError,
land_update::LandUpdate, login_event::Login, login_response::LoginResponse, logout::Logout,
mesh_update::MeshUpdate,
},
};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(tag = "type", content = "data")] pub enum UIResponse {
Login(Login),
ChatFromViewer(ChatFromUI),
Logout(Logout),
AgentUpdate(AgentUpdate),
}
impl UIResponse {
pub fn to_bytes(&self) -> Vec<u8> {
serde_json::to_vec(self).expect("Failed to serialize UIResponse")
}
pub fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> {
serde_json::from_slice(bytes).map_err(ParseError::SerdeError)
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(tag = "type", content = "data")] pub enum UIMessage {
ChatFromSimulator(ChatFromSimulator),
CoarseLocationUpdate(CoarseLocationUpdate),
LoginResponse(LoginResponse),
MeshUpdate(MeshUpdate),
Error(SessionError),
DisableSimulator(DisableSimulator),
LandUpdate(LandUpdate),
CameraPosition(CameraPosition),
}
impl UIMessage {
pub fn to_bytes(&self) -> Vec<u8> {
serde_json::to_vec(self).expect("Failed to serialize UIMessage")
}
pub fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> {
serde_json::from_slice(bytes).map_err(ParseError::SerdeError)
}
}