Add real networked message type

This commit is contained in:
Lucien Greathouse
2019-09-29 20:16:54 -07:00
parent fd22482f06
commit ab8aa89f2a
2 changed files with 30 additions and 5 deletions

View File

@@ -94,7 +94,17 @@ impl<F: ImfsFetcher> ApiService<F> {
// TODO: Transform applied patch sets into subscribe responses // TODO: Transform applied patch sets into subscribe responses
let api_messages = messages let api_messages = messages
.into_iter() .into_iter()
.map(|_message| SubscribeMessage) .map(|message| {
let removed_instances = message.removed;
let added_instances = HashMap::new(); // TODO
let updated_instances = Vec::new(); // TODO
SubscribeMessage {
removed_instances,
added_instances,
updated_instances,
}
})
.collect(); .collect();
json_ok(SubscribeResponse { json_ok(SubscribeResponse {

View File

@@ -16,9 +16,24 @@ pub(crate) const SERVER_VERSION: &str = env!("CARGO_PKG_VERSION");
/// Current protocol version, which is required to match. /// Current protocol version, which is required to match.
pub const PROTOCOL_VERSION: u64 = 3; pub const PROTOCOL_VERSION: u64 = 3;
// TODO /// Message returned by Rojo API when a change has occurred.
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct SubscribeMessage; #[serde(rename_all = "camelCase")]
pub struct SubscribeMessage<'a> {
pub removed_instances: Vec<RbxId>,
pub added_instances: HashMap<RbxId, Instance<'a>>,
pub updated_instances: Vec<InstanceUpdate>,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct InstanceUpdate {
pub id: RbxId,
pub changed_name: Option<String>,
pub changed_class_name: Option<String>,
pub changed_properties: HashMap<String, RbxValue>,
pub changed_metadata: Option<InstanceMetadata>,
}
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
@@ -73,10 +88,10 @@ pub struct ReadResponse<'a> {
/// Response body from /api/subscribe/{cursor} /// Response body from /api/subscribe/{cursor}
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct SubscribeResponse { pub struct SubscribeResponse<'a> {
pub session_id: SessionId, pub session_id: SessionId,
pub message_cursor: u32, pub message_cursor: u32,
pub messages: Vec<SubscribeMessage>, pub messages: Vec<SubscribeMessage<'a>>,
} }
/// General response type returned from all Rojo routes /// General response type returned from all Rojo routes