Advertisement
Guest User

Untitled

a guest
Aug 17th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 4.32 KB | None | 0 0
  1. // Main
  2.  
  3. let dd = Self::get_ns2__AddressValidationRequest(json);
  4.         match dd {
  5.             Ok(v) => {
  6.                 let mut o = v.unwrap();
  7.                 let soap = unsafe { create_soap() };
  8.                 let base_url = "123";
  9.                 let mut sr: ns2__AddressValidationReply =
  10.                     unsafe { validate_address(soap, CString::new(base_url).unwrap().as_ptr(), &mut *o as *mut ns2__AddressValidationRequest) };
  11.             }
  12.             Err(e) => {
  13.                 return Err(vec!["kaka".to_owned()]);
  14.             }
  15.         }
  16.  
  17. //get_ns2__AddressValidationRequest
  18.  
  19. #[allow(bad_style)]
  20.     fn get_ns2__AddressValidationRequest(
  21.         json: &Value,
  22.     ) -> Result<Option<Box<ns2__AddressValidationRequest>>, Vec<String>> {
  23.        
  24.         let ClientDetail_res = Self::get_ns2__ClientDetail(json);
  25.         let ClientDetail;
  26.         match ClientDetail_res {
  27.             Ok(v) => {              
  28.                 ClientDetail = v;
  29.             }
  30.             Err(e) => {
  31.                 return Err(e);
  32.             }
  33.         }
  34.  
  35.         let root_ClientDetail_ov = if ClientDetail.is_some() {
  36.             &mut *ClientDetail.unwrap() as *mut ns2__ClientDetail
  37.         } else {
  38.             std::ptr::null_mut() as *mut ns2__ClientDetail
  39.         };
  40.  
  41.  
  42.         let mut seconds: i64 = 1555 as i64;
  43.  
  44.         let ret = Some(Box::new(ns2__AddressValidationRequest {
  45.             WebAuthenticationDetail: null_mut_ptr!(ns2__WebAuthenticationDetail),
  46.             ClientDetail: root_ClientDetail_ov,
  47.             TransactionDetail: null_mut_ptr!(ns2__TransactionDetail),
  48.             Version: null_mut_ptr!(ns2__VersionId),
  49.             InEffectAsOfTimestamp: item_as_mut_ptr!(seconds, ::std::os::raw::c_long),
  50.  
  51.             __sizeAddressesToValidate: AddressesToValidate_tmp.len() as i32,
  52.             AddressesToValidate: null_mut_ptr!(ns2__AddressToValidate),
  53.         }));
  54.  
  55.         Ok(ret)
  56.     }
  57.  
  58. // Cliet detail
  59.  
  60. #[allow(bad_style)]
  61.     fn get_ns2__ClientDetail(json: &Value) -> Result<Option<Box<ns2__ClientDetail>>, Vec<String>> {
  62.         let real = !json["ClientDetail"].is_null();
  63.         if !real {
  64.             return Err(vec![format!("Required obj '{}' not set", "ClientDetail")]);
  65.         }
  66.         let AccountNumber;
  67.         let AccountNumber_op =
  68.             Self::get_string("AccountNumber", &json["ClientDetail"]["AccountNumber"], true);
  69.         match AccountNumber_op {
  70.             Ok(v) => {
  71.                 AccountNumber = v;      
  72.             }
  73.             Err(e) => {
  74.                 return Err(e);
  75.             }
  76.         }
  77.         let IntegratorId;
  78.         let IntegratorId_op = Self::get_string("IntegratorId", &json["ClientDetail"]["IntegratorId"], false);
  79.         match IntegratorId_op {
  80.             Ok(v) => {
  81.                 IntegratorId = v;
  82.             }
  83.             Err(e) => {
  84.                 return Err(e);
  85.             }
  86.         }
  87.        
  88.         let MeterNumber;
  89.         let MeterNumber_op = Self::get_string("MeterNumber", &json["ClientDetail"]["MeterNumber"], true);
  90.         match MeterNumber_op {
  91.             Ok(v) => {
  92.                 MeterNumber = v;
  93.             }
  94.             Err(e) => {
  95.                 return Err(e);
  96.             }
  97.         }
  98.        
  99.         let ret = Some(Box::new(ns2__ClientDetail {
  100.             AccountNumber: AccountNumber,
  101.             MeterNumber: MeterNumber,
  102.             IntegratorId: IntegratorId,
  103.             Localization: null_mut_ptr!(ns2__Localization),            
  104.         }));
  105.         Ok(ret)
  106.     }
  107.  
  108. // Get string
  109. #[allow(bad_style)]
  110.     fn get_string(
  111.         key: &str,
  112.         json_str: &Value,
  113.         required: bool,
  114.     ) -> Result<*mut std::os::raw::c_char, Vec<String>> {
  115.         if json_str.is_null() {
  116.             if required {
  117.                 return Err(vec![format!("Required value '{}' not set", key)]);
  118.             } else {
  119.                 return Ok(std::ptr::null_mut() as *mut i8);
  120.             }
  121.         } else {
  122.             let as_str_op = json_str.as_str();
  123.             match as_str_op {
  124.                 Some(s) => {
  125.                     let str_kk = CString::new(s).unwrap().into_raw();
  126.                     return Ok(str_kk);
  127.                 }
  128.                 None => {
  129.                     return Err(vec![format!("Value '{}' is not string as specified", key)]);
  130.                 }
  131.             }
  132.         }
  133.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement