From: Thomas Gazagnaire Date: Mon, 11 Jan 2010 17:44:38 +0000 (+0000) Subject: [rpc-light] Add some basic RPC int functions. X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=ec485083019f124249d86e7fc7d3c96b053f8d4e;p=xcp%2Fxen-api-libs.git [rpc-light] Add some basic RPC int functions. This patch adds rpc_of_{int,int32,int64} and {int,int32,int64}_of_rpc Signed-off-by: Thomas Gazagnaire --- diff --git a/rpc-light/rpc.ml b/rpc-light/rpc.ml index 380ab3f..5c87bfb 100644 --- a/rpc-light/rpc.ml +++ b/rpc-light/rpc.ml @@ -42,14 +42,30 @@ let rec to_string t = match t with let rpc_of_t x = x let rpc_of_int64 i = Int i +let rpc_of_int32 i = Int (Int64.of_int32 i) +let rpc_of_int i = Int (Int64.of_int i) let rpc_of_bool b = Bool b let rpc_of_float f = Float f let rpc_of_string s = String s let t_of_rpc x = x -let int64_of_rpc = function Int i -> i | _ -> failwith "int64_of_rpc" +let int64_of_rpc = function + | Int i -> i + | String s -> Int64.of_string s + | _ -> failwith "int64_of_rpc" +let int32_of_rpc = function + | Int i -> Int64.to_int32 i + | String s -> Int32.of_string s + | _ -> failwith "int32_of_rpc" +let int_of_rpc = function + | Int i -> Int64.to_int i + | String s -> int_of_string s + | _ -> failwith "int_of_rpc" let bool_of_rpc = function Bool b -> b | _ -> failwith "bool_of_rpc" -let float_of_rpc = function Float f -> f | _ -> failwith "float_of_rpc" +let float_of_rpc = function + | Float f -> f + | String s -> float_of_string s + | _ -> failwith "float_of_rpc" let string_of_rpc = function String s -> s | _ -> failwith "string_of_rpc" type callback = string list -> t -> unit diff --git a/rpc-light/rpc.mli b/rpc-light/rpc.mli index ba12ef7..76a6745 100644 --- a/rpc-light/rpc.mli +++ b/rpc-light/rpc.mli @@ -30,6 +30,12 @@ val to_string : t -> string val int64_of_rpc : t -> int64 val rpc_of_int64 : int64 -> t +val int32_of_rpc : t -> int32 +val rpc_of_int32 : int32 -> t + +val int_of_rpc : t -> int +val rpc_of_int : int -> t + val bool_of_rpc : t -> bool val rpc_of_bool : bool -> t