Skip to content

Commit

Permalink
handle both number and string ids
Browse files Browse the repository at this point in the history
  • Loading branch information
Trolldemorted committed Jun 20, 2017
1 parent 9ca162f commit 319ce05
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,15 @@ macro_rules! messages {
match name {
$(
$method_str => {
let id = ls_command.get("id").unwrap().as_u64().unwrap() as usize;
Ok(ServerMessage::Request(Request{id: id, method: Method::$method_name$((params_as!($method_arg)))* }))
let id_value = ls_command.get("id").unwrap();
if id_value.is_u64() {
let id = ls_command.get("id").unwrap().as_u64().unwrap() as usize;
Ok(ServerMessage::Request(Request{id: id, method: Method::$method_name$((params_as!($method_arg)))* }))
} else if id_value.is_string() {
Ok(ServerMessage::Request(Request{id: usize::from_str_radix(id_value.as_str().unwrap(), 10).unwrap(), method: Method::$method_name$((params_as!($method_arg)))* }))
} else {
Err(ParseError::new(ErrorKind::InvalidData, "Id is not a number or string", id!()))
}
}
)*
$(
Expand Down

0 comments on commit 319ce05

Please sign in to comment.