Browse Source

Replace rustc-serialize with serde.

wip
Titouan Rigoudy 4 years ago
parent
commit
27d0539a41
8 changed files with 28 additions and 155 deletions
  1. +1
    -2
      Cargo.lock
  2. +1
    -1
      client/Cargo.toml
  3. +2
    -6
      client/src/control/request.rs
  4. +10
    -30
      client/src/control/response.rs
  5. +8
    -52
      client/src/control/ws.rs
  6. +4
    -42
      client/src/room.rs
  7. +0
    -1
      proto/Cargo.toml
  8. +2
    -21
      proto/src/core/user.rs

+ 1
- 2
Cargo.lock View File

@ -1180,11 +1180,11 @@ dependencies = [
"log 0.4.14", "log 0.4.14",
"mio 0.6.23", "mio 0.6.23",
"parking_lot 0.8.0", "parking_lot 0.8.0",
"rustc-serialize",
"serde", "serde",
"serde_json", "serde_json",
"slab 0.2.0", "slab 0.2.0",
"solstice-proto", "solstice-proto",
"thiserror",
"threadpool", "threadpool",
"tokio 1.8.1", "tokio 1.8.1",
"tokio-codec", "tokio-codec",
@ -1209,7 +1209,6 @@ dependencies = [
"mio 0.6.23", "mio 0.6.23",
"parking_lot 0.8.0", "parking_lot 0.8.0",
"rust-crypto", "rust-crypto",
"rustc-serialize",
"serde", "serde",
"serde_json", "serde_json",
"slab 0.2.0", "slab 0.2.0",


+ 1
- 1
client/Cargo.toml View File

@ -14,11 +14,11 @@ futures = "0.3"
log = "^0.4" log = "^0.4"
mio = "^0.6" mio = "^0.6"
parking_lot = "^0.8" parking_lot = "^0.8"
rustc-serialize = "^0.3.17"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
slab = "^0.2" slab = "^0.2"
solstice-proto = { path = "../proto" } solstice-proto = { path = "../proto" }
thiserror = "1.0"
threadpool = "^1.0" threadpool = "^1.0"
tokio = { version = "1", features = ["full"] } tokio = { version = "1", features = ["full"] }
tokio-core = "^0.1" tokio-core = "^0.1"


+ 2
- 6
client/src/control/request.rs View File

@ -2,9 +2,7 @@ use serde::{Deserialize, Serialize};
/// This enumeration is the list of possible control requests made by the /// This enumeration is the list of possible control requests made by the
/// controller client to the client. /// controller client to the client.
#[derive(
Debug, PartialEq, Eq, RustcDecodable, RustcEncodable, Serialize, Deserialize,
)]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum Request { pub enum Request {
/// The controller wants to join a room. Contains the room name. /// The controller wants to join a room. Contains the room name.
RoomJoinRequest(String), RoomJoinRequest(String),
@ -21,9 +19,7 @@ pub enum Request {
} }
/// This structure contains the chat room message request from the controller. /// This structure contains the chat room message request from the controller.
#[derive(
Debug, PartialEq, Eq, RustcDecodable, RustcEncodable, Deserialize, Serialize,
)]
#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct RoomMessageRequest { pub struct RoomMessageRequest {
/// The name of the chat room in which to send the message. /// The name of the chat room in which to send the message.
pub room_name: String, pub room_name: String,


+ 10
- 30
client/src/control/response.rs View File

@ -4,9 +4,7 @@ use solstice_proto::User;
/// This enumeration is the list of possible control responses from the client /// This enumeration is the list of possible control responses from the client
/// to the controller. /// to the controller.
#[derive(
Debug, PartialEq, Eq, RustcDecodable, RustcEncodable, Serialize, Deserialize,
)]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum Response { pub enum Response {
LoginStatusResponse(LoginStatusResponse), LoginStatusResponse(LoginStatusResponse),
RoomJoinResponse(RoomJoinResponse), RoomJoinResponse(RoomJoinResponse),
@ -19,25 +17,19 @@ pub enum Response {
UserListResponse(UserListResponse), UserListResponse(UserListResponse),
} }
#[derive(
Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, Serialize, Deserialize,
)]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct RoomJoinResponse { pub struct RoomJoinResponse {
pub room_name: String, pub room_name: String,
} }
#[derive(
Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, Serialize, Deserialize,
)]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct RoomLeaveResponse { pub struct RoomLeaveResponse {
pub room_name: String, pub room_name: String,
} }
/// This enumeration is the list of possible login states, and the associated /// This enumeration is the list of possible login states, and the associated
/// information. /// information.
#[derive(
Debug, PartialEq, Eq, RustcDecodable, RustcEncodable, Serialize, Deserialize,
)]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum LoginStatusResponse { pub enum LoginStatusResponse {
/// The login request has been sent to the server, but the response hasn't /// The login request has been sent to the server, but the response hasn't
/// been received yet. /// been received yet.
@ -65,9 +57,7 @@ pub enum LoginStatusResponse {
/// This structure contains the list of all visible rooms, and their associated /// This structure contains the list of all visible rooms, and their associated
/// data. /// data.
#[derive(
Debug, PartialEq, Eq, RustcDecodable, RustcEncodable, Serialize, Deserialize,
)]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct RoomListResponse { pub struct RoomListResponse {
/// The list of (room name, room data) pairs. /// The list of (room name, room data) pairs.
pub rooms: Vec<(String, room::Room)>, pub rooms: Vec<(String, room::Room)>,
@ -75,9 +65,7 @@ pub struct RoomListResponse {
/// This structure contains a message said in a chat room the user is a member /// This structure contains a message said in a chat room the user is a member
/// of. /// of.
#[derive(
Debug, PartialEq, Eq, RustcDecodable, RustcEncodable, Serialize, Deserialize,
)]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct RoomMessageResponse { pub struct RoomMessageResponse {
/// The name of the room in which the message was said. /// The name of the room in which the message was said.
pub room_name: String, pub room_name: String,
@ -88,36 +76,28 @@ pub struct RoomMessageResponse {
} }
/// This struct describes the fact that the given user joined the given room. /// This struct describes the fact that the given user joined the given room.
#[derive(
Debug, PartialEq, Eq, RustcDecodable, RustcEncodable, Serialize, Deserialize,
)]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct RoomUserJoinedResponse { pub struct RoomUserJoinedResponse {
pub room_name: String, pub room_name: String,
pub user_name: String, pub user_name: String,
} }
/// This struct describes the fact that the given user left the given room. /// This struct describes the fact that the given user left the given room.
#[derive(
Debug, PartialEq, Eq, RustcDecodable, RustcEncodable, Serialize, Deserialize,
)]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct RoomUserLeftResponse { pub struct RoomUserLeftResponse {
pub room_name: String, pub room_name: String,
pub user_name: String, pub user_name: String,
} }
/// This struct contains the last known information about a given user. /// This struct contains the last known information about a given user.
#[derive(
Debug, PartialEq, Eq, RustcDecodable, RustcEncodable, Serialize, Deserialize,
)]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct UserInfoResponse { pub struct UserInfoResponse {
pub user_name: String, pub user_name: String,
pub user_info: User, pub user_info: User,
} }
/// This stuct contains the last known information about every user. /// This stuct contains the last known information about every user.
#[derive(
Debug, PartialEq, Eq, RustcDecodable, RustcEncodable, Serialize, Deserialize,
)]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct UserListResponse { pub struct UserListResponse {
pub user_list: Vec<(String, User)>, pub user_list: Vec<(String, User)>,
} }


+ 8
- 52
client/src/control/ws.rs View File

@ -1,9 +1,6 @@
use std::error;
use std::fmt;
use crossbeam_channel; use crossbeam_channel;
use rustc_serialize::json;
use solstice_proto::config; use solstice_proto::config;
use thiserror::Error;
use ws; use ws;
use super::request::*; use super::request::*;
@ -25,53 +22,12 @@ pub enum Notification {
} }
/// This error is returned when a `Sender` fails to send a control request. /// This error is returned when a `Sender` fails to send a control request.
#[derive(Debug)]
#[derive(Debug, Error)]
pub enum SendError { pub enum SendError {
/// Error encoding the control request.
JSONEncoderError(json::EncoderError),
/// Error sending the encoded control request to the websocket.
WebSocketError(ws::Error),
}
impl fmt::Display for SendError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match *self {
SendError::JSONEncoderError(ref err) => {
write!(fmt, "JSONEncoderError: {}", err)
}
SendError::WebSocketError(ref err) => {
write!(fmt, "WebSocketError: {}", err)
}
}
}
}
impl error::Error for SendError {
fn description(&self) -> &str {
match *self {
SendError::JSONEncoderError(_) => "JSONEncoderError",
SendError::WebSocketError(_) => "WebSocketError",
}
}
fn cause(&self) -> Option<&dyn error::Error> {
match *self {
SendError::JSONEncoderError(ref err) => Some(err),
SendError::WebSocketError(ref err) => Some(err),
}
}
}
impl From<json::EncoderError> for SendError {
fn from(err: json::EncoderError) -> Self {
SendError::JSONEncoderError(err)
}
}
impl From<ws::Error> for SendError {
fn from(err: ws::Error) -> Self {
SendError::WebSocketError(err)
}
#[error("error encoding response to JSON: {0}")]
JsonError(#[from] serde_json::Error),
#[error("error sending response on socket: {0}")]
WebSocketError(#[from] ws::Error),
} }
/// This struct is used to send control responses to the controller. /// This struct is used to send control responses to the controller.
@ -85,7 +41,7 @@ pub struct Sender {
impl Sender { impl Sender {
/// Queues up a control response to be sent to the controller. /// Queues up a control response to be sent to the controller.
pub fn send(&mut self, response: Response) -> Result<(), SendError> { pub fn send(&mut self, response: Response) -> Result<(), SendError> {
let encoded = json::encode(&response)?;
let encoded = serde_json::to_string(&response)?;
self.sender.send(encoded)?; self.sender.send(encoded)?;
Ok(()) Ok(())
} }
@ -141,7 +97,7 @@ impl ws::Handler for Handler {
}; };
// Decode the json control request. // Decode the json control request.
let control_request = match json::decode(&payload) {
let control_request = match serde_json::from_str(&payload) {
Ok(control_request) => control_request, Ok(control_request) => control_request,
Err(e) => { Err(e) => {
error!("Received invalid JSON message from controller: {}", e); error!("Received invalid JSON message from controller: {}", e);


+ 4
- 42
client/src/room.rs View File

@ -7,17 +7,7 @@ use serde::{Deserialize, Serialize};
use solstice_proto::{server, User}; use solstice_proto::{server, User};
/// This enumeration is the list of possible membership states for a chat room. /// This enumeration is the list of possible membership states for a chat room.
#[derive(
Clone,
Copy,
Debug,
Eq,
PartialEq,
RustcDecodable,
RustcEncodable,
Serialize,
Deserialize,
)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub enum Membership { pub enum Membership {
/// The user is not a member of this room. /// The user is not a member of this room.
NonMember, NonMember,
@ -33,17 +23,7 @@ pub enum Membership {
/// This enumeration is the list of visibility types for rooms that the user is /// This enumeration is the list of visibility types for rooms that the user is
/// a member of. /// a member of.
#[derive(
Clone,
Copy,
Debug,
Eq,
PartialEq,
RustcDecodable,
RustcEncodable,
Serialize,
Deserialize,
)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub enum Visibility { pub enum Visibility {
/// This room is visible to any user. /// This room is visible to any user.
Public, Public,
@ -54,16 +34,7 @@ pub enum Visibility {
} }
/// This structure contains a chat room message. /// This structure contains a chat room message.
#[derive(
Clone,
Debug,
Eq,
PartialEq,
RustcDecodable,
RustcEncodable,
Serialize,
Deserialize,
)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct Message { pub struct Message {
pub user_name: String, pub user_name: String,
pub message: String, pub message: String,
@ -72,16 +43,7 @@ pub struct Message {
/// This structure contains the last known information about a chat room. /// This structure contains the last known information about a chat room.
/// It does not store the name, as that is stored implicitly as the key in the /// It does not store the name, as that is stored implicitly as the key in the
/// room hash table. /// room hash table.
#[derive(
Clone,
Debug,
Eq,
PartialEq,
RustcDecodable,
RustcEncodable,
Serialize,
Deserialize,
)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct Room { pub struct Room {
/// The membership state of the user for the room. /// The membership state of the user for the room.
pub membership: Membership, pub membership: Membership,


+ 0
- 1
proto/Cargo.toml View File

@ -17,7 +17,6 @@ log = "^0.4"
mio = "^0.6" mio = "^0.6"
parking_lot = "^0.8" parking_lot = "^0.8"
rust-crypto = "^0.2.34" rust-crypto = "^0.2.34"
rustc-serialize = "^0.3.17"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
slab = "^0.2" slab = "^0.2"
thiserror = "^1.0" thiserror = "^1.0"


+ 2
- 21
proto/src/core/user.rs View File

@ -16,17 +16,7 @@ const STATUS_ONLINE: u32 = 3;
/// This enumeration is the list of possible user statuses. /// This enumeration is the list of possible user statuses.
#[derive( #[derive(
Clone,
Copy,
Debug,
Eq,
Ord,
PartialEq,
PartialOrd,
RustcDecodable,
RustcEncodable,
Serialize,
Deserialize,
Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Serialize, Deserialize,
)] )]
pub enum UserStatus { pub enum UserStatus {
/// The user if offline. /// The user if offline.
@ -94,16 +84,7 @@ impl ValueDecode for UserStatus {
/// This structure contains the last known information about a fellow user. /// This structure contains the last known information about a fellow user.
#[derive( #[derive(
Clone,
Debug,
Eq,
Ord,
PartialEq,
PartialOrd,
RustcDecodable,
RustcEncodable,
Serialize,
Deserialize,
Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Serialize, Deserialize,
)] )]
pub struct User { pub struct User {
/// The name of the user. /// The name of the user.


Loading…
Cancel
Save