zplus 0.9.3-rc.1

Subor Z+/Ruyi SDK
Documentation
// Autogenerated by Thrift Compiler (0.12.0)
// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING

#![allow(unused_imports)]
#![allow(unused_extern_crates)]
#![cfg_attr(feature = "cargo-clippy", allow(too_many_arguments, type_complexity))]
#![cfg_attr(rustfmt, rustfmt_skip)]

extern crate ordered_float;
extern crate thrift;
extern crate try_from;

use ordered_float::OrderedFloat;
use std::cell::RefCell;
use std::collections::{BTreeMap, BTreeSet};
use std::convert::From;
use std::default::Default;
use std::error::Error;
use std::fmt;
use std::fmt::{Display, Formatter};
use std::rc::Rc;
use try_from::TryFrom;

use thrift::{ApplicationError, ApplicationErrorKind, ProtocolError, ProtocolErrorKind, TThriftClient};
use thrift::protocol::{TFieldIdentifier, TListIdentifier, TMapIdentifier, TMessageIdentifier, TMessageType, TInputProtocol, TOutputProtocol, TSetIdentifier, TStructIdentifier, TType};
use thrift::protocol::field_id;
use thrift::protocol::verify_expected_message_type;
use thrift::protocol::verify_expected_sequence_number;
use thrift::protocol::verify_expected_service_call;
use thrift::protocol::verify_required_field_exists;
use thrift::server::TProcessor;

use common_type_s_d_k_data_types;
use user_service_external_s_d_k_data_types;

//
// UserServExternal service client
//

pub trait TUserServExternalSyncClient {
  /// @GetPlayingUserInfo_Summary
  fn get_playing_user_info(&mut self, user_id: String) -> thrift::Result<user_service_external_s_d_k_data_types::UserInfoPublic>;
}

pub trait TUserServExternalSyncClientMarker {}

pub struct UserServExternalSyncClient<IP, OP> where IP: TInputProtocol, OP: TOutputProtocol {
  _i_prot: IP,
  _o_prot: OP,
  _sequence_number: i32,
}

impl <IP, OP> UserServExternalSyncClient<IP, OP> where IP: TInputProtocol, OP: TOutputProtocol {
  pub fn new(input_protocol: IP, output_protocol: OP) -> UserServExternalSyncClient<IP, OP> {
    UserServExternalSyncClient { _i_prot: input_protocol, _o_prot: output_protocol, _sequence_number: 0 }
  }
}

impl <IP, OP> TThriftClient for UserServExternalSyncClient<IP, OP> where IP: TInputProtocol, OP: TOutputProtocol {
  fn i_prot_mut(&mut self) -> &mut TInputProtocol { &mut self._i_prot }
  fn o_prot_mut(&mut self) -> &mut TOutputProtocol { &mut self._o_prot }
  fn sequence_number(&self) -> i32 { self._sequence_number }
  fn increment_sequence_number(&mut self) -> i32 { self._sequence_number += 1; self._sequence_number }
}

impl <IP, OP> TUserServExternalSyncClientMarker for UserServExternalSyncClient<IP, OP> where IP: TInputProtocol, OP: TOutputProtocol {}

impl <C: TThriftClient + TUserServExternalSyncClientMarker> TUserServExternalSyncClient for C {
  fn get_playing_user_info(&mut self, user_id: String) -> thrift::Result<user_service_external_s_d_k_data_types::UserInfoPublic> {
    (
      {
        self.increment_sequence_number();
        let message_ident = TMessageIdentifier::new("GetPlayingUserInfo", TMessageType::Call, self.sequence_number());
        let call_args = UserServExternalGetPlayingUserInfoArgs { user_id: user_id };
        self.o_prot_mut().write_message_begin(&message_ident)?;
        call_args.write_to_out_protocol(self.o_prot_mut())?;
        self.o_prot_mut().write_message_end()?;
        self.o_prot_mut().flush()
      }
    )?;
    {
      let message_ident = self.i_prot_mut().read_message_begin()?;
      verify_expected_sequence_number(self.sequence_number(), message_ident.sequence_number)?;
      verify_expected_service_call("GetPlayingUserInfo", &message_ident.name)?;
      if message_ident.message_type == TMessageType::Exception {
        let remote_error = thrift::Error::read_application_error_from_in_protocol(self.i_prot_mut())?;
        self.i_prot_mut().read_message_end()?;
        return Err(thrift::Error::Application(remote_error))
      }
      verify_expected_message_type(TMessageType::Reply, message_ident.message_type)?;
      let result = UserServExternalGetPlayingUserInfoResult::read_from_in_protocol(self.i_prot_mut())?;
      self.i_prot_mut().read_message_end()?;
      result.ok_or()
    }
  }
}

//
// UserServExternal service processor
//

pub trait UserServExternalSyncHandler {
  /// @GetPlayingUserInfo_Summary
  fn handle_get_playing_user_info(&self, user_id: String) -> thrift::Result<user_service_external_s_d_k_data_types::UserInfoPublic>;
}

pub struct UserServExternalSyncProcessor<H: UserServExternalSyncHandler> {
  handler: H,
}

impl <H: UserServExternalSyncHandler> UserServExternalSyncProcessor<H> {
  pub fn new(handler: H) -> UserServExternalSyncProcessor<H> {
    UserServExternalSyncProcessor {
      handler,
    }
  }
  fn process_get_playing_user_info(&self, incoming_sequence_number: i32, i_prot: &mut TInputProtocol, o_prot: &mut TOutputProtocol) -> thrift::Result<()> {
    TUserServExternalProcessFunctions::process_get_playing_user_info(&self.handler, incoming_sequence_number, i_prot, o_prot)
  }
}

pub struct TUserServExternalProcessFunctions;

impl TUserServExternalProcessFunctions {
  pub fn process_get_playing_user_info<H: UserServExternalSyncHandler>(handler: &H, incoming_sequence_number: i32, i_prot: &mut TInputProtocol, o_prot: &mut TOutputProtocol) -> thrift::Result<()> {
    let args = UserServExternalGetPlayingUserInfoArgs::read_from_in_protocol(i_prot)?;
    match handler.handle_get_playing_user_info(args.user_id) {
      Ok(handler_return) => {
        let message_ident = TMessageIdentifier::new("GetPlayingUserInfo", TMessageType::Reply, incoming_sequence_number);
        o_prot.write_message_begin(&message_ident)?;
        let ret = UserServExternalGetPlayingUserInfoResult { result_value: Some(handler_return), error1: None };
        ret.write_to_out_protocol(o_prot)?;
        o_prot.write_message_end()?;
        o_prot.flush()
      },
      Err(e) => {
        match e {
          thrift::Error::User(usr_err) => {
            if usr_err.downcast_ref::<common_type_s_d_k_data_types::ErrorException>().is_some() {
              let err = usr_err.downcast::<common_type_s_d_k_data_types::ErrorException>().expect("downcast already checked");
              let ret_err = UserServExternalGetPlayingUserInfoResult{ result_value: None, error1: Some(*err) };
              let message_ident = TMessageIdentifier::new("GetPlayingUserInfo", TMessageType::Reply, incoming_sequence_number);
              o_prot.write_message_begin(&message_ident)?;
              ret_err.write_to_out_protocol(o_prot)?;
              o_prot.write_message_end()?;
              o_prot.flush()
            } else {
              let ret_err = {
                ApplicationError::new(
                  ApplicationErrorKind::Unknown,
                  usr_err.description()
                )
              };
              let message_ident = TMessageIdentifier::new("GetPlayingUserInfo", TMessageType::Exception, incoming_sequence_number);
              o_prot.write_message_begin(&message_ident)?;
              thrift::Error::write_application_error_to_out_protocol(&ret_err, o_prot)?;
              o_prot.write_message_end()?;
              o_prot.flush()
            }
          },
          thrift::Error::Application(app_err) => {
            let message_ident = TMessageIdentifier::new("GetPlayingUserInfo", TMessageType::Exception, incoming_sequence_number);
            o_prot.write_message_begin(&message_ident)?;
            thrift::Error::write_application_error_to_out_protocol(&app_err, o_prot)?;
            o_prot.write_message_end()?;
            o_prot.flush()
          },
          _ => {
            let ret_err = {
              ApplicationError::new(
                ApplicationErrorKind::Unknown,
                e.description()
              )
            };
            let message_ident = TMessageIdentifier::new("GetPlayingUserInfo", TMessageType::Exception, incoming_sequence_number);
            o_prot.write_message_begin(&message_ident)?;
            thrift::Error::write_application_error_to_out_protocol(&ret_err, o_prot)?;
            o_prot.write_message_end()?;
            o_prot.flush()
          },
        }
      },
    }
  }
}

impl <H: UserServExternalSyncHandler> TProcessor for UserServExternalSyncProcessor<H> {
  fn process(&self, i_prot: &mut TInputProtocol, o_prot: &mut TOutputProtocol) -> thrift::Result<()> {
    let message_ident = i_prot.read_message_begin()?;
    let res = match &*message_ident.name {
      "GetPlayingUserInfo" => {
        self.process_get_playing_user_info(message_ident.sequence_number, i_prot, o_prot)
      },
      method => {
        Err(
          thrift::Error::Application(
            ApplicationError::new(
              ApplicationErrorKind::UnknownMethod,
              format!("unknown method {}", method)
            )
          )
        )
      },
    };
    thrift::server::handle_process_result(&message_ident, res, o_prot)
  }
}

//
// UserServExternalGetPlayingUserInfoArgs
//

#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
struct UserServExternalGetPlayingUserInfoArgs {
  /// @GetPlayingUserInfo_userId_desc
  user_id: String,
}

impl UserServExternalGetPlayingUserInfoArgs {
  fn read_from_in_protocol(i_prot: &mut TInputProtocol) -> thrift::Result<UserServExternalGetPlayingUserInfoArgs> {
    i_prot.read_struct_begin()?;
    let mut f_1: Option<String> = None;
    loop {
      let field_ident = i_prot.read_field_begin()?;
      if field_ident.field_type == TType::Stop {
        break;
      }
      let field_id = field_id(&field_ident)?;
      match field_id {
        1 => {
          let val = i_prot.read_string()?;
          f_1 = Some(val);
        },
        _ => {
          i_prot.skip(field_ident.field_type)?;
        },
      };
      i_prot.read_field_end()?;
    }
    i_prot.read_struct_end()?;
    verify_required_field_exists("UserServExternalGetPlayingUserInfoArgs.user_id", &f_1)?;
    let ret = UserServExternalGetPlayingUserInfoArgs {
      user_id: f_1.expect("auto-generated code should have checked for presence of required fields"),
    };
    Ok(ret)
  }
  fn write_to_out_protocol(&self, o_prot: &mut TOutputProtocol) -> thrift::Result<()> {
    let struct_ident = TStructIdentifier::new("GetPlayingUserInfo_args");
    o_prot.write_struct_begin(&struct_ident)?;
    o_prot.write_field_begin(&TFieldIdentifier::new("userId", TType::String, 1))?;
    o_prot.write_string(&self.user_id)?;
    o_prot.write_field_end()?;
    o_prot.write_field_stop()?;
    o_prot.write_struct_end()
  }
}

//
// UserServExternalGetPlayingUserInfoResult
//

#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
struct UserServExternalGetPlayingUserInfoResult {
  result_value: Option<user_service_external_s_d_k_data_types::UserInfoPublic>,
  error1: Option<common_type_s_d_k_data_types::ErrorException>,
}

impl UserServExternalGetPlayingUserInfoResult {
  fn read_from_in_protocol(i_prot: &mut TInputProtocol) -> thrift::Result<UserServExternalGetPlayingUserInfoResult> {
    i_prot.read_struct_begin()?;
    let mut f_0: Option<user_service_external_s_d_k_data_types::UserInfoPublic> = None;
    let mut f_1: Option<common_type_s_d_k_data_types::ErrorException> = None;
    loop {
      let field_ident = i_prot.read_field_begin()?;
      if field_ident.field_type == TType::Stop {
        break;
      }
      let field_id = field_id(&field_ident)?;
      match field_id {
        0 => {
          let val = user_service_external_s_d_k_data_types::UserInfoPublic::read_from_in_protocol(i_prot)?;
          f_0 = Some(val);
        },
        1 => {
          let val = common_type_s_d_k_data_types::ErrorException::read_from_in_protocol(i_prot)?;
          f_1 = Some(val);
        },
        _ => {
          i_prot.skip(field_ident.field_type)?;
        },
      };
      i_prot.read_field_end()?;
    }
    i_prot.read_struct_end()?;
    let ret = UserServExternalGetPlayingUserInfoResult {
      result_value: f_0,
      error1: f_1,
    };
    Ok(ret)
  }
  fn write_to_out_protocol(&self, o_prot: &mut TOutputProtocol) -> thrift::Result<()> {
    let struct_ident = TStructIdentifier::new("UserServExternalGetPlayingUserInfoResult");
    o_prot.write_struct_begin(&struct_ident)?;
    if let Some(ref fld_var) = self.result_value {
      o_prot.write_field_begin(&TFieldIdentifier::new("result_value", TType::Struct, 0))?;
      fld_var.write_to_out_protocol(o_prot)?;
      o_prot.write_field_end()?;
      ()
    } else {
      ()
    }
    if let Some(ref fld_var) = self.error1 {
      o_prot.write_field_begin(&TFieldIdentifier::new("error1", TType::Struct, 1))?;
      fld_var.write_to_out_protocol(o_prot)?;
      o_prot.write_field_end()?;
      ()
    } else {
      ()
    }
    o_prot.write_field_stop()?;
    o_prot.write_struct_end()
  }
  fn ok_or(self) -> thrift::Result<user_service_external_s_d_k_data_types::UserInfoPublic> {
    if self.error1.is_some() {
      Err(thrift::Error::User(Box::new(self.error1.unwrap())))
    } else if self.result_value.is_some() {
      Ok(self.result_value.unwrap())
    } else {
      Err(
        thrift::Error::Application(
          ApplicationError::new(
            ApplicationErrorKind::MissingResult,
            "no result received for UserServExternalGetPlayingUserInfo"
          )
        )
      )
    }
  }
}