From 319ce05d699478558245015cba78d9f229b83301 Mon Sep 17 00:00:00 2001 From: Benedikt Constantin Radtke Date: Tue, 20 Jun 2017 11:11:41 +0200 Subject: [PATCH] handle both number and string ids fixes #360 --- src/server.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/server.rs b/src/server.rs index 2206982f403..ffeca1ff818 100644 --- a/src/server.rs +++ b/src/server.rs @@ -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!())) + } } )* $(