(************************************************************
 * WARNING!
 *
 * This file is generated by ocamlrpcgen from the source file
 * test.x
 *
 ************************************************************)
type x = 
     { 
       mutable x_a : Netnumber.int4;
       mutable x_b : Netnumber.int8;
     }
and e = 
     Netnumber.int4
and u = 
     [ | `oNe of (Netnumber.int4) | `Two of (Netnumber.int8) ]
and e2 = 
     Netnumber.int4
and u2 = 
     [ | `one_ of (Netnumber.int4) | `two_ of (Netnumber.int8) ]
and y = 
     ( Netnumber.int4 * Netnumber.int8 )
;;
exception X_x of x
exception X_e of e
exception X_u of u
exception X_e2 of e2
exception X_u2 of u2
exception X_y of y
;;
let enum_one = (Netnumber.int4_of_int (1));;
let enum_two = (Netnumber.int4_of_int (2));;
let one_ = (Netnumber.int4_of_int (1));;
let two_ = (Netnumber.int4_of_int (2));;
let ( +! ) = Xdr.safe_add
let ( *! ) = Xdr.safe_mul
;;
let rec _to_x (x:Xdr.xdr_value) : x =
  ( let f s =
      { x_a = (fun x -> ( match x with
                          | Xdr.XV_int x -> x
                          | _ -> raise Xdr.Dest_failure
                        ))
              s.(0); 
        x_b = (fun x -> ( match x with
                          | Xdr.XV_hyper x -> x
                          | _ -> raise Xdr.Dest_failure
                        ))
              s.(1); 
      } in
    ( match x with
      | Xdr.XV_struct_fast x -> f x
      | Xdr.XV_direct(X_x x, _) -> x
      | _ -> raise Xdr.Dest_failure
    )
  )
and _of_x (x:x) : Xdr.xdr_value = Xdr.XV_direct(X_x x, _sizeexpr_x x)
and _sizeexpr_x (x:x) : int = 12
and _size_x (x:exn) : int =
  match x with
  | X_x y -> _sizeexpr_x y
  | _ -> raise Xdr.Dest_failure
and _writeexpr_x (x:x) s p : unit =
  ( let x = x.x_a in Netnumber.BE.write_int4_unsafe s !p ( x); p := !p + 4;
    ()
  );
  ( let x = x.x_b in Netnumber.BE.write_int8_unsafe s !p ( x); p := !p + 8;
    ()
  );
  ()
and _write_x (x:exn) s p : unit =
  match x with
  | X_x y -> _writeexpr_x y s p
  | _ -> raise Xdr.Dest_failure
and _readexpr_x s p p_end =
  ( let x0 =
      ( if !p > p_end-4 then raise Netnumber.Out_of_range;
        let x = Netnumber.BE.read_int4_unsafe s !p in
        p := !p + 4;
        ( x)
      ) in
    let x1 =
      ( if !p > p_end-8 then raise Netnumber.Out_of_range;
        let x = Netnumber.BE.read_int8_unsafe s !p in
        p := !p + 8;
        ( x)
      ) in
    {  x_a = x0; x_b = x1;
    }
  )
and _read_x s p p_end : exn = X_x(_readexpr_x s p p_end)
and _to_e (x:Xdr.xdr_value) : e =
  ( match x with
    | Xdr.XV_enum_fast 0 -> (Netnumber.int4_of_int (1))
    | Xdr.XV_enum_fast 1 -> (Netnumber.int4_of_int (2))
    | Xdr.XV_direct(X_e x, _) -> x
    | _ -> raise Xdr.Dest_failure
    
  )
and _of_e (x:e) : Xdr.xdr_value =
  (match Netnumber.int32_of_int4 x with
  | (1l) -> Xdr.XV_enum_fast 0
  | (2l) -> Xdr.XV_enum_fast 1
  | _ -> failwith "RPC/XDR error: invalid enum value for type `e'"
  )
and _sizeexpr_e (x:e) : int = 4
and _size_e (x:exn) : int =
  match x with
  | X_e y -> _sizeexpr_e y
  | _ -> raise Xdr.Dest_failure
and _writeexpr_e (x:e) s p : unit =
  if not(List.mem (Netnumber.int32_of_int4 x) [ 1l; 2l ]) then
    raise(Xdr.Xdr_failure "invalid enum");
  Netnumber.BE.write_int4_unsafe s !p x;
  p := !p + 4;
  ()
and _write_e (x:exn) s p : unit =
  match x with
  | X_e y -> _writeexpr_e y s p
  | _ -> raise Xdr.Dest_failure
and _readexpr_e s p p_end =
  ( if !p > p_end-4 then raise Netnumber.Out_of_range;
    let x = Netnumber.BE.read_int4_unsafe s !p in
    p := !p + 4;
    if not(List.mem (Netnumber.int32_of_int4 x) [ 1l; 2l ]) then
      raise(Xdr.Xdr_format "invalid enum");
    x
  )
and _read_e s p p_end : exn = X_e(_readexpr_e s p p_end)
and _to_u (x:Xdr.xdr_value) : u =
  ( match x with
    | Xdr.XV_direct(X_u x, _) -> x
    | _ ->
    ( let k, x = Xdr.dest_xv_union_over_enum_fast x in
      match k with
      | 0 ->
            `oNe ( match x with
                   | Xdr.XV_int x -> x
                   | _ -> raise Xdr.Dest_failure
                 )
      | 1 ->
            `Two ( match x with
                   | Xdr.XV_hyper x -> x
                   | _ -> raise Xdr.Dest_failure
                 )
      | _ -> Xdr.raise_xdr_format_undefined_descriminator()
      :> [ | `oNe of _ | `Two of _ ]
    )
  )
and _of_u (x:u) : Xdr.xdr_value = Xdr.XV_direct(X_u x, _sizeexpr_u x)
and _sizeexpr_u (x:u) : int =
  ( 4 +! ( match x with
           | `oNe x -> 4
           | `Two x -> 8 )
  )
and _size_u (x:exn) : int =
  match x with
  | X_u y -> _sizeexpr_u y
  | _ -> raise Xdr.Dest_failure
and _writeexpr_u (x:u) s p : unit =
  ( match x with
    | `oNe x ->
          Netnumber.BE.write_int4_unsafe s !p (Netnumber.int4_of_int (1));
          p := !p + 4;
          Netnumber.BE.write_int4_unsafe s !p ( x);
          p := !p + 4;
          ()
    | `Two x ->
          Netnumber.BE.write_int4_unsafe s !p (Netnumber.int4_of_int (2));
          p := !p + 4;
          Netnumber.BE.write_int8_unsafe s !p ( x);
          p := !p + 8;
          ()
  );
  ()
and _write_u (x:exn) s p : unit =
  match x with
  | X_u y -> _writeexpr_u y s p
  | _ -> raise Xdr.Dest_failure
and _readexpr_u s p p_end =
  ( if !p > p_end-4 then raise Netnumber.Out_of_range;
    let d0 = Netnumber.BE.read_int4_unsafe s !p in
    p := !p + 4;
    ( let d = Netnumber.int32_of_int4 d0 in
      match d with
      | (1l) ->
            let x =
              ( if !p > p_end-4 then raise Netnumber.Out_of_range;
                let x = Netnumber.BE.read_int4_unsafe s !p in
                p := !p + 4;
                ( x)
              ) in
            `oNe x
      | (2l) ->
            let x =
              ( if !p > p_end-8 then raise Netnumber.Out_of_range;
                let x = Netnumber.BE.read_int8_unsafe s !p in
                p := !p + 8;
                ( x)
              ) in
            `Two x
      | _ -> Xdr.raise_xdr_format_undefined_descriminator()
      :> [ | `oNe of _ | `Two of _ ]
    )
  )
and _read_u s p p_end : exn = X_u(_readexpr_u s p p_end)
and _to_e2 (x:Xdr.xdr_value) : e2 =
  ( match x with
    | Xdr.XV_enum_fast 0 -> (Netnumber.int4_of_int (1))
    | Xdr.XV_enum_fast 1 -> (Netnumber.int4_of_int (2))
    | Xdr.XV_direct(X_e2 x, _) -> x
    | _ -> raise Xdr.Dest_failure
    
  )
and _of_e2 (x:e2) : Xdr.xdr_value =
  (match Netnumber.int32_of_int4 x with
  | (1l) -> Xdr.XV_enum_fast 0
  | (2l) -> Xdr.XV_enum_fast 1
  | _ -> failwith "RPC/XDR error: invalid enum value for type `e2'"
  )
and _sizeexpr_e2 (x:e2) : int = 4
and _size_e2 (x:exn) : int =
  match x with
  | X_e2 y -> _sizeexpr_e2 y
  | _ -> raise Xdr.Dest_failure
and _writeexpr_e2 (x:e2) s p : unit =
  if not(List.mem (Netnumber.int32_of_int4 x) [ 1l; 2l ]) then
    raise(Xdr.Xdr_failure "invalid enum");
  Netnumber.BE.write_int4_unsafe s !p x;
  p := !p + 4;
  ()
and _write_e2 (x:exn) s p : unit =
  match x with
  | X_e2 y -> _writeexpr_e2 y s p
  | _ -> raise Xdr.Dest_failure
and _readexpr_e2 s p p_end =
  ( if !p > p_end-4 then raise Netnumber.Out_of_range;
    let x = Netnumber.BE.read_int4_unsafe s !p in
    p := !p + 4;
    if not(List.mem (Netnumber.int32_of_int4 x) [ 1l; 2l ]) then
      raise(Xdr.Xdr_format "invalid enum");
    x
  )
and _read_e2 s p p_end : exn = X_e2(_readexpr_e2 s p p_end)
and _to_u2 (x:Xdr.xdr_value) : u2 =
  ( match x with
    | Xdr.XV_direct(X_u2 x, _) -> x
    | _ ->
    ( let k, x = Xdr.dest_xv_union_over_enum_fast x in
      match k with
      | 0 ->
            `one_ ( match x with
                    | Xdr.XV_int x -> x
                    | _ -> raise Xdr.Dest_failure
                  )
      | 1 ->
            `two_ ( match x with
                    | Xdr.XV_hyper x -> x
                    | _ -> raise Xdr.Dest_failure
                  )
      | _ -> Xdr.raise_xdr_format_undefined_descriminator()
      :> [ | `one_ of _ | `two_ of _ ]
    )
  )
and _of_u2 (x:u2) : Xdr.xdr_value = Xdr.XV_direct(X_u2 x, _sizeexpr_u2 x)
and _sizeexpr_u2 (x:u2) : int =
  ( 4 +! ( match x with
           | `one_ x -> 4
           | `two_ x -> 8 )
  )
and _size_u2 (x:exn) : int =
  match x with
  | X_u2 y -> _sizeexpr_u2 y
  | _ -> raise Xdr.Dest_failure
and _writeexpr_u2 (x:u2) s p : unit =
  ( match x with
    | `one_ x ->
          Netnumber.BE.write_int4_unsafe s !p (Netnumber.int4_of_int (1));
          p := !p + 4;
          Netnumber.BE.write_int4_unsafe s !p ( x);
          p := !p + 4;
          ()
    | `two_ x ->
          Netnumber.BE.write_int4_unsafe s !p (Netnumber.int4_of_int (2));
          p := !p + 4;
          Netnumber.BE.write_int8_unsafe s !p ( x);
          p := !p + 8;
          ()
  );
  ()
and _write_u2 (x:exn) s p : unit =
  match x with
  | X_u2 y -> _writeexpr_u2 y s p
  | _ -> raise Xdr.Dest_failure
and _readexpr_u2 s p p_end =
  ( if !p > p_end-4 then raise Netnumber.Out_of_range;
    let d0 = Netnumber.BE.read_int4_unsafe s !p in
    p := !p + 4;
    ( let d = Netnumber.int32_of_int4 d0 in
      match d with
      | (1l) ->
            let x =
              ( if !p > p_end-4 then raise Netnumber.Out_of_range;
                let x = Netnumber.BE.read_int4_unsafe s !p in
                p := !p + 4;
                ( x)
              ) in
            `one_ x
      | (2l) ->
            let x =
              ( if !p > p_end-8 then raise Netnumber.Out_of_range;
                let x = Netnumber.BE.read_int8_unsafe s !p in
                p := !p + 8;
                ( x)
              ) in
            `two_ x
      | _ -> Xdr.raise_xdr_format_undefined_descriminator()
      :> [ | `one_ of _ | `two_ of _ ]
    )
  )
and _read_u2 s p p_end : exn = X_u2(_readexpr_u2 s p p_end)
and _to_y (x:Xdr.xdr_value) : y =
  ( let f s =
      ( (fun x -> ( match x with
                    | Xdr.XV_int x -> x
                    | _ -> raise Xdr.Dest_failure
                  ))
        s.(0),
        (fun x -> ( match x with
                    | Xdr.XV_hyper x -> x
                    | _ -> raise Xdr.Dest_failure
                  ))
        s.(1)
      ) in
    ( match x with
      | Xdr.XV_struct_fast x -> f x
      | Xdr.XV_direct(X_y x, _) -> x
      | _ -> raise Xdr.Dest_failure
    )
  )
and _of_y (x:y) : Xdr.xdr_value = Xdr.XV_direct(X_y x, _sizeexpr_y x)
and _sizeexpr_y (x:y) : int = 12
and _size_y (x:exn) : int =
  match x with
  | X_y y -> _sizeexpr_y y
  | _ -> raise Xdr.Dest_failure
and _writeexpr_y (x:y) s p : unit =
  ( let (x,_) = x in Netnumber.BE.write_int4_unsafe s !p ( x); p := !p + 4;
    ()
  );
  ( let (_,x) = x in Netnumber.BE.write_int8_unsafe s !p ( x); p := !p + 8;
    ()
  );
  ()
and _write_y (x:exn) s p : unit =
  match x with
  | X_y y -> _writeexpr_y y s p
  | _ -> raise Xdr.Dest_failure
and _readexpr_y s p p_end =
  ( let x0 =
      ( if !p > p_end-4 then raise Netnumber.Out_of_range;
        let x = Netnumber.BE.read_int4_unsafe s !p in
        p := !p + 4;
        ( x)
      ) in
    let x1 =
      ( if !p > p_end-8 then raise Netnumber.Out_of_range;
        let x = Netnumber.BE.read_int8_unsafe s !p in
        p := !p + 8;
        ( x)
      ) in
    (x0,x1)
  )
and _read_y s p p_end : exn = X_y(_readexpr_y s p p_end)
;;
let xdrt_x =
  Xdr.X_rec("x",
    Xdr.X_direct(Xdr.X_struct
                   [   ("A", (Xdr.X_int));   ("B", (Xdr.X_hyper)); ],
      _read_x,
      _write_x,
      _size_x))
;;
let xdrt_e =
  Xdr.X_rec("e",
    Xdr.X_direct(Xdr.X_enum
                   [
                     ("ONE", (Netnumber.int4_of_int (1)));
                     ("TWO", (Netnumber.int4_of_int (2)));
                   ],
      _read_e,
      _write_e,
      _size_e))
;;
let xdrt_u =
  Xdr.X_rec("u",
    Xdr.X_direct(Xdr.X_union_over_enum(
                   (Xdr.X_enum
                      [
                        ("ONE", (Netnumber.int4_of_int (1)));
                        ("TWO", (Netnumber.int4_of_int (2)));
                      ]),
                   [
                     "ONE", (Xdr.X_int);
                     "TWO", (Xdr.X_hyper);
                   ],
                   None),
    _read_u,
    _write_u,
    _size_u))
;;
let xdrt_e2 =
  Xdr.X_rec("e2",
    Xdr.X_direct(Xdr.X_enum
                   [
                     ("ONE_", (Netnumber.int4_of_int (1)));
                     ("TWO_", (Netnumber.int4_of_int (2)));
                   ],
      _read_e2,
      _write_e2,
      _size_e2))
;;
let xdrt_u2 =
  Xdr.X_rec("u2",
    Xdr.X_direct(Xdr.X_union_over_enum(
                   (Xdr.X_enum
                      [
                        ("ONE_", (Netnumber.int4_of_int (1)));
                        ("TWO_", (Netnumber.int4_of_int (2)));
                      ]),
                   [
                     "ONE_", (Xdr.X_int);
                     "TWO_", (Xdr.X_hyper);
                   ],
                   None),
    _read_u2,
    _write_u2,
    _size_u2))
;;
let xdrt_y =
  Xdr.X_rec("y",
    Xdr.X_direct(Xdr.X_struct
                   [   ("A", (Xdr.X_int));   ("B", (Xdr.X_hyper)); ],
      _read_y,
      _write_y,
      _size_y))
;;

