// Generated by the protocol buffer compiler.  DO NOT EDIT!
// source: ril.proto

#ifndef PROTOBUF_ril_2eproto__INCLUDED
#define PROTOBUF_ril_2eproto__INCLUDED

#include <string>

#include <google/protobuf/stubs/common.h>

#if GOOGLE_PROTOBUF_VERSION < 2003000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers.  Please update
#error your headers.
#endif
#if 2003000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers.  Please
#error regenerate this file with a newer version of protoc.
#endif

#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/generated_message_reflection.h>
// @@protoc_insertion_point(includes)

namespace ril_proto {

// Internal implementation detail -- do not call these.
void  protobuf_AddDesc_ril_2eproto();
void protobuf_AssignDesc_ril_2eproto();
void protobuf_ShutdownFile_ril_2eproto();

class RilAppStatus;
class RilCardStatus;
class RilUusInfo;
class RilCall;
class RILGWSignalStrength;
class RILCDMASignalStrength;
class RILEVDOSignalStrength;
class RspStrings;
class RspIntegers;
class RspGetSimStatus;
class ReqEnterSimPin;
class RspEnterSimPin;
class RspGetCurrentCalls;
class ReqDial;
class ReqHangUp;
class RspLastCallFailCause;
class RspSignalStrength;
class RspOperator;
class ReqSeparateConnection;
class ReqSetMute;
class ReqScreenState;

enum RadioState {
  RADIOSTATE_OFF = 0,
  RADIOSTATE_UNAVAILABLE = 1,
  RADIOSTATE_SIM_NOT_READY = 2,
  RADIOSTATE_SIM_LOCKED_OR_ABSENT = 3,
  RADIOSTATE_SIM_READY = 4,
  RADIOSTATE_RUIM_NOT_READY = 5,
  RADIOSTATE_RUIM_READY = 6,
  RADIOSTATE_RUIM_LOCKED_OR_ABSENT = 7,
  RADIOSTATE_NV_NOT_READY = 8,
  RADIOSTATE_NV_READY = 9
};
bool RadioState_IsValid(int value);
const RadioState RadioState_MIN = RADIOSTATE_OFF;
const RadioState RadioState_MAX = RADIOSTATE_NV_READY;
const int RadioState_ARRAYSIZE = RadioState_MAX + 1;

const ::google::protobuf::EnumDescriptor* RadioState_descriptor();
inline const ::std::string& RadioState_Name(RadioState value) {
  return ::google::protobuf::internal::NameOfEnum(
    RadioState_descriptor(), value);
}
inline bool RadioState_Parse(
    const ::std::string& name, RadioState* value) {
  return ::google::protobuf::internal::ParseNamedEnum<RadioState>(
    RadioState_descriptor(), name, value);
}
enum RilCardState {
  CARDSTATE_ABSENT = 0,
  CARDSTATE_PRESENT = 1,
  CARDSTATE_ERROR = 2
};
bool RilCardState_IsValid(int value);
const RilCardState RilCardState_MIN = CARDSTATE_ABSENT;
const RilCardState RilCardState_MAX = CARDSTATE_ERROR;
const int RilCardState_ARRAYSIZE = RilCardState_MAX + 1;

const ::google::protobuf::EnumDescriptor* RilCardState_descriptor();
inline const ::std::string& RilCardState_Name(RilCardState value) {
  return ::google::protobuf::internal::NameOfEnum(
    RilCardState_descriptor(), value);
}
inline bool RilCardState_Parse(
    const ::std::string& name, RilCardState* value) {
  return ::google::protobuf::internal::ParseNamedEnum<RilCardState>(
    RilCardState_descriptor(), name, value);
}
enum RilPersoSubstate {
  PERSOSUBSTATE_UNKNOWN = 0,
  PERSOSUBSTATE_IN_PROGRESS = 1,
  PERSOSUBSTATE_READY = 2,
  PERSOSUBSTATE_SIM_NETWORK = 3,
  PERSOSUBSTATE_SIM_NETWORK_SUBSET = 4,
  PERSOSUBSTATE_SIM_CORPORATE = 5,
  PERSOSUBSTATE_SIM_SERVICE_PROVIDER = 6,
  PERSOSUBSTATE_SIM_SIM = 7,
  PERSOSUBSTATE_SIM_NETWORK_PUK = 8,
  PERSOSUBSTATE_SIM_NETWORK_SUBSET_PUK = 9,
  PERSOSUBSTATE_SIM_CORPORATE_PUK = 10,
  PERSOSUBSTATE_SIM_SERVICE_PROVIDER_PUK = 11,
  PERSOSUBSTATE_SIM_SIM_PUK = 12,
  PERSOSUBSTATE_RUIM_NETWORK1 = 13,
  PERSOSUBSTATE_RUIM_NETWORK2 = 14,
  PERSOSUBSTATE_RUIM_HRPD = 15,
  PERSOSUBSTATE_RUIM_CORPORATE = 16,
  PERSOSUBSTATE_RUIM_SERVICE_PROVIDER = 17,
  PERSOSUBSTATE_RUIM_RUIM = 18,
  PERSOSUBSTATE_RUIM_NETWORK1_PUK = 19,
  PERSOSUBSTATE_RUIM_NETWORK2_PUK = 20,
  PERSOSUBSTATE_RUIM_HRPD_PUK = 21,
  PERSOSUBSTATE_RUIM_CORPORATE_PUK = 22,
  PERSOSUBSTATE_RUIM_SERVICE_PROVIDER_PUK = 23,
  PERSOSUBSTATE_RUIM_RUIM_PUK = 24
};
bool RilPersoSubstate_IsValid(int value);
const RilPersoSubstate RilPersoSubstate_MIN = PERSOSUBSTATE_UNKNOWN;
const RilPersoSubstate RilPersoSubstate_MAX = PERSOSUBSTATE_RUIM_RUIM_PUK;
const int RilPersoSubstate_ARRAYSIZE = RilPersoSubstate_MAX + 1;

const ::google::protobuf::EnumDescriptor* RilPersoSubstate_descriptor();
inline const ::std::string& RilPersoSubstate_Name(RilPersoSubstate value) {
  return ::google::protobuf::internal::NameOfEnum(
    RilPersoSubstate_descriptor(), value);
}
inline bool RilPersoSubstate_Parse(
    const ::std::string& name, RilPersoSubstate* value) {
  return ::google::protobuf::internal::ParseNamedEnum<RilPersoSubstate>(
    RilPersoSubstate_descriptor(), name, value);
}
enum RilAppState {
  APPSTATE_UNKNOWN = 0,
  APPSTATE_DETECTED = 1,
  APPSTATE_PIN = 2,
  APPSTATE_PUK = 3,
  APPSTATE_SUBSCRIPTION_PERSO = 4,
  APPSTATE_READY = 5
};
bool RilAppState_IsValid(int value);
const RilAppState RilAppState_MIN = APPSTATE_UNKNOWN;
const RilAppState RilAppState_MAX = APPSTATE_READY;
const int RilAppState_ARRAYSIZE = RilAppState_MAX + 1;

const ::google::protobuf::EnumDescriptor* RilAppState_descriptor();
inline const ::std::string& RilAppState_Name(RilAppState value) {
  return ::google::protobuf::internal::NameOfEnum(
    RilAppState_descriptor(), value);
}
inline bool RilAppState_Parse(
    const ::std::string& name, RilAppState* value) {
  return ::google::protobuf::internal::ParseNamedEnum<RilAppState>(
    RilAppState_descriptor(), name, value);
}
enum RilPinState {
  PINSTATE_UNKNOWN = 0,
  PINSTATE_ENABLED_NOT_VERIFIED = 1,
  PINSTATE_ENABLED_VERIFIED = 2,
  PINSTATE_DISABLED = 3,
  PINSTATE_ENABLED_BLOCKED = 4,
  PINSTATE_ENABLED_PERM_BLOCKED = 5
};
bool RilPinState_IsValid(int value);
const RilPinState RilPinState_MIN = PINSTATE_UNKNOWN;
const RilPinState RilPinState_MAX = PINSTATE_ENABLED_PERM_BLOCKED;
const int RilPinState_ARRAYSIZE = RilPinState_MAX + 1;

const ::google::protobuf::EnumDescriptor* RilPinState_descriptor();
inline const ::std::string& RilPinState_Name(RilPinState value) {
  return ::google::protobuf::internal::NameOfEnum(
    RilPinState_descriptor(), value);
}
inline bool RilPinState_Parse(
    const ::std::string& name, RilPinState* value) {
  return ::google::protobuf::internal::ParseNamedEnum<RilPinState>(
    RilPinState_descriptor(), name, value);
}
enum RilAppType {
  APPTYPE_UNKNOWN = 0,
  APPTYPE_SIM = 1,
  APPTYPE_USIM = 2,
  APPTYPE_RUIM = 3,
  APPTYPE_CSIM = 4
};
bool RilAppType_IsValid(int value);
const RilAppType RilAppType_MIN = APPTYPE_UNKNOWN;
const RilAppType RilAppType_MAX = APPTYPE_CSIM;
const int RilAppType_ARRAYSIZE = RilAppType_MAX + 1;

const ::google::protobuf::EnumDescriptor* RilAppType_descriptor();
inline const ::std::string& RilAppType_Name(RilAppType value) {
  return ::google::protobuf::internal::NameOfEnum(
    RilAppType_descriptor(), value);
}
inline bool RilAppType_Parse(
    const ::std::string& name, RilAppType* value) {
  return ::google::protobuf::internal::ParseNamedEnum<RilAppType>(
    RilAppType_descriptor(), name, value);
}
enum RilUusType {
  RILUUSTYPE1_IMPLICIT = 0,
  RILUUSTYPE1_REQUIRED = 1,
  RILUUSTYPE1_NOT_REQUIRED = 2,
  RILUUSTYPE2_REQUIRED = 3,
  RILUUSTYPE2_NOT_REQUIRED = 4,
  RILUUSTYPE3_REQUIRED = 5,
  RILUUSTYPE3_NOT_REQUIRED = 6
};
bool RilUusType_IsValid(int value);
const RilUusType RilUusType_MIN = RILUUSTYPE1_IMPLICIT;
const RilUusType RilUusType_MAX = RILUUSTYPE3_NOT_REQUIRED;
const int RilUusType_ARRAYSIZE = RilUusType_MAX + 1;

const ::google::protobuf::EnumDescriptor* RilUusType_descriptor();
inline const ::std::string& RilUusType_Name(RilUusType value) {
  return ::google::protobuf::internal::NameOfEnum(
    RilUusType_descriptor(), value);
}
inline bool RilUusType_Parse(
    const ::std::string& name, RilUusType* value) {
  return ::google::protobuf::internal::ParseNamedEnum<RilUusType>(
    RilUusType_descriptor(), name, value);
}
enum RilUusDcs {
  RILUUSDCS_USP = 0,
  RILUUSDCS_OSIHLP = 1,
  RILUUSDCS_X244 = 2,
  RILUUSDCS_RMCF = 3,
  RILUUSDCS_IA5c = 4
};
bool RilUusDcs_IsValid(int value);
const RilUusDcs RilUusDcs_MIN = RILUUSDCS_USP;
const RilUusDcs RilUusDcs_MAX = RILUUSDCS_IA5c;
const int RilUusDcs_ARRAYSIZE = RilUusDcs_MAX + 1;

const ::google::protobuf::EnumDescriptor* RilUusDcs_descriptor();
inline const ::std::string& RilUusDcs_Name(RilUusDcs value) {
  return ::google::protobuf::internal::NameOfEnum(
    RilUusDcs_descriptor(), value);
}
inline bool RilUusDcs_Parse(
    const ::std::string& name, RilUusDcs* value) {
  return ::google::protobuf::internal::ParseNamedEnum<RilUusDcs>(
    RilUusDcs_descriptor(), name, value);
}
enum RilCallState {
  CALLSTATE_ACTIVE = 0,
  CALLSTATE_HOLDING = 1,
  CALLSTATE_DIALING = 2,
  CALLSTATE_ALERTING = 3,
  CALLSTATE_INCOMING = 4,
  CALLSTATE_WAITING = 5
};
bool RilCallState_IsValid(int value);
const RilCallState RilCallState_MIN = CALLSTATE_ACTIVE;
const RilCallState RilCallState_MAX = CALLSTATE_WAITING;
const int RilCallState_ARRAYSIZE = RilCallState_MAX + 1;

const ::google::protobuf::EnumDescriptor* RilCallState_descriptor();
inline const ::std::string& RilCallState_Name(RilCallState value) {
  return ::google::protobuf::internal::NameOfEnum(
    RilCallState_descriptor(), value);
}
inline bool RilCallState_Parse(
    const ::std::string& name, RilCallState* value) {
  return ::google::protobuf::internal::ParseNamedEnum<RilCallState>(
    RilCallState_descriptor(), name, value);
}
// ===================================================================

class RilAppStatus : public ::google::protobuf::Message {
 public:
  RilAppStatus();
  virtual ~RilAppStatus();
  
  RilAppStatus(const RilAppStatus& from);
  
  inline RilAppStatus& operator=(const RilAppStatus& from) {
    CopyFrom(from);
    return *this;
  }
  
  inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
    return _unknown_fields_;
  }
  
  inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
    return &_unknown_fields_;
  }
  
  static const ::google::protobuf::Descriptor* descriptor();
  static const RilAppStatus& default_instance();
  
  void Swap(RilAppStatus* other);
  
  // implements Message ----------------------------------------------
  
  RilAppStatus* New() const;
  void CopyFrom(const ::google::protobuf::Message& from);
  void MergeFrom(const ::google::protobuf::Message& from);
  void CopyFrom(const RilAppStatus& from);
  void MergeFrom(const RilAppStatus& from);
  void Clear();
  bool IsInitialized() const;
  
  int ByteSize() const;
  bool MergePartialFromCodedStream(
      ::google::protobuf::io::CodedInputStream* input);
  void SerializeWithCachedSizes(
      ::google::protobuf::io::CodedOutputStream* output) const;
  ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
  int GetCachedSize() const { return _cached_size_; }
  private:
  void SharedCtor();
  void SharedDtor();
  void SetCachedSize(int size) const;
  public:
  
  ::google::protobuf::Metadata GetMetadata() const;
  
  // nested types ----------------------------------------------------
  
  // accessors -------------------------------------------------------
  
  // optional .ril_proto.RilAppType app_type = 1;
  inline bool has_app_type() const;
  inline void clear_app_type();
  static const int kAppTypeFieldNumber = 1;
  inline ril_proto::RilAppType app_type() const;
  inline void set_app_type(ril_proto::RilAppType value);
  
  // optional .ril_proto.RilAppState app_state = 2;
  inline bool has_app_state() const;
  inline void clear_app_state();
  static const int kAppStateFieldNumber = 2;
  inline ril_proto::RilAppState app_state() const;
  inline void set_app_state(ril_proto::RilAppState value);
  
  // optional .ril_proto.RilPersoSubstate perso_substate = 3;
  inline bool has_perso_substate() const;
  inline void clear_perso_substate();
  static const int kPersoSubstateFieldNumber = 3;
  inline ril_proto::RilPersoSubstate perso_substate() const;
  inline void set_perso_substate(ril_proto::RilPersoSubstate value);
  
  // optional string aid = 4;
  inline bool has_aid() const;
  inline void clear_aid();
  static const int kAidFieldNumber = 4;
  inline const ::std::string& aid() const;
  inline void set_aid(const ::std::string& value);
  inline void set_aid(const char* value);
  inline void set_aid(const char* value, size_t size);
  inline ::std::string* mutable_aid();
  
  // optional string app_label = 5;
  inline bool has_app_label() const;
  inline void clear_app_label();
  static const int kAppLabelFieldNumber = 5;
  inline const ::std::string& app_label() const;
  inline void set_app_label(const ::std::string& value);
  inline void set_app_label(const char* value);
  inline void set_app_label(const char* value, size_t size);
  inline ::std::string* mutable_app_label();
  
  // optional int32 pin1_replaced = 6;
  inline bool has_pin1_replaced() const;
  inline void clear_pin1_replaced();
  static const int kPin1ReplacedFieldNumber = 6;
  inline ::google::protobuf::int32 pin1_replaced() const;
  inline void set_pin1_replaced(::google::protobuf::int32 value);
  
  // optional .ril_proto.RilPinState pin1 = 7;
  inline bool has_pin1() const;
  inline void clear_pin1();
  static const int kPin1FieldNumber = 7;
  inline ril_proto::RilPinState pin1() const;
  inline void set_pin1(ril_proto::RilPinState value);
  
  // optional .ril_proto.RilPinState pin2 = 8;
  inline bool has_pin2() const;
  inline void clear_pin2();
  static const int kPin2FieldNumber = 8;
  inline ril_proto::RilPinState pin2() const;
  inline void set_pin2(ril_proto::RilPinState value);
  
  // @@protoc_insertion_point(class_scope:ril_proto.RilAppStatus)
 private:
  ::google::protobuf::UnknownFieldSet _unknown_fields_;
  mutable int _cached_size_;
  
  int app_type_;
  int app_state_;
  int perso_substate_;
  ::std::string* aid_;
  static const ::std::string _default_aid_;
  ::std::string* app_label_;
  static const ::std::string _default_app_label_;
  ::google::protobuf::int32 pin1_replaced_;
  int pin1_;
  int pin2_;
  friend void  protobuf_AddDesc_ril_2eproto();
  friend void protobuf_AssignDesc_ril_2eproto();
  friend void protobuf_ShutdownFile_ril_2eproto();
  
  ::google::protobuf::uint32 _has_bits_[(8 + 31) / 32];
  
  // WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
  inline bool _has_bit(int index) const {
    return (_has_bits_[index / 32] & (1u << (index % 32))) != 0;
  }
  inline void _set_bit(int index) {
    _has_bits_[index / 32] |= (1u << (index % 32));
  }
  inline void _clear_bit(int index) {
    _has_bits_[index / 32] &= ~(1u << (index % 32));
  }
  
  void InitAsDefaultInstance();
  static RilAppStatus* default_instance_;
};
// -------------------------------------------------------------------

class RilCardStatus : public ::google::protobuf::Message {
 public:
  RilCardStatus();
  virtual ~RilCardStatus();
  
  RilCardStatus(const RilCardStatus& from);
  
  inline RilCardStatus& operator=(const RilCardStatus& from) {
    CopyFrom(from);
    return *this;
  }
  
  inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
    return _unknown_fields_;
  }
  
  inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
    return &_unknown_fields_;
  }
  
  static const ::google::protobuf::Descriptor* descriptor();
  static const RilCardStatus& default_instance();
  
  void Swap(RilCardStatus* other);
  
  // implements Message ----------------------------------------------
  
  RilCardStatus* New() const;
  void CopyFrom(const ::google::protobuf::Message& from);
  void MergeFrom(const ::google::protobuf::Message& from);
  void CopyFrom(const RilCardStatus& from);
  void MergeFrom(const RilCardStatus& from);
  void Clear();
  bool IsInitialized() const;
  
  int ByteSize() const;
  bool MergePartialFromCodedStream(
      ::google::protobuf::io::CodedInputStream* input);
  void SerializeWithCachedSizes(
      ::google::protobuf::io::CodedOutputStream* output) const;
  ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
  int GetCachedSize() const { return _cached_size_; }
  private:
  void SharedCtor();
  void SharedDtor();
  void SetCachedSize(int size) const;
  public:
  
  ::google::protobuf::Metadata GetMetadata() const;
  
  // nested types ----------------------------------------------------
  
  // accessors -------------------------------------------------------
  
  // optional .ril_proto.RilCardState card_state = 1;
  inline bool has_card_state() const;
  inline void clear_card_state();
  static const int kCardStateFieldNumber = 1;
  inline ril_proto::RilCardState card_state() const;
  inline void set_card_state(ril_proto::RilCardState value);
  
  // optional .ril_proto.RilPinState universal_pin_state = 2;
  inline bool has_universal_pin_state() const;
  inline void clear_universal_pin_state();
  static const int kUniversalPinStateFieldNumber = 2;
  inline ril_proto::RilPinState universal_pin_state() const;
  inline void set_universal_pin_state(ril_proto::RilPinState value);
  
  // optional int32 gsm_umts_subscription_app_index = 3;
  inline bool has_gsm_umts_subscription_app_index() const;
  inline void clear_gsm_umts_subscription_app_index();
  static const int kGsmUmtsSubscriptionAppIndexFieldNumber = 3;
  inline ::google::protobuf::int32 gsm_umts_subscription_app_index() const;
  inline void set_gsm_umts_subscription_app_index(::google::protobuf::int32 value);
  
  // optional int32 cdma_subscription_app_index = 4;
  inline bool has_cdma_subscription_app_index() const;
  inline void clear_cdma_subscription_app_index();
  static const int kCdmaSubscriptionAppIndexFieldNumber = 4;
  inline ::google::protobuf::int32 cdma_subscription_app_index() const;
  inline void set_cdma_subscription_app_index(::google::protobuf::int32 value);
  
  // optional int32 num_applications = 5;
  inline bool has_num_applications() const;
  inline void clear_num_applications();
  static const int kNumApplicationsFieldNumber = 5;
  inline ::google::protobuf::int32 num_applications() const;
  inline void set_num_applications(::google::protobuf::int32 value);
  
  // repeated .ril_proto.RilAppStatus applications = 6;
  inline int applications_size() const;
  inline void clear_applications();
  static const int kApplicationsFieldNumber = 6;
  inline const ::ril_proto::RilAppStatus& applications(int index) const;
  inline ::ril_proto::RilAppStatus* mutable_applications(int index);
  inline ::ril_proto::RilAppStatus* add_applications();
  inline const ::google::protobuf::RepeatedPtrField< ::ril_proto::RilAppStatus >&
      applications() const;
  inline ::google::protobuf::RepeatedPtrField< ::ril_proto::RilAppStatus >*
      mutable_applications();
  
  // @@protoc_insertion_point(class_scope:ril_proto.RilCardStatus)
 private:
  ::google::protobuf::UnknownFieldSet _unknown_fields_;
  mutable int _cached_size_;
  
  int card_state_;
  int universal_pin_state_;
  ::google::protobuf::int32 gsm_umts_subscription_app_index_;
  ::google::protobuf::int32 cdma_subscription_app_index_;
  ::google::protobuf::int32 num_applications_;
  ::google::protobuf::RepeatedPtrField< ::ril_proto::RilAppStatus > applications_;
  friend void  protobuf_AddDesc_ril_2eproto();
  friend void protobuf_AssignDesc_ril_2eproto();
  friend void protobuf_ShutdownFile_ril_2eproto();
  
  ::google::protobuf::uint32 _has_bits_[(6 + 31) / 32];
  
  // WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
  inline bool _has_bit(int index) const {
    return (_has_bits_[index / 32] & (1u << (index % 32))) != 0;
  }
  inline void _set_bit(int index) {
    _has_bits_[index / 32] |= (1u << (index % 32));
  }
  inline void _clear_bit(int index) {
    _has_bits_[index / 32] &= ~(1u << (index % 32));
  }
  
  void InitAsDefaultInstance();
  static RilCardStatus* default_instance_;
};
// -------------------------------------------------------------------

class RilUusInfo : public ::google::protobuf::Message {
 public:
  RilUusInfo();
  virtual ~RilUusInfo();
  
  RilUusInfo(const RilUusInfo& from);
  
  inline RilUusInfo& operator=(const RilUusInfo& from) {
    CopyFrom(from);
    return *this;
  }
  
  inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
    return _unknown_fields_;
  }
  
  inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
    return &_unknown_fields_;
  }
  
  static const ::google::protobuf::Descriptor* descriptor();
  static const RilUusInfo& default_instance();
  
  void Swap(RilUusInfo* other);
  
  // implements Message ----------------------------------------------
  
  RilUusInfo* New() const;
  void CopyFrom(const ::google::protobuf::Message& from);
  void MergeFrom(const ::google::protobuf::Message& from);
  void CopyFrom(const RilUusInfo& from);
  void MergeFrom(const RilUusInfo& from);
  void Clear();
  bool IsInitialized() const;
  
  int ByteSize() const;
  bool MergePartialFromCodedStream(
      ::google::protobuf::io::CodedInputStream* input);
  void SerializeWithCachedSizes(
      ::google::protobuf::io::CodedOutputStream* output) const;
  ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
  int GetCachedSize() const { return _cached_size_; }
  private:
  void SharedCtor();
  void SharedDtor();
  void SetCachedSize(int size) const;
  public:
  
  ::google::protobuf::Metadata GetMetadata() const;
  
  // nested types ----------------------------------------------------
  
  // accessors -------------------------------------------------------
  
  // optional .ril_proto.RilUusType uus_type = 1;
  inline bool has_uus_type() const;
  inline void clear_uus_type();
  static const int kUusTypeFieldNumber = 1;
  inline ril_proto::RilUusType uus_type() const;
  inline void set_uus_type(ril_proto::RilUusType value);
  
  // optional .ril_proto.RilUusDcs uus_dcs = 2;
  inline bool has_uus_dcs() const;
  inline void clear_uus_dcs();
  static const int kUusDcsFieldNumber = 2;
  inline ril_proto::RilUusDcs uus_dcs() const;
  inline void set_uus_dcs(ril_proto::RilUusDcs value);
  
  // optional int32 uus_length = 3;
  inline bool has_uus_length() const;
  inline void clear_uus_length();
  static const int kUusLengthFieldNumber = 3;
  inline ::google::protobuf::int32 uus_length() const;
  inline void set_uus_length(::google::protobuf::int32 value);
  
  // optional string uus_data = 4;
  inline bool has_uus_data() const;
  inline void clear_uus_data();
  static const int kUusDataFieldNumber = 4;
  inline const ::std::string& uus_data() const;
  inline void set_uus_data(const ::std::string& value);
  inline void set_uus_data(const char* value);
  inline void set_uus_data(const char* value, size_t size);
  inline ::std::string* mutable_uus_data();
  
  // @@protoc_insertion_point(class_scope:ril_proto.RilUusInfo)
 private:
  ::google::protobuf::UnknownFieldSet _unknown_fields_;
  mutable int _cached_size_;
  
  int uus_type_;
  int uus_dcs_;
  ::google::protobuf::int32 uus_length_;
  ::std::string* uus_data_;
  static const ::std::string _default_uus_data_;
  friend void  protobuf_AddDesc_ril_2eproto();
  friend void protobuf_AssignDesc_ril_2eproto();
  friend void protobuf_ShutdownFile_ril_2eproto();
  
  ::google::protobuf::uint32 _has_bits_[(4 + 31) / 32];
  
  // WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
  inline bool _has_bit(int index) const {
    return (_has_bits_[index / 32] & (1u << (index % 32))) != 0;
  }
  inline void _set_bit(int index) {
    _has_bits_[index / 32] |= (1u << (index % 32));
  }
  inline void _clear_bit(int index) {
    _has_bits_[index / 32] &= ~(1u << (index % 32));
  }
  
  void InitAsDefaultInstance();
  static RilUusInfo* default_instance_;
};
// -------------------------------------------------------------------

class RilCall : public ::google::protobuf::Message {
 public:
  RilCall();
  virtual ~RilCall();
  
  RilCall(const RilCall& from);
  
  inline RilCall& operator=(const RilCall& from) {
    CopyFrom(from);
    return *this;
  }
  
  inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
    return _unknown_fields_;
  }
  
  inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
    return &_unknown_fields_;
  }
  
  static const ::google::protobuf::Descriptor* descriptor();
  static const RilCall& default_instance();
  
  void Swap(RilCall* other);
  
  // implements Message ----------------------------------------------
  
  RilCall* New() const;
  void CopyFrom(const ::google::protobuf::Message& from);
  void MergeFrom(const ::google::protobuf::Message& from);
  void CopyFrom(const RilCall& from);
  void MergeFrom(const RilCall& from);
  void Clear();
  bool IsInitialized() const;
  
  int ByteSize() const;
  bool MergePartialFromCodedStream(
      ::google::protobuf::io::CodedInputStream* input);
  void SerializeWithCachedSizes(
      ::google::protobuf::io::CodedOutputStream* output) const;
  ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
  int GetCachedSize() const { return _cached_size_; }
  private:
  void SharedCtor();
  void SharedDtor();
  void SetCachedSize(int size) const;
  public:
  
  ::google::protobuf::Metadata GetMetadata() const;
  
  // nested types ----------------------------------------------------
  
  // accessors -------------------------------------------------------
  
  // optional .ril_proto.RilCallState state = 1;
  inline bool has_state() const;
  inline void clear_state();
  static const int kStateFieldNumber = 1;
  inline ril_proto::RilCallState state() const;
  inline void set_state(ril_proto::RilCallState value);
  
  // optional int32 index = 2;
  inline bool has_index() const;
  inline void clear_index();
  static const int kIndexFieldNumber = 2;
  inline ::google::protobuf::int32 index() const;
  inline void set_index(::google::protobuf::int32 value);
  
  // optional int32 toa = 3;
  inline bool has_toa() const;
  inline void clear_toa();
  static const int kToaFieldNumber = 3;
  inline ::google::protobuf::int32 toa() const;
  inline void set_toa(::google::protobuf::int32 value);
  
  // optional bool is_mpty = 4;
  inline bool has_is_mpty() const;
  inline void clear_is_mpty();
  static const int kIsMptyFieldNumber = 4;
  inline bool is_mpty() const;
  inline void set_is_mpty(bool value);
  
  // optional bool is_mt = 5;
  inline bool has_is_mt() const;
  inline void clear_is_mt();
  static const int kIsMtFieldNumber = 5;
  inline bool is_mt() const;
  inline void set_is_mt(bool value);
  
  // optional int32 als = 6;
  inline bool has_als() const;
  inline void clear_als();
  static const int kAlsFieldNumber = 6;
  inline ::google::protobuf::int32 als() const;
  inline void set_als(::google::protobuf::int32 value);
  
  // optional bool is_voice = 7;
  inline bool has_is_voice() const;
  inline void clear_is_voice();
  static const int kIsVoiceFieldNumber = 7;
  inline bool is_voice() const;
  inline void set_is_voice(bool value);
  
  // optional bool is_voice_privacy = 8;
  inline bool has_is_voice_privacy() const;
  inline void clear_is_voice_privacy();
  static const int kIsVoicePrivacyFieldNumber = 8;
  inline bool is_voice_privacy() const;
  inline void set_is_voice_privacy(bool value);
  
  // optional string number = 9;
  inline bool has_number() const;
  inline void clear_number();
  static const int kNumberFieldNumber = 9;
  inline const ::std::string& number() const;
  inline void set_number(const ::std::string& value);
  inline void set_number(const char* value);
  inline void set_number(const char* value, size_t size);
  inline ::std::string* mutable_number();
  
  // optional int32 number_presentation = 10;
  inline bool has_number_presentation() const;
  inline void clear_number_presentation();
  static const int kNumberPresentationFieldNumber = 10;
  inline ::google::protobuf::int32 number_presentation() const;
  inline void set_number_presentation(::google::protobuf::int32 value);
  
  // optional string name = 11;
  inline bool has_name() const;
  inline void clear_name();
  static const int kNameFieldNumber = 11;
  inline const ::std::string& name() const;
  inline void set_name(const ::std::string& value);
  inline void set_name(const char* value);
  inline void set_name(const char* value, size_t size);
  inline ::std::string* mutable_name();
  
  // optional int32 name_presentation = 12;
  inline bool has_name_presentation() const;
  inline void clear_name_presentation();
  static const int kNamePresentationFieldNumber = 12;
  inline ::google::protobuf::int32 name_presentation() const;
  inline void set_name_presentation(::google::protobuf::int32 value);
  
  // optional .ril_proto.RilUusInfo uus_info = 13;
  inline bool has_uus_info() const;
  inline void clear_uus_info();
  static const int kUusInfoFieldNumber = 13;
  inline const ::ril_proto::RilUusInfo& uus_info() const;
  inline ::ril_proto::RilUusInfo* mutable_uus_info();
  
  // @@protoc_insertion_point(class_scope:ril_proto.RilCall)
 private:
  ::google::protobuf::UnknownFieldSet _unknown_fields_;
  mutable int _cached_size_;
  
  int state_;
  ::google::protobuf::int32 index_;
  ::google::protobuf::int32 toa_;
  bool is_mpty_;
  bool is_mt_;
  ::google::protobuf::int32 als_;
  bool is_voice_;
  bool is_voice_privacy_;
  ::std::string* number_;
  static const ::std::string _default_number_;
  ::google::protobuf::int32 number_presentation_;
  ::std::string* name_;
  static const ::std::string _default_name_;
  ::google::protobuf::int32 name_presentation_;
  ::ril_proto::RilUusInfo* uus_info_;
  friend void  protobuf_AddDesc_ril_2eproto();
  friend void protobuf_AssignDesc_ril_2eproto();
  friend void protobuf_ShutdownFile_ril_2eproto();
  
  ::google::protobuf::uint32 _has_bits_[(13 + 31) / 32];
  
  // WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
  inline bool _has_bit(int index) const {
    return (_has_bits_[index / 32] & (1u << (index % 32))) != 0;
  }
  inline void _set_bit(int index) {
    _has_bits_[index / 32] |= (1u << (index % 32));
  }
  inline void _clear_bit(int index) {
    _has_bits_[index / 32] &= ~(1u << (index % 32));
  }
  
  void InitAsDefaultInstance();
  static RilCall* default_instance_;
};
// -------------------------------------------------------------------

class RILGWSignalStrength : public ::google::protobuf::Message {
 public:
  RILGWSignalStrength();
  virtual ~RILGWSignalStrength();
  
  RILGWSignalStrength(const RILGWSignalStrength& from);
  
  inline RILGWSignalStrength& operator=(const RILGWSignalStrength& from) {
    CopyFrom(from);
    return *this;
  }
  
  inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
    return _unknown_fields_;
  }
  
  inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
    return &_unknown_fields_;
  }
  
  static const ::google::protobuf::Descriptor* descriptor();
  static const RILGWSignalStrength& default_instance();
  
  void Swap(RILGWSignalStrength* other);
  
  // implements Message ----------------------------------------------
  
  RILGWSignalStrength* New() const;
  void CopyFrom(const ::google::protobuf::Message& from);
  void MergeFrom(const ::google::protobuf::Message& from);
  void CopyFrom(const RILGWSignalStrength& from);
  void MergeFrom(const RILGWSignalStrength& from);
  void Clear();
  bool IsInitialized() const;
  
  int ByteSize() const;
  bool MergePartialFromCodedStream(
      ::google::protobuf::io::CodedInputStream* input);
  void SerializeWithCachedSizes(
      ::google::protobuf::io::CodedOutputStream* output) const;
  ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
  int GetCachedSize() const { return _cached_size_; }
  private:
  void SharedCtor();
  void SharedDtor();
  void SetCachedSize(int size) const;
  public:
  
  ::google::protobuf::Metadata GetMetadata() const;
  
  // nested types ----------------------------------------------------
  
  // accessors -------------------------------------------------------
  
  // optional int32 signal_strength = 1;
  inline bool has_signal_strength() const;
  inline void clear_signal_strength();
  static const int kSignalStrengthFieldNumber = 1;
  inline ::google::protobuf::int32 signal_strength() const;
  inline void set_signal_strength(::google::protobuf::int32 value);
  
  // optional int32 bit_error_rate = 2;
  inline bool has_bit_error_rate() const;
  inline void clear_bit_error_rate();
  static const int kBitErrorRateFieldNumber = 2;
  inline ::google::protobuf::int32 bit_error_rate() const;
  inline void set_bit_error_rate(::google::protobuf::int32 value);
  
  // @@protoc_insertion_point(class_scope:ril_proto.RILGWSignalStrength)
 private:
  ::google::protobuf::UnknownFieldSet _unknown_fields_;
  mutable int _cached_size_;
  
  ::google::protobuf::int32 signal_strength_;
  ::google::protobuf::int32 bit_error_rate_;
  friend void  protobuf_AddDesc_ril_2eproto();
  friend void protobuf_AssignDesc_ril_2eproto();
  friend void protobuf_ShutdownFile_ril_2eproto();
  
  ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32];
  
  // WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
  inline bool _has_bit(int index) const {
    return (_has_bits_[index / 32] & (1u << (index % 32))) != 0;
  }
  inline void _set_bit(int index) {
    _has_bits_[index / 32] |= (1u << (index % 32));
  }
  inline void _clear_bit(int index) {
    _has_bits_[index / 32] &= ~(1u << (index % 32));
  }
  
  void InitAsDefaultInstance();
  static RILGWSignalStrength* default_instance_;
};
// -------------------------------------------------------------------

class RILCDMASignalStrength : public ::google::protobuf::Message {
 public:
  RILCDMASignalStrength();
  virtual ~RILCDMASignalStrength();
  
  RILCDMASignalStrength(const RILCDMASignalStrength& from);
  
  inline RILCDMASignalStrength& operator=(const RILCDMASignalStrength& from) {
    CopyFrom(from);
    return *this;
  }
  
  inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
    return _unknown_fields_;
  }
  
  inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
    return &_unknown_fields_;
  }
  
  static const ::google::protobuf::Descriptor* descriptor();
  static const RILCDMASignalStrength& default_instance();
  
  void Swap(RILCDMASignalStrength* other);
  
  // implements Message ----------------------------------------------
  
  RILCDMASignalStrength* New() const;
  void CopyFrom(const ::google::protobuf::Message& from);
  void MergeFrom(const ::google::protobuf::Message& from);
  void CopyFrom(const RILCDMASignalStrength& from);
  void MergeFrom(const RILCDMASignalStrength& from);
  void Clear();
  bool IsInitialized() const;
  
  int ByteSize() const;
  bool MergePartialFromCodedStream(
      ::google::protobuf::io::CodedInputStream* input);
  void SerializeWithCachedSizes(
      ::google::protobuf::io::CodedOutputStream* output) const;
  ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
  int GetCachedSize() const { return _cached_size_; }
  private:
  void SharedCtor();
  void SharedDtor();
  void SetCachedSize(int size) const;
  public:
  
  ::google::protobuf::Metadata GetMetadata() const;
  
  // nested types ----------------------------------------------------
  
  // accessors -------------------------------------------------------
  
  // optional int32 dbm = 1;
  inline bool has_dbm() const;
  inline void clear_dbm();
  static const int kDbmFieldNumber = 1;
  inline ::google::protobuf::int32 dbm() const;
  inline void set_dbm(::google::protobuf::int32 value);
  
  // optional int32 ecio = 2;
  inline bool has_ecio() const;
  inline void clear_ecio();
  static const int kEcioFieldNumber = 2;
  inline ::google::protobuf::int32 ecio() const;
  inline void set_ecio(::google::protobuf::int32 value);
  
  // @@protoc_insertion_point(class_scope:ril_proto.RILCDMASignalStrength)
 private:
  ::google::protobuf::UnknownFieldSet _unknown_fields_;
  mutable int _cached_size_;
  
  ::google::protobuf::int32 dbm_;
  ::google::protobuf::int32 ecio_;
  friend void  protobuf_AddDesc_ril_2eproto();
  friend void protobuf_AssignDesc_ril_2eproto();
  friend void protobuf_ShutdownFile_ril_2eproto();
  
  ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32];
  
  // WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
  inline bool _has_bit(int index) const {
    return (_has_bits_[index / 32] & (1u << (index % 32))) != 0;
  }
  inline void _set_bit(int index) {
    _has_bits_[index / 32] |= (1u << (index % 32));
  }
  inline void _clear_bit(int index) {
    _has_bits_[index / 32] &= ~(1u << (index % 32));
  }
  
  void InitAsDefaultInstance();
  static RILCDMASignalStrength* default_instance_;
};
// -------------------------------------------------------------------

class RILEVDOSignalStrength : public ::google::protobuf::Message {
 public:
  RILEVDOSignalStrength();
  virtual ~RILEVDOSignalStrength();
  
  RILEVDOSignalStrength(const RILEVDOSignalStrength& from);
  
  inline RILEVDOSignalStrength& operator=(const RILEVDOSignalStrength& from) {
    CopyFrom(from);
    return *this;
  }
  
  inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
    return _unknown_fields_;
  }
  
  inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
    return &_unknown_fields_;
  }
  
  static const ::google::protobuf::Descriptor* descriptor();
  static const RILEVDOSignalStrength& default_instance();
  
  void Swap(RILEVDOSignalStrength* other);
  
  // implements Message ----------------------------------------------
  
  RILEVDOSignalStrength* New() const;
  void CopyFrom(const ::google::protobuf::Message& from);
  void MergeFrom(const ::google::protobuf::Message& from);
  void CopyFrom(const RILEVDOSignalStrength& from);
  void MergeFrom(const RILEVDOSignalStrength& from);
  void Clear();
  bool IsInitialized() const;
  
  int ByteSize() const;
  bool MergePartialFromCodedStream(
      ::google::protobuf::io::CodedInputStream* input);
  void SerializeWithCachedSizes(
      ::google::protobuf::io::CodedOutputStream* output) const;
  ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
  int GetCachedSize() const { return _cached_size_; }
  private:
  void SharedCtor();
  void SharedDtor();
  void SetCachedSize(int size) const;
  public:
  
  ::google::protobuf::Metadata GetMetadata() const;
  
  // nested types ----------------------------------------------------
  
  // accessors -------------------------------------------------------
  
  // optional int32 dbm = 1;
  inline bool has_dbm() const;
  inline void clear_dbm();
  static const int kDbmFieldNumber = 1;
  inline ::google::protobuf::int32 dbm() const;
  inline void set_dbm(::google::protobuf::int32 value);
  
  // optional int32 ecio = 2;
  inline bool has_ecio() const;
  inline void clear_ecio();
  static const int kEcioFieldNumber = 2;
  inline ::google::protobuf::int32 ecio() const;
  inline void set_ecio(::google::protobuf::int32 value);
  
  // optional int32 signal_noise_ratio = 3;
  inline bool has_signal_noise_ratio() const;
  inline void clear_signal_noise_ratio();
  static const int kSignalNoiseRatioFieldNumber = 3;
  inline ::google::protobuf::int32 signal_noise_ratio() const;
  inline void set_signal_noise_ratio(::google::protobuf::int32 value);
  
  // @@protoc_insertion_point(class_scope:ril_proto.RILEVDOSignalStrength)
 private:
  ::google::protobuf::UnknownFieldSet _unknown_fields_;
  mutable int _cached_size_;
  
  ::google::protobuf::int32 dbm_;
  ::google::protobuf::int32 ecio_;
  ::google::protobuf::int32 signal_noise_ratio_;
  friend void  protobuf_AddDesc_ril_2eproto();
  friend void protobuf_AssignDesc_ril_2eproto();
  friend void protobuf_ShutdownFile_ril_2eproto();
  
  ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32];
  
  // WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
  inline bool _has_bit(int index) const {
    return (_has_bits_[index / 32] & (1u << (index % 32))) != 0;
  }
  inline void _set_bit(int index) {
    _has_bits_[index / 32] |= (1u << (index % 32));
  }
  inline void _clear_bit(int index) {
    _has_bits_[index / 32] &= ~(1u << (index % 32));
  }
  
  void InitAsDefaultInstance();
  static RILEVDOSignalStrength* default_instance_;
};
// -------------------------------------------------------------------

class RspStrings : public ::google::protobuf::Message {
 public:
  RspStrings();
  virtual ~RspStrings();
  
  RspStrings(const RspStrings& from);
  
  inline RspStrings& operator=(const RspStrings& from) {
    CopyFrom(from);
    return *this;
  }
  
  inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
    return _unknown_fields_;
  }
  
  inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
    return &_unknown_fields_;
  }
  
  static const ::google::protobuf::Descriptor* descriptor();
  static const RspStrings& default_instance();
  
  void Swap(RspStrings* other);
  
  // implements Message ----------------------------------------------
  
  RspStrings* New() const;
  void CopyFrom(const ::google::protobuf::Message& from);
  void MergeFrom(const ::google::protobuf::Message& from);
  void CopyFrom(const RspStrings& from);
  void MergeFrom(const RspStrings& from);
  void Clear();
  bool IsInitialized() const;
  
  int ByteSize() const;
  bool MergePartialFromCodedStream(
      ::google::protobuf::io::CodedInputStream* input);
  void SerializeWithCachedSizes(
      ::google::protobuf::io::CodedOutputStream* output) const;
  ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
  int GetCachedSize() const { return _cached_size_; }
  private:
  void SharedCtor();
  void SharedDtor();
  void SetCachedSize(int size) const;
  public:
  
  ::google::protobuf::Metadata GetMetadata() const;
  
  // nested types ----------------------------------------------------
  
  // accessors -------------------------------------------------------
  
  // repeated string strings = 1;
  inline int strings_size() const;
  inline void clear_strings();
  static const int kStringsFieldNumber = 1;
  inline const ::std::string& strings(int index) const;
  inline ::std::string* mutable_strings(int index);
  inline void set_strings(int index, const ::std::string& value);
  inline void set_strings(int index, const char* value);
  inline void set_strings(int index, const char* value, size_t size);
  inline ::std::string* add_strings();
  inline void add_strings(const ::std::string& value);
  inline void add_strings(const char* value);
  inline void add_strings(const char* value, size_t size);
  inline const ::google::protobuf::RepeatedPtrField< ::std::string>& strings() const;
  inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_strings();
  
  // @@protoc_insertion_point(class_scope:ril_proto.RspStrings)
 private:
  ::google::protobuf::UnknownFieldSet _unknown_fields_;
  mutable int _cached_size_;
  
  ::google::protobuf::RepeatedPtrField< ::std::string> strings_;
  friend void  protobuf_AddDesc_ril_2eproto();
  friend void protobuf_AssignDesc_ril_2eproto();
  friend void protobuf_ShutdownFile_ril_2eproto();
  
  ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32];
  
  // WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
  inline bool _has_bit(int index) const {
    return (_has_bits_[index / 32] & (1u << (index % 32))) != 0;
  }
  inline void _set_bit(int index) {
    _has_bits_[index / 32] |= (1u << (index % 32));
  }
  inline void _clear_bit(int index) {
    _has_bits_[index / 32] &= ~(1u << (index % 32));
  }
  
  void InitAsDefaultInstance();
  static RspStrings* default_instance_;
};
// -------------------------------------------------------------------

class RspIntegers : public ::google::protobuf::Message {
 public:
  RspIntegers();
  virtual ~RspIntegers();
  
  RspIntegers(const RspIntegers& from);
  
  inline RspIntegers& operator=(const RspIntegers& from) {
    CopyFrom(from);
    return *this;
  }
  
  inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
    return _unknown_fields_;
  }
  
  inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
    return &_unknown_fields_;
  }
  
  static const ::google::protobuf::Descriptor* descriptor();
  static const RspIntegers& default_instance();
  
  void Swap(RspIntegers* other);
  
  // implements Message ----------------------------------------------
  
  RspIntegers* New() const;
  void CopyFrom(const ::google::protobuf::Message& from);
  void MergeFrom(const ::google::protobuf::Message& from);
  void CopyFrom(const RspIntegers& from);
  void MergeFrom(const RspIntegers& from);
  void Clear();
  bool IsInitialized() const;
  
  int ByteSize() const;
  bool MergePartialFromCodedStream(
      ::google::protobuf::io::CodedInputStream* input);
  void SerializeWithCachedSizes(
      ::google::protobuf::io::CodedOutputStream* output) const;
  ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
  int GetCachedSize() const { return _cached_size_; }
  private:
  void SharedCtor();
  void SharedDtor();
  void SetCachedSize(int size) const;
  public:
  
  ::google::protobuf::Metadata GetMetadata() const;
  
  // nested types ----------------------------------------------------
  
  // accessors -------------------------------------------------------
  
  // repeated int32 integers = 1;
  inline int integers_size() const;
  inline void clear_integers();
  static const int kIntegersFieldNumber = 1;
  inline ::google::protobuf::int32 integers(int index) const;
  inline void set_integers(int index, ::google::protobuf::int32 value);
  inline void add_integers(::google::protobuf::int32 value);
  inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >&
      integers() const;
  inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >*
      mutable_integers();
  
  // @@protoc_insertion_point(class_scope:ril_proto.RspIntegers)
 private:
  ::google::protobuf::UnknownFieldSet _unknown_fields_;
  mutable int _cached_size_;
  
  ::google::protobuf::RepeatedField< ::google::protobuf::int32 > integers_;
  friend void  protobuf_AddDesc_ril_2eproto();
  friend void protobuf_AssignDesc_ril_2eproto();
  friend void protobuf_ShutdownFile_ril_2eproto();
  
  ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32];
  
  // WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
  inline bool _has_bit(int index) const {
    return (_has_bits_[index / 32] & (1u << (index % 32))) != 0;
  }
  inline void _set_bit(int index) {
    _has_bits_[index / 32] |= (1u << (index % 32));
  }
  inline void _clear_bit(int index) {
    _has_bits_[index / 32] &= ~(1u << (index % 32));
  }
  
  void InitAsDefaultInstance();
  static RspIntegers* default_instance_;
};
// -------------------------------------------------------------------

class RspGetSimStatus : public ::google::protobuf::Message {
 public:
  RspGetSimStatus();
  virtual ~RspGetSimStatus();
  
  RspGetSimStatus(const RspGetSimStatus& from);
  
  inline RspGetSimStatus& operator=(const RspGetSimStatus& from) {
    CopyFrom(from);
    return *this;
  }
  
  inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
    return _unknown_fields_;
  }
  
  inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
    return &_unknown_fields_;
  }
  
  static const ::google::protobuf::Descriptor* descriptor();
  static const RspGetSimStatus& default_instance();
  
  void Swap(RspGetSimStatus* other);
  
  // implements Message ----------------------------------------------
  
  RspGetSimStatus* New() const;
  void CopyFrom(const ::google::protobuf::Message& from);
  void MergeFrom(const ::google::protobuf::Message& from);
  void CopyFrom(const RspGetSimStatus& from);
  void MergeFrom(const RspGetSimStatus& from);
  void Clear();
  bool IsInitialized() const;
  
  int ByteSize() const;
  bool MergePartialFromCodedStream(
      ::google::protobuf::io::CodedInputStream* input);
  void SerializeWithCachedSizes(
      ::google::protobuf::io::CodedOutputStream* output) const;
  ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
  int GetCachedSize() const { return _cached_size_; }
  private:
  void SharedCtor();
  void SharedDtor();
  void SetCachedSize(int size) const;
  public:
  
  ::google::protobuf::Metadata GetMetadata() const;
  
  // nested types ----------------------------------------------------
  
  // accessors -------------------------------------------------------
  
  // required .ril_proto.RilCardStatus card_status = 1;
  inline bool has_card_status() const;
  inline void clear_card_status();
  static const int kCardStatusFieldNumber = 1;
  inline const ::ril_proto::RilCardStatus& card_status() const;
  inline ::ril_proto::RilCardStatus* mutable_card_status();
  
  // @@protoc_insertion_point(class_scope:ril_proto.RspGetSimStatus)
 private:
  ::google::protobuf::UnknownFieldSet _unknown_fields_;
  mutable int _cached_size_;
  
  ::ril_proto::RilCardStatus* card_status_;
  friend void  protobuf_AddDesc_ril_2eproto();
  friend void protobuf_AssignDesc_ril_2eproto();
  friend void protobuf_ShutdownFile_ril_2eproto();
  
  ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32];
  
  // WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
  inline bool _has_bit(int index) const {
    return (_has_bits_[index / 32] & (1u << (index % 32))) != 0;
  }
  inline void _set_bit(int index) {
    _has_bits_[index / 32] |= (1u << (index % 32));
  }
  inline void _clear_bit(int index) {
    _has_bits_[index / 32] &= ~(1u << (index % 32));
  }
  
  void InitAsDefaultInstance();
  static RspGetSimStatus* default_instance_;
};
// -------------------------------------------------------------------

class ReqEnterSimPin : public ::google::protobuf::Message {
 public:
  ReqEnterSimPin();
  virtual ~ReqEnterSimPin();
  
  ReqEnterSimPin(const ReqEnterSimPin& from);
  
  inline ReqEnterSimPin& operator=(const ReqEnterSimPin& from) {
    CopyFrom(from);
    return *this;
  }
  
  inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
    return _unknown_fields_;
  }
  
  inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
    return &_unknown_fields_;
  }
  
  static const ::google::protobuf::Descriptor* descriptor();
  static const ReqEnterSimPin& default_instance();
  
  void Swap(ReqEnterSimPin* other);
  
  // implements Message ----------------------------------------------
  
  ReqEnterSimPin* New() const;
  void CopyFrom(const ::google::protobuf::Message& from);
  void MergeFrom(const ::google::protobuf::Message& from);
  void CopyFrom(const ReqEnterSimPin& from);
  void MergeFrom(const ReqEnterSimPin& from);
  void Clear();
  bool IsInitialized() const;
  
  int ByteSize() const;
  bool MergePartialFromCodedStream(
      ::google::protobuf::io::CodedInputStream* input);
  void SerializeWithCachedSizes(
      ::google::protobuf::io::CodedOutputStream* output) const;
  ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
  int GetCachedSize() const { return _cached_size_; }
  private:
  void SharedCtor();
  void SharedDtor();
  void SetCachedSize(int size) const;
  public:
  
  ::google::protobuf::Metadata GetMetadata() const;
  
  // nested types ----------------------------------------------------
  
  // accessors -------------------------------------------------------
  
  // required string pin = 1;
  inline bool has_pin() const;
  inline void clear_pin();
  static const int kPinFieldNumber = 1;
  inline const ::std::string& pin() const;
  inline void set_pin(const ::std::string& value);
  inline void set_pin(const char* value);
  inline void set_pin(const char* value, size_t size);
  inline ::std::string* mutable_pin();
  
  // @@protoc_insertion_point(class_scope:ril_proto.ReqEnterSimPin)
 private:
  ::google::protobuf::UnknownFieldSet _unknown_fields_;
  mutable int _cached_size_;
  
  ::std::string* pin_;
  static const ::std::string _default_pin_;
  friend void  protobuf_AddDesc_ril_2eproto();
  friend void protobuf_AssignDesc_ril_2eproto();
  friend void protobuf_ShutdownFile_ril_2eproto();
  
  ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32];
  
  // WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
  inline bool _has_bit(int index) const {
    return (_has_bits_[index / 32] & (1u << (index % 32))) != 0;
  }
  inline void _set_bit(int index) {
    _has_bits_[index / 32] |= (1u << (index % 32));
  }
  inline void _clear_bit(int index) {
    _has_bits_[index / 32] &= ~(1u << (index % 32));
  }
  
  void InitAsDefaultInstance();
  static ReqEnterSimPin* default_instance_;
};
// -------------------------------------------------------------------

class RspEnterSimPin : public ::google::protobuf::Message {
 public:
  RspEnterSimPin();
  virtual ~RspEnterSimPin();
  
  RspEnterSimPin(const RspEnterSimPin& from);
  
  inline RspEnterSimPin& operator=(const RspEnterSimPin& from) {
    CopyFrom(from);
    return *this;
  }
  
  inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
    return _unknown_fields_;
  }
  
  inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
    return &_unknown_fields_;
  }
  
  static const ::google::protobuf::Descriptor* descriptor();
  static const RspEnterSimPin& default_instance();
  
  void Swap(RspEnterSimPin* other);
  
  // implements Message ----------------------------------------------
  
  RspEnterSimPin* New() const;
  void CopyFrom(const ::google::protobuf::Message& from);
  void MergeFrom(const ::google::protobuf::Message& from);
  void CopyFrom(const RspEnterSimPin& from);
  void MergeFrom(const RspEnterSimPin& from);
  void Clear();
  bool IsInitialized() const;
  
  int ByteSize() const;
  bool MergePartialFromCodedStream(
      ::google::protobuf::io::CodedInputStream* input);
  void SerializeWithCachedSizes(
      ::google::protobuf::io::CodedOutputStream* output) const;
  ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
  int GetCachedSize() const { return _cached_size_; }
  private:
  void SharedCtor();
  void SharedDtor();
  void SetCachedSize(int size) const;
  public:
  
  ::google::protobuf::Metadata GetMetadata() const;
  
  // nested types ----------------------------------------------------
  
  // accessors -------------------------------------------------------
  
  // required int32 retries_remaining = 1;
  inline bool has_retries_remaining() const;
  inline void clear_retries_remaining();
  static const int kRetriesRemainingFieldNumber = 1;
  inline ::google::protobuf::int32 retries_remaining() const;
  inline void set_retries_remaining(::google::protobuf::int32 value);
  
  // @@protoc_insertion_point(class_scope:ril_proto.RspEnterSimPin)
 private:
  ::google::protobuf::UnknownFieldSet _unknown_fields_;
  mutable int _cached_size_;
  
  ::google::protobuf::int32 retries_remaining_;
  friend void  protobuf_AddDesc_ril_2eproto();
  friend void protobuf_AssignDesc_ril_2eproto();
  friend void protobuf_ShutdownFile_ril_2eproto();
  
  ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32];
  
  // WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
  inline bool _has_bit(int index) const {
    return (_has_bits_[index / 32] & (1u << (index % 32))) != 0;
  }
  inline void _set_bit(int index) {
    _has_bits_[index / 32] |= (1u << (index % 32));
  }
  inline void _clear_bit(int index) {
    _has_bits_[index / 32] &= ~(1u << (index % 32));
  }
  
  void InitAsDefaultInstance();
  static RspEnterSimPin* default_instance_;
};
// -------------------------------------------------------------------

class RspGetCurrentCalls : public ::google::protobuf::Message {
 public:
  RspGetCurrentCalls();
  virtual ~RspGetCurrentCalls();
  
  RspGetCurrentCalls(const RspGetCurrentCalls& from);
  
  inline RspGetCurrentCalls& operator=(const RspGetCurrentCalls& from) {
    CopyFrom(from);
    return *this;
  }
  
  inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
    return _unknown_fields_;
  }
  
  inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
    return &_unknown_fields_;
  }
  
  static const ::google::protobuf::Descriptor* descriptor();
  static const RspGetCurrentCalls& default_instance();
  
  void Swap(RspGetCurrentCalls* other);
  
  // implements Message ----------------------------------------------
  
  RspGetCurrentCalls* New() const;
  void CopyFrom(const ::google::protobuf::Message& from);
  void MergeFrom(const ::google::protobuf::Message& from);
  void CopyFrom(const RspGetCurrentCalls& from);
  void MergeFrom(const RspGetCurrentCalls& from);
  void Clear();
  bool IsInitialized() const;
  
  int ByteSize() const;
  bool MergePartialFromCodedStream(
      ::google::protobuf::io::CodedInputStream* input);
  void SerializeWithCachedSizes(
      ::google::protobuf::io::CodedOutputStream* output) const;
  ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
  int GetCachedSize() const { return _cached_size_; }
  private:
  void SharedCtor();
  void SharedDtor();
  void SetCachedSize(int size) const;
  public:
  
  ::google::protobuf::Metadata GetMetadata() const;
  
  // nested types ----------------------------------------------------
  
  // accessors -------------------------------------------------------
  
  // repeated .ril_proto.RilCall calls = 1;
  inline int calls_size() const;
  inline void clear_calls();
  static const int kCallsFieldNumber = 1;
  inline const ::ril_proto::RilCall& calls(int index) const;
  inline ::ril_proto::RilCall* mutable_calls(int index);
  inline ::ril_proto::RilCall* add_calls();
  inline const ::google::protobuf::RepeatedPtrField< ::ril_proto::RilCall >&
      calls() const;
  inline ::google::protobuf::RepeatedPtrField< ::ril_proto::RilCall >*
      mutable_calls();
  
  // @@protoc_insertion_point(class_scope:ril_proto.RspGetCurrentCalls)
 private:
  ::google::protobuf::UnknownFieldSet _unknown_fields_;
  mutable int _cached_size_;
  
  ::google::protobuf::RepeatedPtrField< ::ril_proto::RilCall > calls_;
  friend void  protobuf_AddDesc_ril_2eproto();
  friend void protobuf_AssignDesc_ril_2eproto();
  friend void protobuf_ShutdownFile_ril_2eproto();
  
  ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32];
  
  // WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
  inline bool _has_bit(int index) const {
    return (_has_bits_[index / 32] & (1u << (index % 32))) != 0;
  }
  inline void _set_bit(int index) {
    _has_bits_[index / 32] |= (1u << (index % 32));
  }
  inline void _clear_bit(int index) {
    _has_bits_[index / 32] &= ~(1u << (index % 32));
  }
  
  void InitAsDefaultInstance();
  static RspGetCurrentCalls* default_instance_;
};
// -------------------------------------------------------------------

class ReqDial : public ::google::protobuf::Message {
 public:
  ReqDial();
  virtual ~ReqDial();
  
  ReqDial(const ReqDial& from);
  
  inline ReqDial& operator=(const ReqDial& from) {
    CopyFrom(from);
    return *this;
  }
  
  inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
    return _unknown_fields_;
  }
  
  inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
    return &_unknown_fields_;
  }
  
  static const ::google::protobuf::Descriptor* descriptor();
  static const ReqDial& default_instance();
  
  void Swap(ReqDial* other);
  
  // implements Message ----------------------------------------------
  
  ReqDial* New() const;
  void CopyFrom(const ::google::protobuf::Message& from);
  void MergeFrom(const ::google::protobuf::Message& from);
  void CopyFrom(const ReqDial& from);
  void MergeFrom(const ReqDial& from);
  void Clear();
  bool IsInitialized() const;
  
  int ByteSize() const;
  bool MergePartialFromCodedStream(
      ::google::protobuf::io::CodedInputStream* input);
  void SerializeWithCachedSizes(
      ::google::protobuf::io::CodedOutputStream* output) const;
  ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
  int GetCachedSize() const { return _cached_size_; }
  private:
  void SharedCtor();
  void SharedDtor();
  void SetCachedSize(int size) const;
  public:
  
  ::google::protobuf::Metadata GetMetadata() const;
  
  // nested types ----------------------------------------------------
  
  // accessors -------------------------------------------------------
  
  // optional string address = 1;
  inline bool has_address() const;
  inline void clear_address();
  static const int kAddressFieldNumber = 1;
  inline const ::std::string& address() const;
  inline void set_address(const ::std::string& value);
  inline void set_address(const char* value);
  inline void set_address(const char* value, size_t size);
  inline ::std::string* mutable_address();
  
  // optional int32 clir = 2;
  inline bool has_clir() const;
  inline void clear_clir();
  static const int kClirFieldNumber = 2;
  inline ::google::protobuf::int32 clir() const;
  inline void set_clir(::google::protobuf::int32 value);
  
  // optional .ril_proto.RilUusInfo uus_info = 3;
  inline bool has_uus_info() const;
  inline void clear_uus_info();
  static const int kUusInfoFieldNumber = 3;
  inline const ::ril_proto::RilUusInfo& uus_info() const;
  inline ::ril_proto::RilUusInfo* mutable_uus_info();
  
  // @@protoc_insertion_point(class_scope:ril_proto.ReqDial)
 private:
  ::google::protobuf::UnknownFieldSet _unknown_fields_;
  mutable int _cached_size_;
  
  ::std::string* address_;
  static const ::std::string _default_address_;
  ::google::protobuf::int32 clir_;
  ::ril_proto::RilUusInfo* uus_info_;
  friend void  protobuf_AddDesc_ril_2eproto();
  friend void protobuf_AssignDesc_ril_2eproto();
  friend void protobuf_ShutdownFile_ril_2eproto();
  
  ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32];
  
  // WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
  inline bool _has_bit(int index) const {
    return (_has_bits_[index / 32] & (1u << (index % 32))) != 0;
  }
  inline void _set_bit(int index) {
    _has_bits_[index / 32] |= (1u << (index % 32));
  }
  inline void _clear_bit(int index) {
    _has_bits_[index / 32] &= ~(1u << (index % 32));
  }
  
  void InitAsDefaultInstance();
  static ReqDial* default_instance_;
};
// -------------------------------------------------------------------

class ReqHangUp : public ::google::protobuf::Message {
 public:
  ReqHangUp();
  virtual ~ReqHangUp();
  
  ReqHangUp(const ReqHangUp& from);
  
  inline ReqHangUp& operator=(const ReqHangUp& from) {
    CopyFrom(from);
    return *this;
  }
  
  inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
    return _unknown_fields_;
  }
  
  inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
    return &_unknown_fields_;
  }
  
  static const ::google::protobuf::Descriptor* descriptor();
  static const ReqHangUp& default_instance();
  
  void Swap(ReqHangUp* other);
  
  // implements Message ----------------------------------------------
  
  ReqHangUp* New() const;
  void CopyFrom(const ::google::protobuf::Message& from);
  void MergeFrom(const ::google::protobuf::Message& from);
  void CopyFrom(const ReqHangUp& from);
  void MergeFrom(const ReqHangUp& from);
  void Clear();
  bool IsInitialized() const;
  
  int ByteSize() const;
  bool MergePartialFromCodedStream(
      ::google::protobuf::io::CodedInputStream* input);
  void SerializeWithCachedSizes(
      ::google::protobuf::io::CodedOutputStream* output) const;
  ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
  int GetCachedSize() const { return _cached_size_; }
  private:
  void SharedCtor();
  void SharedDtor();
  void SetCachedSize(int size) const;
  public:
  
  ::google::protobuf::Metadata GetMetadata() const;
  
  // nested types ----------------------------------------------------
  
  // accessors -------------------------------------------------------
  
  // required int32 connection_index = 1;
  inline bool has_connection_index() const;
  inline void clear_connection_index();
  static const int kConnectionIndexFieldNumber = 1;
  inline ::google::protobuf::int32 connection_index() const;
  inline void set_connection_index(::google::protobuf::int32 value);
  
  // @@protoc_insertion_point(class_scope:ril_proto.ReqHangUp)
 private:
  ::google::protobuf::UnknownFieldSet _unknown_fields_;
  mutable int _cached_size_;
  
  ::google::protobuf::int32 connection_index_;
  friend void  protobuf_AddDesc_ril_2eproto();
  friend void protobuf_AssignDesc_ril_2eproto();
  friend void protobuf_ShutdownFile_ril_2eproto();
  
  ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32];
  
  // WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
  inline bool _has_bit(int index) const {
    return (_has_bits_[index / 32] & (1u << (index % 32))) != 0;
  }
  inline void _set_bit(int index) {
    _has_bits_[index / 32] |= (1u << (index % 32));
  }
  inline void _clear_bit(int index) {
    _has_bits_[index / 32] &= ~(1u << (index % 32));
  }
  
  void InitAsDefaultInstance();
  static ReqHangUp* default_instance_;
};
// -------------------------------------------------------------------

class RspLastCallFailCause : public ::google::protobuf::Message {
 public:
  RspLastCallFailCause();
  virtual ~RspLastCallFailCause();
  
  RspLastCallFailCause(const RspLastCallFailCause& from);
  
  inline RspLastCallFailCause& operator=(const RspLastCallFailCause& from) {
    CopyFrom(from);
    return *this;
  }
  
  inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
    return _unknown_fields_;
  }
  
  inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
    return &_unknown_fields_;
  }
  
  static const ::google::protobuf::Descriptor* descriptor();
  static const RspLastCallFailCause& default_instance();
  
  void Swap(RspLastCallFailCause* other);
  
  // implements Message ----------------------------------------------
  
  RspLastCallFailCause* New() const;
  void CopyFrom(const ::google::protobuf::Message& from);
  void MergeFrom(const ::google::protobuf::Message& from);
  void CopyFrom(const RspLastCallFailCause& from);
  void MergeFrom(const RspLastCallFailCause& from);
  void Clear();
  bool IsInitialized() const;
  
  int ByteSize() const;
  bool MergePartialFromCodedStream(
      ::google::protobuf::io::CodedInputStream* input);
  void SerializeWithCachedSizes(
      ::google::protobuf::io::CodedOutputStream* output) const;
  ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
  int GetCachedSize() const { return _cached_size_; }
  private:
  void SharedCtor();
  void SharedDtor();
  void SetCachedSize(int size) const;
  public:
  
  ::google::protobuf::Metadata GetMetadata() const;
  
  // nested types ----------------------------------------------------
  
  // accessors -------------------------------------------------------
  
  // required int32 last_call_fail_cause = 1;
  inline bool has_last_call_fail_cause() const;
  inline void clear_last_call_fail_cause();
  static const int kLastCallFailCauseFieldNumber = 1;
  inline ::google::protobuf::int32 last_call_fail_cause() const;
  inline void set_last_call_fail_cause(::google::protobuf::int32 value);
  
  // @@protoc_insertion_point(class_scope:ril_proto.RspLastCallFailCause)
 private:
  ::google::protobuf::UnknownFieldSet _unknown_fields_;
  mutable int _cached_size_;
  
  ::google::protobuf::int32 last_call_fail_cause_;
  friend void  protobuf_AddDesc_ril_2eproto();
  friend void protobuf_AssignDesc_ril_2eproto();
  friend void protobuf_ShutdownFile_ril_2eproto();
  
  ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32];
  
  // WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
  inline bool _has_bit(int index) const {
    return (_has_bits_[index / 32] & (1u << (index % 32))) != 0;
  }
  inline void _set_bit(int index) {
    _has_bits_[index / 32] |= (1u << (index % 32));
  }
  inline void _clear_bit(int index) {
    _has_bits_[index / 32] &= ~(1u << (index % 32));
  }
  
  void InitAsDefaultInstance();
  static RspLastCallFailCause* default_instance_;
};
// -------------------------------------------------------------------

class RspSignalStrength : public ::google::protobuf::Message {
 public:
  RspSignalStrength();
  virtual ~RspSignalStrength();
  
  RspSignalStrength(const RspSignalStrength& from);
  
  inline RspSignalStrength& operator=(const RspSignalStrength& from) {
    CopyFrom(from);
    return *this;
  }
  
  inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
    return _unknown_fields_;
  }
  
  inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
    return &_unknown_fields_;
  }
  
  static const ::google::protobuf::Descriptor* descriptor();
  static const RspSignalStrength& default_instance();
  
  void Swap(RspSignalStrength* other);
  
  // implements Message ----------------------------------------------
  
  RspSignalStrength* New() const;
  void CopyFrom(const ::google::protobuf::Message& from);
  void MergeFrom(const ::google::protobuf::Message& from);
  void CopyFrom(const RspSignalStrength& from);
  void MergeFrom(const RspSignalStrength& from);
  void Clear();
  bool IsInitialized() const;
  
  int ByteSize() const;
  bool MergePartialFromCodedStream(
      ::google::protobuf::io::CodedInputStream* input);
  void SerializeWithCachedSizes(
      ::google::protobuf::io::CodedOutputStream* output) const;
  ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
  int GetCachedSize() const { return _cached_size_; }
  private:
  void SharedCtor();
  void SharedDtor();
  void SetCachedSize(int size) const;
  public:
  
  ::google::protobuf::Metadata GetMetadata() const;
  
  // nested types ----------------------------------------------------
  
  // accessors -------------------------------------------------------
  
  // optional .ril_proto.RILGWSignalStrength gw_signalstrength = 1;
  inline bool has_gw_signalstrength() const;
  inline void clear_gw_signalstrength();
  static const int kGwSignalstrengthFieldNumber = 1;
  inline const ::ril_proto::RILGWSignalStrength& gw_signalstrength() const;
  inline ::ril_proto::RILGWSignalStrength* mutable_gw_signalstrength();
  
  // optional .ril_proto.RILCDMASignalStrength cdma_signalstrength = 2;
  inline bool has_cdma_signalstrength() const;
  inline void clear_cdma_signalstrength();
  static const int kCdmaSignalstrengthFieldNumber = 2;
  inline const ::ril_proto::RILCDMASignalStrength& cdma_signalstrength() const;
  inline ::ril_proto::RILCDMASignalStrength* mutable_cdma_signalstrength();
  
  // optional .ril_proto.RILEVDOSignalStrength evdo_signalstrength = 3;
  inline bool has_evdo_signalstrength() const;
  inline void clear_evdo_signalstrength();
  static const int kEvdoSignalstrengthFieldNumber = 3;
  inline const ::ril_proto::RILEVDOSignalStrength& evdo_signalstrength() const;
  inline ::ril_proto::RILEVDOSignalStrength* mutable_evdo_signalstrength();
  
  // @@protoc_insertion_point(class_scope:ril_proto.RspSignalStrength)
 private:
  ::google::protobuf::UnknownFieldSet _unknown_fields_;
  mutable int _cached_size_;
  
  ::ril_proto::RILGWSignalStrength* gw_signalstrength_;
  ::ril_proto::RILCDMASignalStrength* cdma_signalstrength_;
  ::ril_proto::RILEVDOSignalStrength* evdo_signalstrength_;
  friend void  protobuf_AddDesc_ril_2eproto();
  friend void protobuf_AssignDesc_ril_2eproto();
  friend void protobuf_ShutdownFile_ril_2eproto();
  
  ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32];
  
  // WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
  inline bool _has_bit(int index) const {
    return (_has_bits_[index / 32] & (1u << (index % 32))) != 0;
  }
  inline void _set_bit(int index) {
    _has_bits_[index / 32] |= (1u << (index % 32));
  }
  inline void _clear_bit(int index) {
    _has_bits_[index / 32] &= ~(1u << (index % 32));
  }
  
  void InitAsDefaultInstance();
  static RspSignalStrength* default_instance_;
};
// -------------------------------------------------------------------

class RspOperator : public ::google::protobuf::Message {
 public:
  RspOperator();
  virtual ~RspOperator();
  
  RspOperator(const RspOperator& from);
  
  inline RspOperator& operator=(const RspOperator& from) {
    CopyFrom(from);
    return *this;
  }
  
  inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
    return _unknown_fields_;
  }
  
  inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
    return &_unknown_fields_;
  }
  
  static const ::google::protobuf::Descriptor* descriptor();
  static const RspOperator& default_instance();
  
  void Swap(RspOperator* other);
  
  // implements Message ----------------------------------------------
  
  RspOperator* New() const;
  void CopyFrom(const ::google::protobuf::Message& from);
  void MergeFrom(const ::google::protobuf::Message& from);
  void CopyFrom(const RspOperator& from);
  void MergeFrom(const RspOperator& from);
  void Clear();
  bool IsInitialized() const;
  
  int ByteSize() const;
  bool MergePartialFromCodedStream(
      ::google::protobuf::io::CodedInputStream* input);
  void SerializeWithCachedSizes(
      ::google::protobuf::io::CodedOutputStream* output) const;
  ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
  int GetCachedSize() const { return _cached_size_; }
  private:
  void SharedCtor();
  void SharedDtor();
  void SetCachedSize(int size) const;
  public:
  
  ::google::protobuf::Metadata GetMetadata() const;
  
  // nested types ----------------------------------------------------
  
  // accessors -------------------------------------------------------
  
  // optional string long_alpha_ons = 1;
  inline bool has_long_alpha_ons() const;
  inline void clear_long_alpha_ons();
  static const int kLongAlphaOnsFieldNumber = 1;
  inline const ::std::string& long_alpha_ons() const;
  inline void set_long_alpha_ons(const ::std::string& value);
  inline void set_long_alpha_ons(const char* value);
  inline void set_long_alpha_ons(const char* value, size_t size);
  inline ::std::string* mutable_long_alpha_ons();
  
  // optional string short_alpha_ons = 2;
  inline bool has_short_alpha_ons() const;
  inline void clear_short_alpha_ons();
  static const int kShortAlphaOnsFieldNumber = 2;
  inline const ::std::string& short_alpha_ons() const;
  inline void set_short_alpha_ons(const ::std::string& value);
  inline void set_short_alpha_ons(const char* value);
  inline void set_short_alpha_ons(const char* value, size_t size);
  inline ::std::string* mutable_short_alpha_ons();
  
  // optional string mcc_mnc = 3;
  inline bool has_mcc_mnc() const;
  inline void clear_mcc_mnc();
  static const int kMccMncFieldNumber = 3;
  inline const ::std::string& mcc_mnc() const;
  inline void set_mcc_mnc(const ::std::string& value);
  inline void set_mcc_mnc(const char* value);
  inline void set_mcc_mnc(const char* value, size_t size);
  inline ::std::string* mutable_mcc_mnc();
  
  // @@protoc_insertion_point(class_scope:ril_proto.RspOperator)
 private:
  ::google::protobuf::UnknownFieldSet _unknown_fields_;
  mutable int _cached_size_;
  
  ::std::string* long_alpha_ons_;
  static const ::std::string _default_long_alpha_ons_;
  ::std::string* short_alpha_ons_;
  static const ::std::string _default_short_alpha_ons_;
  ::std::string* mcc_mnc_;
  static const ::std::string _default_mcc_mnc_;
  friend void  protobuf_AddDesc_ril_2eproto();
  friend void protobuf_AssignDesc_ril_2eproto();
  friend void protobuf_ShutdownFile_ril_2eproto();
  
  ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32];
  
  // WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
  inline bool _has_bit(int index) const {
    return (_has_bits_[index / 32] & (1u << (index % 32))) != 0;
  }
  inline void _set_bit(int index) {
    _has_bits_[index / 32] |= (1u << (index % 32));
  }
  inline void _clear_bit(int index) {
    _has_bits_[index / 32] &= ~(1u << (index % 32));
  }
  
  void InitAsDefaultInstance();
  static RspOperator* default_instance_;
};
// -------------------------------------------------------------------

class ReqSeparateConnection : public ::google::protobuf::Message {
 public:
  ReqSeparateConnection();
  virtual ~ReqSeparateConnection();
  
  ReqSeparateConnection(const ReqSeparateConnection& from);
  
  inline ReqSeparateConnection& operator=(const ReqSeparateConnection& from) {
    CopyFrom(from);
    return *this;
  }
  
  inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
    return _unknown_fields_;
  }
  
  inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
    return &_unknown_fields_;
  }
  
  static const ::google::protobuf::Descriptor* descriptor();
  static const ReqSeparateConnection& default_instance();
  
  void Swap(ReqSeparateConnection* other);
  
  // implements Message ----------------------------------------------
  
  ReqSeparateConnection* New() const;
  void CopyFrom(const ::google::protobuf::Message& from);
  void MergeFrom(const ::google::protobuf::Message& from);
  void CopyFrom(const ReqSeparateConnection& from);
  void MergeFrom(const ReqSeparateConnection& from);
  void Clear();
  bool IsInitialized() const;
  
  int ByteSize() const;
  bool MergePartialFromCodedStream(
      ::google::protobuf::io::CodedInputStream* input);
  void SerializeWithCachedSizes(
      ::google::protobuf::io::CodedOutputStream* output) const;
  ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
  int GetCachedSize() const { return _cached_size_; }
  private:
  void SharedCtor();
  void SharedDtor();
  void SetCachedSize(int size) const;
  public:
  
  ::google::protobuf::Metadata GetMetadata() const;
  
  // nested types ----------------------------------------------------
  
  // accessors -------------------------------------------------------
  
  // required int32 index = 1;
  inline bool has_index() const;
  inline void clear_index();
  static const int kIndexFieldNumber = 1;
  inline ::google::protobuf::int32 index() const;
  inline void set_index(::google::protobuf::int32 value);
  
  // @@protoc_insertion_point(class_scope:ril_proto.ReqSeparateConnection)
 private:
  ::google::protobuf::UnknownFieldSet _unknown_fields_;
  mutable int _cached_size_;
  
  ::google::protobuf::int32 index_;
  friend void  protobuf_AddDesc_ril_2eproto();
  friend void protobuf_AssignDesc_ril_2eproto();
  friend void protobuf_ShutdownFile_ril_2eproto();
  
  ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32];
  
  // WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
  inline bool _has_bit(int index) const {
    return (_has_bits_[index / 32] & (1u << (index % 32))) != 0;
  }
  inline void _set_bit(int index) {
    _has_bits_[index / 32] |= (1u << (index % 32));
  }
  inline void _clear_bit(int index) {
    _has_bits_[index / 32] &= ~(1u << (index % 32));
  }
  
  void InitAsDefaultInstance();
  static ReqSeparateConnection* default_instance_;
};
// -------------------------------------------------------------------

class ReqSetMute : public ::google::protobuf::Message {
 public:
  ReqSetMute();
  virtual ~ReqSetMute();
  
  ReqSetMute(const ReqSetMute& from);
  
  inline ReqSetMute& operator=(const ReqSetMute& from) {
    CopyFrom(from);
    return *this;
  }
  
  inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
    return _unknown_fields_;
  }
  
  inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
    return &_unknown_fields_;
  }
  
  static const ::google::protobuf::Descriptor* descriptor();
  static const ReqSetMute& default_instance();
  
  void Swap(ReqSetMute* other);
  
  // implements Message ----------------------------------------------
  
  ReqSetMute* New() const;
  void CopyFrom(const ::google::protobuf::Message& from);
  void MergeFrom(const ::google::protobuf::Message& from);
  void CopyFrom(const ReqSetMute& from);
  void MergeFrom(const ReqSetMute& from);
  void Clear();
  bool IsInitialized() const;
  
  int ByteSize() const;
  bool MergePartialFromCodedStream(
      ::google::protobuf::io::CodedInputStream* input);
  void SerializeWithCachedSizes(
      ::google::protobuf::io::CodedOutputStream* output) const;
  ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
  int GetCachedSize() const { return _cached_size_; }
  private:
  void SharedCtor();
  void SharedDtor();
  void SetCachedSize(int size) const;
  public:
  
  ::google::protobuf::Metadata GetMetadata() const;
  
  // nested types ----------------------------------------------------
  
  // accessors -------------------------------------------------------
  
  // required bool state = 1;
  inline bool has_state() const;
  inline void clear_state();
  static const int kStateFieldNumber = 1;
  inline bool state() const;
  inline void set_state(bool value);
  
  // @@protoc_insertion_point(class_scope:ril_proto.ReqSetMute)
 private:
  ::google::protobuf::UnknownFieldSet _unknown_fields_;
  mutable int _cached_size_;
  
  bool state_;
  friend void  protobuf_AddDesc_ril_2eproto();
  friend void protobuf_AssignDesc_ril_2eproto();
  friend void protobuf_ShutdownFile_ril_2eproto();
  
  ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32];
  
  // WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
  inline bool _has_bit(int index) const {
    return (_has_bits_[index / 32] & (1u << (index % 32))) != 0;
  }
  inline void _set_bit(int index) {
    _has_bits_[index / 32] |= (1u << (index % 32));
  }
  inline void _clear_bit(int index) {
    _has_bits_[index / 32] &= ~(1u << (index % 32));
  }
  
  void InitAsDefaultInstance();
  static ReqSetMute* default_instance_;
};
// -------------------------------------------------------------------

class ReqScreenState : public ::google::protobuf::Message {
 public:
  ReqScreenState();
  virtual ~ReqScreenState();
  
  ReqScreenState(const ReqScreenState& from);
  
  inline ReqScreenState& operator=(const ReqScreenState& from) {
    CopyFrom(from);
    return *this;
  }
  
  inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
    return _unknown_fields_;
  }
  
  inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
    return &_unknown_fields_;
  }
  
  static const ::google::protobuf::Descriptor* descriptor();
  static const ReqScreenState& default_instance();
  
  void Swap(ReqScreenState* other);
  
  // implements Message ----------------------------------------------
  
  ReqScreenState* New() const;
  void CopyFrom(const ::google::protobuf::Message& from);
  void MergeFrom(const ::google::protobuf::Message& from);
  void CopyFrom(const ReqScreenState& from);
  void MergeFrom(const ReqScreenState& from);
  void Clear();
  bool IsInitialized() const;
  
  int ByteSize() const;
  bool MergePartialFromCodedStream(
      ::google::protobuf::io::CodedInputStream* input);
  void SerializeWithCachedSizes(
      ::google::protobuf::io::CodedOutputStream* output) const;
  ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
  int GetCachedSize() const { return _cached_size_; }
  private:
  void SharedCtor();
  void SharedDtor();
  void SetCachedSize(int size) const;
  public:
  
  ::google::protobuf::Metadata GetMetadata() const;
  
  // nested types ----------------------------------------------------
  
  // accessors -------------------------------------------------------
  
  // required bool state = 1;
  inline bool has_state() const;
  inline void clear_state();
  static const int kStateFieldNumber = 1;
  inline bool state() const;
  inline void set_state(bool value);
  
  // @@protoc_insertion_point(class_scope:ril_proto.ReqScreenState)
 private:
  ::google::protobuf::UnknownFieldSet _unknown_fields_;
  mutable int _cached_size_;
  
  bool state_;
  friend void  protobuf_AddDesc_ril_2eproto();
  friend void protobuf_AssignDesc_ril_2eproto();
  friend void protobuf_ShutdownFile_ril_2eproto();
  
  ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32];
  
  // WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
  inline bool _has_bit(int index) const {
    return (_has_bits_[index / 32] & (1u << (index % 32))) != 0;
  }
  inline void _set_bit(int index) {
    _has_bits_[index / 32] |= (1u << (index % 32));
  }
  inline void _clear_bit(int index) {
    _has_bits_[index / 32] &= ~(1u << (index % 32));
  }
  
  void InitAsDefaultInstance();
  static ReqScreenState* default_instance_;
};
// ===================================================================


// ===================================================================

// RilAppStatus

// optional .ril_proto.RilAppType app_type = 1;
inline bool RilAppStatus::has_app_type() const {
  return _has_bit(0);
}
inline void RilAppStatus::clear_app_type() {
  app_type_ = 0;
  _clear_bit(0);
}
inline ril_proto::RilAppType RilAppStatus::app_type() const {
  return static_cast< ril_proto::RilAppType >(app_type_);
}
inline void RilAppStatus::set_app_type(ril_proto::RilAppType value) {
  GOOGLE_DCHECK(ril_proto::RilAppType_IsValid(value));
  _set_bit(0);
  app_type_ = value;
}

// optional .ril_proto.RilAppState app_state = 2;
inline bool RilAppStatus::has_app_state() const {
  return _has_bit(1);
}
inline void RilAppStatus::clear_app_state() {
  app_state_ = 0;
  _clear_bit(1);
}
inline ril_proto::RilAppState RilAppStatus::app_state() const {
  return static_cast< ril_proto::RilAppState >(app_state_);
}
inline void RilAppStatus::set_app_state(ril_proto::RilAppState value) {
  GOOGLE_DCHECK(ril_proto::RilAppState_IsValid(value));
  _set_bit(1);
  app_state_ = value;
}

// optional .ril_proto.RilPersoSubstate perso_substate = 3;
inline bool RilAppStatus::has_perso_substate() const {
  return _has_bit(2);
}
inline void RilAppStatus::clear_perso_substate() {
  perso_substate_ = 0;
  _clear_bit(2);
}
inline ril_proto::RilPersoSubstate RilAppStatus::perso_substate() const {
  return static_cast< ril_proto::RilPersoSubstate >(perso_substate_);
}
inline void RilAppStatus::set_perso_substate(ril_proto::RilPersoSubstate value) {
  GOOGLE_DCHECK(ril_proto::RilPersoSubstate_IsValid(value));
  _set_bit(2);
  perso_substate_ = value;
}

// optional string aid = 4;
inline bool RilAppStatus::has_aid() const {
  return _has_bit(3);
}
inline void RilAppStatus::clear_aid() {
  if (aid_ != &_default_aid_) {
    aid_->clear();
  }
  _clear_bit(3);
}
inline const ::std::string& RilAppStatus::aid() const {
  return *aid_;
}
inline void RilAppStatus::set_aid(const ::std::string& value) {
  _set_bit(3);
  if (aid_ == &_default_aid_) {
    aid_ = new ::std::string;
  }
  aid_->assign(value);
}
inline void RilAppStatus::set_aid(const char* value) {
  _set_bit(3);
  if (aid_ == &_default_aid_) {
    aid_ = new ::std::string;
  }
  aid_->assign(value);
}
inline void RilAppStatus::set_aid(const char* value, size_t size) {
  _set_bit(3);
  if (aid_ == &_default_aid_) {
    aid_ = new ::std::string;
  }
  aid_->assign(reinterpret_cast<const char*>(value), size);
}
inline ::std::string* RilAppStatus::mutable_aid() {
  _set_bit(3);
  if (aid_ == &_default_aid_) {
    aid_ = new ::std::string;
  }
  return aid_;
}

// optional string app_label = 5;
inline bool RilAppStatus::has_app_label() const {
  return _has_bit(4);
}
inline void RilAppStatus::clear_app_label() {
  if (app_label_ != &_default_app_label_) {
    app_label_->clear();
  }
  _clear_bit(4);
}
inline const ::std::string& RilAppStatus::app_label() const {
  return *app_label_;
}
inline void RilAppStatus::set_app_label(const ::std::string& value) {
  _set_bit(4);
  if (app_label_ == &_default_app_label_) {
    app_label_ = new ::std::string;
  }
  app_label_->assign(value);
}
inline void RilAppStatus::set_app_label(const char* value) {
  _set_bit(4);
  if (app_label_ == &_default_app_label_) {
    app_label_ = new ::std::string;
  }
  app_label_->assign(value);
}
inline void RilAppStatus::set_app_label(const char* value, size_t size) {
  _set_bit(4);
  if (app_label_ == &_default_app_label_) {
    app_label_ = new ::std::string;
  }
  app_label_->assign(reinterpret_cast<const char*>(value), size);
}
inline ::std::string* RilAppStatus::mutable_app_label() {
  _set_bit(4);
  if (app_label_ == &_default_app_label_) {
    app_label_ = new ::std::string;
  }
  return app_label_;
}

// optional int32 pin1_replaced = 6;
inline bool RilAppStatus::has_pin1_replaced() const {
  return _has_bit(5);
}
inline void RilAppStatus::clear_pin1_replaced() {
  pin1_replaced_ = 0;
  _clear_bit(5);
}
inline ::google::protobuf::int32 RilAppStatus::pin1_replaced() const {
  return pin1_replaced_;
}
inline void RilAppStatus::set_pin1_replaced(::google::protobuf::int32 value) {
  _set_bit(5);
  pin1_replaced_ = value;
}

// optional .ril_proto.RilPinState pin1 = 7;
inline bool RilAppStatus::has_pin1() const {
  return _has_bit(6);
}
inline void RilAppStatus::clear_pin1() {
  pin1_ = 0;
  _clear_bit(6);
}
inline ril_proto::RilPinState RilAppStatus::pin1() const {
  return static_cast< ril_proto::RilPinState >(pin1_);
}
inline void RilAppStatus::set_pin1(ril_proto::RilPinState value) {
  GOOGLE_DCHECK(ril_proto::RilPinState_IsValid(value));
  _set_bit(6);
  pin1_ = value;
}

// optional .ril_proto.RilPinState pin2 = 8;
inline bool RilAppStatus::has_pin2() const {
  return _has_bit(7);
}
inline void RilAppStatus::clear_pin2() {
  pin2_ = 0;
  _clear_bit(7);
}
inline ril_proto::RilPinState RilAppStatus::pin2() const {
  return static_cast< ril_proto::RilPinState >(pin2_);
}
inline void RilAppStatus::set_pin2(ril_proto::RilPinState value) {
  GOOGLE_DCHECK(ril_proto::RilPinState_IsValid(value));
  _set_bit(7);
  pin2_ = value;
}

// -------------------------------------------------------------------

// RilCardStatus

// optional .ril_proto.RilCardState card_state = 1;
inline bool RilCardStatus::has_card_state() const {
  return _has_bit(0);
}
inline void RilCardStatus::clear_card_state() {
  card_state_ = 0;
  _clear_bit(0);
}
inline ril_proto::RilCardState RilCardStatus::card_state() const {
  return static_cast< ril_proto::RilCardState >(card_state_);
}
inline void RilCardStatus::set_card_state(ril_proto::RilCardState value) {
  GOOGLE_DCHECK(ril_proto::RilCardState_IsValid(value));
  _set_bit(0);
  card_state_ = value;
}

// optional .ril_proto.RilPinState universal_pin_state = 2;
inline bool RilCardStatus::has_universal_pin_state() const {
  return _has_bit(1);
}
inline void RilCardStatus::clear_universal_pin_state() {
  universal_pin_state_ = 0;
  _clear_bit(1);
}
inline ril_proto::RilPinState RilCardStatus::universal_pin_state() const {
  return static_cast< ril_proto::RilPinState >(universal_pin_state_);
}
inline void RilCardStatus::set_universal_pin_state(ril_proto::RilPinState value) {
  GOOGLE_DCHECK(ril_proto::RilPinState_IsValid(value));
  _set_bit(1);
  universal_pin_state_ = value;
}

// optional int32 gsm_umts_subscription_app_index = 3;
inline bool RilCardStatus::has_gsm_umts_subscription_app_index() const {
  return _has_bit(2);
}
inline void RilCardStatus::clear_gsm_umts_subscription_app_index() {
  gsm_umts_subscription_app_index_ = 0;
  _clear_bit(2);
}
inline ::google::protobuf::int32 RilCardStatus::gsm_umts_subscription_app_index() const {
  return gsm_umts_subscription_app_index_;
}
inline void RilCardStatus::set_gsm_umts_subscription_app_index(::google::protobuf::int32 value) {
  _set_bit(2);
  gsm_umts_subscription_app_index_ = value;
}

// optional int32 cdma_subscription_app_index = 4;
inline bool RilCardStatus::has_cdma_subscription_app_index() const {
  return _has_bit(3);
}
inline void RilCardStatus::clear_cdma_subscription_app_index() {
  cdma_subscription_app_index_ = 0;
  _clear_bit(3);
}
inline ::google::protobuf::int32 RilCardStatus::cdma_subscription_app_index() const {
  return cdma_subscription_app_index_;
}
inline void RilCardStatus::set_cdma_subscription_app_index(::google::protobuf::int32 value) {
  _set_bit(3);
  cdma_subscription_app_index_ = value;
}

// optional int32 num_applications = 5;
inline bool RilCardStatus::has_num_applications() const {
  return _has_bit(4);
}
inline void RilCardStatus::clear_num_applications() {
  num_applications_ = 0;
  _clear_bit(4);
}
inline ::google::protobuf::int32 RilCardStatus::num_applications() const {
  return num_applications_;
}
inline void RilCardStatus::set_num_applications(::google::protobuf::int32 value) {
  _set_bit(4);
  num_applications_ = value;
}

// repeated .ril_proto.RilAppStatus applications = 6;
inline int RilCardStatus::applications_size() const {
  return applications_.size();
}
inline void RilCardStatus::clear_applications() {
  applications_.Clear();
}
inline const ::ril_proto::RilAppStatus& RilCardStatus::applications(int index) const {
  return applications_.Get(index);
}
inline ::ril_proto::RilAppStatus* RilCardStatus::mutable_applications(int index) {
  return applications_.Mutable(index);
}
inline ::ril_proto::RilAppStatus* RilCardStatus::add_applications() {
  return applications_.Add();
}
inline const ::google::protobuf::RepeatedPtrField< ::ril_proto::RilAppStatus >&
RilCardStatus::applications() const {
  return applications_;
}
inline ::google::protobuf::RepeatedPtrField< ::ril_proto::RilAppStatus >*
RilCardStatus::mutable_applications() {
  return &applications_;
}

// -------------------------------------------------------------------

// RilUusInfo

// optional .ril_proto.RilUusType uus_type = 1;
inline bool RilUusInfo::has_uus_type() const {
  return _has_bit(0);
}
inline void RilUusInfo::clear_uus_type() {
  uus_type_ = 0;
  _clear_bit(0);
}
inline ril_proto::RilUusType RilUusInfo::uus_type() const {
  return static_cast< ril_proto::RilUusType >(uus_type_);
}
inline void RilUusInfo::set_uus_type(ril_proto::RilUusType value) {
  GOOGLE_DCHECK(ril_proto::RilUusType_IsValid(value));
  _set_bit(0);
  uus_type_ = value;
}

// optional .ril_proto.RilUusDcs uus_dcs = 2;
inline bool RilUusInfo::has_uus_dcs() const {
  return _has_bit(1);
}
inline void RilUusInfo::clear_uus_dcs() {
  uus_dcs_ = 0;
  _clear_bit(1);
}
inline ril_proto::RilUusDcs RilUusInfo::uus_dcs() const {
  return static_cast< ril_proto::RilUusDcs >(uus_dcs_);
}
inline void RilUusInfo::set_uus_dcs(ril_proto::RilUusDcs value) {
  GOOGLE_DCHECK(ril_proto::RilUusDcs_IsValid(value));
  _set_bit(1);
  uus_dcs_ = value;
}

// optional int32 uus_length = 3;
inline bool RilUusInfo::has_uus_length() const {
  return _has_bit(2);
}
inline void RilUusInfo::clear_uus_length() {
  uus_length_ = 0;
  _clear_bit(2);
}
inline ::google::protobuf::int32 RilUusInfo::uus_length() const {
  return uus_length_;
}
inline void RilUusInfo::set_uus_length(::google::protobuf::int32 value) {
  _set_bit(2);
  uus_length_ = value;
}

// optional string uus_data = 4;
inline bool RilUusInfo::has_uus_data() const {
  return _has_bit(3);
}
inline void RilUusInfo::clear_uus_data() {
  if (uus_data_ != &_default_uus_data_) {
    uus_data_->clear();
  }
  _clear_bit(3);
}
inline const ::std::string& RilUusInfo::uus_data() const {
  return *uus_data_;
}
inline void RilUusInfo::set_uus_data(const ::std::string& value) {
  _set_bit(3);
  if (uus_data_ == &_default_uus_data_) {
    uus_data_ = new ::std::string;
  }
  uus_data_->assign(value);
}
inline void RilUusInfo::set_uus_data(const char* value) {
  _set_bit(3);
  if (uus_data_ == &_default_uus_data_) {
    uus_data_ = new ::std::string;
  }
  uus_data_->assign(value);
}
inline void RilUusInfo::set_uus_data(const char* value, size_t size) {
  _set_bit(3);
  if (uus_data_ == &_default_uus_data_) {
    uus_data_ = new ::std::string;
  }
  uus_data_->assign(reinterpret_cast<const char*>(value), size);
}
inline ::std::string* RilUusInfo::mutable_uus_data() {
  _set_bit(3);
  if (uus_data_ == &_default_uus_data_) {
    uus_data_ = new ::std::string;
  }
  return uus_data_;
}

// -------------------------------------------------------------------

// RilCall

// optional .ril_proto.RilCallState state = 1;
inline bool RilCall::has_state() const {
  return _has_bit(0);
}
inline void RilCall::clear_state() {
  state_ = 0;
  _clear_bit(0);
}
inline ril_proto::RilCallState RilCall::state() const {
  return static_cast< ril_proto::RilCallState >(state_);
}
inline void RilCall::set_state(ril_proto::RilCallState value) {
  GOOGLE_DCHECK(ril_proto::RilCallState_IsValid(value));
  _set_bit(0);
  state_ = value;
}

// optional int32 index = 2;
inline bool RilCall::has_index() const {
  return _has_bit(1);
}
inline void RilCall::clear_index() {
  index_ = 0;
  _clear_bit(1);
}
inline ::google::protobuf::int32 RilCall::index() const {
  return index_;
}
inline void RilCall::set_index(::google::protobuf::int32 value) {
  _set_bit(1);
  index_ = value;
}

// optional int32 toa = 3;
inline bool RilCall::has_toa() const {
  return _has_bit(2);
}
inline void RilCall::clear_toa() {
  toa_ = 0;
  _clear_bit(2);
}
inline ::google::protobuf::int32 RilCall::toa() const {
  return toa_;
}
inline void RilCall::set_toa(::google::protobuf::int32 value) {
  _set_bit(2);
  toa_ = value;
}

// optional bool is_mpty = 4;
inline bool RilCall::has_is_mpty() const {
  return _has_bit(3);
}
inline void RilCall::clear_is_mpty() {
  is_mpty_ = false;
  _clear_bit(3);
}
inline bool RilCall::is_mpty() const {
  return is_mpty_;
}
inline void RilCall::set_is_mpty(bool value) {
  _set_bit(3);
  is_mpty_ = value;
}

// optional bool is_mt = 5;
inline bool RilCall::has_is_mt() const {
  return _has_bit(4);
}
inline void RilCall::clear_is_mt() {
  is_mt_ = false;
  _clear_bit(4);
}
inline bool RilCall::is_mt() const {
  return is_mt_;
}
inline void RilCall::set_is_mt(bool value) {
  _set_bit(4);
  is_mt_ = value;
}

// optional int32 als = 6;
inline bool RilCall::has_als() const {
  return _has_bit(5);
}
inline void RilCall::clear_als() {
  als_ = 0;
  _clear_bit(5);
}
inline ::google::protobuf::int32 RilCall::als() const {
  return als_;
}
inline void RilCall::set_als(::google::protobuf::int32 value) {
  _set_bit(5);
  als_ = value;
}

// optional bool is_voice = 7;
inline bool RilCall::has_is_voice() const {
  return _has_bit(6);
}
inline void RilCall::clear_is_voice() {
  is_voice_ = false;
  _clear_bit(6);
}
inline bool RilCall::is_voice() const {
  return is_voice_;
}
inline void RilCall::set_is_voice(bool value) {
  _set_bit(6);
  is_voice_ = value;
}

// optional bool is_voice_privacy = 8;
inline bool RilCall::has_is_voice_privacy() const {
  return _has_bit(7);
}
inline void RilCall::clear_is_voice_privacy() {
  is_voice_privacy_ = false;
  _clear_bit(7);
}
inline bool RilCall::is_voice_privacy() const {
  return is_voice_privacy_;
}
inline void RilCall::set_is_voice_privacy(bool value) {
  _set_bit(7);
  is_voice_privacy_ = value;
}

// optional string number = 9;
inline bool RilCall::has_number() const {
  return _has_bit(8);
}
inline void RilCall::clear_number() {
  if (number_ != &_default_number_) {
    number_->clear();
  }
  _clear_bit(8);
}
inline const ::std::string& RilCall::number() const {
  return *number_;
}
inline void RilCall::set_number(const ::std::string& value) {
  _set_bit(8);
  if (number_ == &_default_number_) {
    number_ = new ::std::string;
  }
  number_->assign(value);
}
inline void RilCall::set_number(const char* value) {
  _set_bit(8);
  if (number_ == &_default_number_) {
    number_ = new ::std::string;
  }
  number_->assign(value);
}
inline void RilCall::set_number(const char* value, size_t size) {
  _set_bit(8);
  if (number_ == &_default_number_) {
    number_ = new ::std::string;
  }
  number_->assign(reinterpret_cast<const char*>(value), size);
}
inline ::std::string* RilCall::mutable_number() {
  _set_bit(8);
  if (number_ == &_default_number_) {
    number_ = new ::std::string;
  }
  return number_;
}

// optional int32 number_presentation = 10;
inline bool RilCall::has_number_presentation() const {
  return _has_bit(9);
}
inline void RilCall::clear_number_presentation() {
  number_presentation_ = 0;
  _clear_bit(9);
}
inline ::google::protobuf::int32 RilCall::number_presentation() const {
  return number_presentation_;
}
inline void RilCall::set_number_presentation(::google::protobuf::int32 value) {
  _set_bit(9);
  number_presentation_ = value;
}

// optional string name = 11;
inline bool RilCall::has_name() const {
  return _has_bit(10);
}
inline void RilCall::clear_name() {
  if (name_ != &_default_name_) {
    name_->clear();
  }
  _clear_bit(10);
}
inline const ::std::string& RilCall::name() const {
  return *name_;
}
inline void RilCall::set_name(const ::std::string& value) {
  _set_bit(10);
  if (name_ == &_default_name_) {
    name_ = new ::std::string;
  }
  name_->assign(value);
}
inline void RilCall::set_name(const char* value) {
  _set_bit(10);
  if (name_ == &_default_name_) {
    name_ = new ::std::string;
  }
  name_->assign(value);
}
inline void RilCall::set_name(const char* value, size_t size) {
  _set_bit(10);
  if (name_ == &_default_name_) {
    name_ = new ::std::string;
  }
  name_->assign(reinterpret_cast<const char*>(value), size);
}
inline ::std::string* RilCall::mutable_name() {
  _set_bit(10);
  if (name_ == &_default_name_) {
    name_ = new ::std::string;
  }
  return name_;
}

// optional int32 name_presentation = 12;
inline bool RilCall::has_name_presentation() const {
  return _has_bit(11);
}
inline void RilCall::clear_name_presentation() {
  name_presentation_ = 0;
  _clear_bit(11);
}
inline ::google::protobuf::int32 RilCall::name_presentation() const {
  return name_presentation_;
}
inline void RilCall::set_name_presentation(::google::protobuf::int32 value) {
  _set_bit(11);
  name_presentation_ = value;
}

// optional .ril_proto.RilUusInfo uus_info = 13;
inline bool RilCall::has_uus_info() const {
  return _has_bit(12);
}
inline void RilCall::clear_uus_info() {
  if (uus_info_ != NULL) uus_info_->::ril_proto::RilUusInfo::Clear();
  _clear_bit(12);
}
inline const ::ril_proto::RilUusInfo& RilCall::uus_info() const {
  return uus_info_ != NULL ? *uus_info_ : *default_instance_->uus_info_;
}
inline ::ril_proto::RilUusInfo* RilCall::mutable_uus_info() {
  _set_bit(12);
  if (uus_info_ == NULL) uus_info_ = new ::ril_proto::RilUusInfo;
  return uus_info_;
}

// -------------------------------------------------------------------

// RILGWSignalStrength

// optional int32 signal_strength = 1;
inline bool RILGWSignalStrength::has_signal_strength() const {
  return _has_bit(0);
}
inline void RILGWSignalStrength::clear_signal_strength() {
  signal_strength_ = 0;
  _clear_bit(0);
}
inline ::google::protobuf::int32 RILGWSignalStrength::signal_strength() const {
  return signal_strength_;
}
inline void RILGWSignalStrength::set_signal_strength(::google::protobuf::int32 value) {
  _set_bit(0);
  signal_strength_ = value;
}

// optional int32 bit_error_rate = 2;
inline bool RILGWSignalStrength::has_bit_error_rate() const {
  return _has_bit(1);
}
inline void RILGWSignalStrength::clear_bit_error_rate() {
  bit_error_rate_ = 0;
  _clear_bit(1);
}
inline ::google::protobuf::int32 RILGWSignalStrength::bit_error_rate() const {
  return bit_error_rate_;
}
inline void RILGWSignalStrength::set_bit_error_rate(::google::protobuf::int32 value) {
  _set_bit(1);
  bit_error_rate_ = value;
}

// -------------------------------------------------------------------

// RILCDMASignalStrength

// optional int32 dbm = 1;
inline bool RILCDMASignalStrength::has_dbm() const {
  return _has_bit(0);
}
inline void RILCDMASignalStrength::clear_dbm() {
  dbm_ = 0;
  _clear_bit(0);
}
inline ::google::protobuf::int32 RILCDMASignalStrength::dbm() const {
  return dbm_;
}
inline void RILCDMASignalStrength::set_dbm(::google::protobuf::int32 value) {
  _set_bit(0);
  dbm_ = value;
}

// optional int32 ecio = 2;
inline bool RILCDMASignalStrength::has_ecio() const {
  return _has_bit(1);
}
inline void RILCDMASignalStrength::clear_ecio() {
  ecio_ = 0;
  _clear_bit(1);
}
inline ::google::protobuf::int32 RILCDMASignalStrength::ecio() const {
  return ecio_;
}
inline void RILCDMASignalStrength::set_ecio(::google::protobuf::int32 value) {
  _set_bit(1);
  ecio_ = value;
}

// -------------------------------------------------------------------

// RILEVDOSignalStrength

// optional int32 dbm = 1;
inline bool RILEVDOSignalStrength::has_dbm() const {
  return _has_bit(0);
}
inline void RILEVDOSignalStrength::clear_dbm() {
  dbm_ = 0;
  _clear_bit(0);
}
inline ::google::protobuf::int32 RILEVDOSignalStrength::dbm() const {
  return dbm_;
}
inline void RILEVDOSignalStrength::set_dbm(::google::protobuf::int32 value) {
  _set_bit(0);
  dbm_ = value;
}

// optional int32 ecio = 2;
inline bool RILEVDOSignalStrength::has_ecio() const {
  return _has_bit(1);
}
inline void RILEVDOSignalStrength::clear_ecio() {
  ecio_ = 0;
  _clear_bit(1);
}
inline ::google::protobuf::int32 RILEVDOSignalStrength::ecio() const {
  return ecio_;
}
inline void RILEVDOSignalStrength::set_ecio(::google::protobuf::int32 value) {
  _set_bit(1);
  ecio_ = value;
}

// optional int32 signal_noise_ratio = 3;
inline bool RILEVDOSignalStrength::has_signal_noise_ratio() const {
  return _has_bit(2);
}
inline void RILEVDOSignalStrength::clear_signal_noise_ratio() {
  signal_noise_ratio_ = 0;
  _clear_bit(2);
}
inline ::google::protobuf::int32 RILEVDOSignalStrength::signal_noise_ratio() const {
  return signal_noise_ratio_;
}
inline void RILEVDOSignalStrength::set_signal_noise_ratio(::google::protobuf::int32 value) {
  _set_bit(2);
  signal_noise_ratio_ = value;
}

// -------------------------------------------------------------------

// RspStrings

// repeated string strings = 1;
inline int RspStrings::strings_size() const {
  return strings_.size();
}
inline void RspStrings::clear_strings() {
  strings_.Clear();
}
inline const ::std::string& RspStrings::strings(int index) const {
  return strings_.Get(index);
}
inline ::std::string* RspStrings::mutable_strings(int index) {
  return strings_.Mutable(index);
}
inline void RspStrings::set_strings(int index, const ::std::string& value) {
  strings_.Mutable(index)->assign(value);
}
inline void RspStrings::set_strings(int index, const char* value) {
  strings_.Mutable(index)->assign(value);
}
inline void RspStrings::set_strings(int index, const char* value, size_t size) {
  strings_.Mutable(index)->assign(
    reinterpret_cast<const char*>(value), size);
}
inline ::std::string* RspStrings::add_strings() {
  return strings_.Add();
}
inline void RspStrings::add_strings(const ::std::string& value) {
  strings_.Add()->assign(value);
}
inline void RspStrings::add_strings(const char* value) {
  strings_.Add()->assign(value);
}
inline void RspStrings::add_strings(const char* value, size_t size) {
  strings_.Add()->assign(reinterpret_cast<const char*>(value), size);
}
inline const ::google::protobuf::RepeatedPtrField< ::std::string>&
RspStrings::strings() const {
  return strings_;
}
inline ::google::protobuf::RepeatedPtrField< ::std::string>*
RspStrings::mutable_strings() {
  return &strings_;
}

// -------------------------------------------------------------------

// RspIntegers

// repeated int32 integers = 1;
inline int RspIntegers::integers_size() const {
  return integers_.size();
}
inline void RspIntegers::clear_integers() {
  integers_.Clear();
}
inline ::google::protobuf::int32 RspIntegers::integers(int index) const {
  return integers_.Get(index);
}
inline void RspIntegers::set_integers(int index, ::google::protobuf::int32 value) {
  integers_.Set(index, value);
}
inline void RspIntegers::add_integers(::google::protobuf::int32 value) {
  integers_.Add(value);
}
inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >&
RspIntegers::integers() const {
  return integers_;
}
inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >*
RspIntegers::mutable_integers() {
  return &integers_;
}

// -------------------------------------------------------------------

// RspGetSimStatus

// required .ril_proto.RilCardStatus card_status = 1;
inline bool RspGetSimStatus::has_card_status() const {
  return _has_bit(0);
}
inline void RspGetSimStatus::clear_card_status() {
  if (card_status_ != NULL) card_status_->::ril_proto::RilCardStatus::Clear();
  _clear_bit(0);
}
inline const ::ril_proto::RilCardStatus& RspGetSimStatus::card_status() const {
  return card_status_ != NULL ? *card_status_ : *default_instance_->card_status_;
}
inline ::ril_proto::RilCardStatus* RspGetSimStatus::mutable_card_status() {
  _set_bit(0);
  if (card_status_ == NULL) card_status_ = new ::ril_proto::RilCardStatus;
  return card_status_;
}

// -------------------------------------------------------------------

// ReqEnterSimPin

// required string pin = 1;
inline bool ReqEnterSimPin::has_pin() const {
  return _has_bit(0);
}
inline void ReqEnterSimPin::clear_pin() {
  if (pin_ != &_default_pin_) {
    pin_->clear();
  }
  _clear_bit(0);
}
inline const ::std::string& ReqEnterSimPin::pin() const {
  return *pin_;
}
inline void ReqEnterSimPin::set_pin(const ::std::string& value) {
  _set_bit(0);
  if (pin_ == &_default_pin_) {
    pin_ = new ::std::string;
  }
  pin_->assign(value);
}
inline void ReqEnterSimPin::set_pin(const char* value) {
  _set_bit(0);
  if (pin_ == &_default_pin_) {
    pin_ = new ::std::string;
  }
  pin_->assign(value);
}
inline void ReqEnterSimPin::set_pin(const char* value, size_t size) {
  _set_bit(0);
  if (pin_ == &_default_pin_) {
    pin_ = new ::std::string;
  }
  pin_->assign(reinterpret_cast<const char*>(value), size);
}
inline ::std::string* ReqEnterSimPin::mutable_pin() {
  _set_bit(0);
  if (pin_ == &_default_pin_) {
    pin_ = new ::std::string;
  }
  return pin_;
}

// -------------------------------------------------------------------

// RspEnterSimPin

// required int32 retries_remaining = 1;
inline bool RspEnterSimPin::has_retries_remaining() const {
  return _has_bit(0);
}
inline void RspEnterSimPin::clear_retries_remaining() {
  retries_remaining_ = 0;
  _clear_bit(0);
}
inline ::google::protobuf::int32 RspEnterSimPin::retries_remaining() const {
  return retries_remaining_;
}
inline void RspEnterSimPin::set_retries_remaining(::google::protobuf::int32 value) {
  _set_bit(0);
  retries_remaining_ = value;
}

// -------------------------------------------------------------------

// RspGetCurrentCalls

// repeated .ril_proto.RilCall calls = 1;
inline int RspGetCurrentCalls::calls_size() const {
  return calls_.size();
}
inline void RspGetCurrentCalls::clear_calls() {
  calls_.Clear();
}
inline const ::ril_proto::RilCall& RspGetCurrentCalls::calls(int index) const {
  return calls_.Get(index);
}
inline ::ril_proto::RilCall* RspGetCurrentCalls::mutable_calls(int index) {
  return calls_.Mutable(index);
}
inline ::ril_proto::RilCall* RspGetCurrentCalls::add_calls() {
  return calls_.Add();
}
inline const ::google::protobuf::RepeatedPtrField< ::ril_proto::RilCall >&
RspGetCurrentCalls::calls() const {
  return calls_;
}
inline ::google::protobuf::RepeatedPtrField< ::ril_proto::RilCall >*
RspGetCurrentCalls::mutable_calls() {
  return &calls_;
}

// -------------------------------------------------------------------

// ReqDial

// optional string address = 1;
inline bool ReqDial::has_address() const {
  return _has_bit(0);
}
inline void ReqDial::clear_address() {
  if (address_ != &_default_address_) {
    address_->clear();
  }
  _clear_bit(0);
}
inline const ::std::string& ReqDial::address() const {
  return *address_;
}
inline void ReqDial::set_address(const ::std::string& value) {
  _set_bit(0);
  if (address_ == &_default_address_) {
    address_ = new ::std::string;
  }
  address_->assign(value);
}
inline void ReqDial::set_address(const char* value) {
  _set_bit(0);
  if (address_ == &_default_address_) {
    address_ = new ::std::string;
  }
  address_->assign(value);
}
inline void ReqDial::set_address(const char* value, size_t size) {
  _set_bit(0);
  if (address_ == &_default_address_) {
    address_ = new ::std::string;
  }
  address_->assign(reinterpret_cast<const char*>(value), size);
}
inline ::std::string* ReqDial::mutable_address() {
  _set_bit(0);
  if (address_ == &_default_address_) {
    address_ = new ::std::string;
  }
  return address_;
}

// optional int32 clir = 2;
inline bool ReqDial::has_clir() const {
  return _has_bit(1);
}
inline void ReqDial::clear_clir() {
  clir_ = 0;
  _clear_bit(1);
}
inline ::google::protobuf::int32 ReqDial::clir() const {
  return clir_;
}
inline void ReqDial::set_clir(::google::protobuf::int32 value) {
  _set_bit(1);
  clir_ = value;
}

// optional .ril_proto.RilUusInfo uus_info = 3;
inline bool ReqDial::has_uus_info() const {
  return _has_bit(2);
}
inline void ReqDial::clear_uus_info() {
  if (uus_info_ != NULL) uus_info_->::ril_proto::RilUusInfo::Clear();
  _clear_bit(2);
}
inline const ::ril_proto::RilUusInfo& ReqDial::uus_info() const {
  return uus_info_ != NULL ? *uus_info_ : *default_instance_->uus_info_;
}
inline ::ril_proto::RilUusInfo* ReqDial::mutable_uus_info() {
  _set_bit(2);
  if (uus_info_ == NULL) uus_info_ = new ::ril_proto::RilUusInfo;
  return uus_info_;
}

// -------------------------------------------------------------------

// ReqHangUp

// required int32 connection_index = 1;
inline bool ReqHangUp::has_connection_index() const {
  return _has_bit(0);
}
inline void ReqHangUp::clear_connection_index() {
  connection_index_ = 0;
  _clear_bit(0);
}
inline ::google::protobuf::int32 ReqHangUp::connection_index() const {
  return connection_index_;
}
inline void ReqHangUp::set_connection_index(::google::protobuf::int32 value) {
  _set_bit(0);
  connection_index_ = value;
}

// -------------------------------------------------------------------

// RspLastCallFailCause

// required int32 last_call_fail_cause = 1;
inline bool RspLastCallFailCause::has_last_call_fail_cause() const {
  return _has_bit(0);
}
inline void RspLastCallFailCause::clear_last_call_fail_cause() {
  last_call_fail_cause_ = 0;
  _clear_bit(0);
}
inline ::google::protobuf::int32 RspLastCallFailCause::last_call_fail_cause() const {
  return last_call_fail_cause_;
}
inline void RspLastCallFailCause::set_last_call_fail_cause(::google::protobuf::int32 value) {
  _set_bit(0);
  last_call_fail_cause_ = value;
}

// -------------------------------------------------------------------

// RspSignalStrength

// optional .ril_proto.RILGWSignalStrength gw_signalstrength = 1;
inline bool RspSignalStrength::has_gw_signalstrength() const {
  return _has_bit(0);
}
inline void RspSignalStrength::clear_gw_signalstrength() {
  if (gw_signalstrength_ != NULL) gw_signalstrength_->::ril_proto::RILGWSignalStrength::Clear();
  _clear_bit(0);
}
inline const ::ril_proto::RILGWSignalStrength& RspSignalStrength::gw_signalstrength() const {
  return gw_signalstrength_ != NULL ? *gw_signalstrength_ : *default_instance_->gw_signalstrength_;
}
inline ::ril_proto::RILGWSignalStrength* RspSignalStrength::mutable_gw_signalstrength() {
  _set_bit(0);
  if (gw_signalstrength_ == NULL) gw_signalstrength_ = new ::ril_proto::RILGWSignalStrength;
  return gw_signalstrength_;
}

// optional .ril_proto.RILCDMASignalStrength cdma_signalstrength = 2;
inline bool RspSignalStrength::has_cdma_signalstrength() const {
  return _has_bit(1);
}
inline void RspSignalStrength::clear_cdma_signalstrength() {
  if (cdma_signalstrength_ != NULL) cdma_signalstrength_->::ril_proto::RILCDMASignalStrength::Clear();
  _clear_bit(1);
}
inline const ::ril_proto::RILCDMASignalStrength& RspSignalStrength::cdma_signalstrength() const {
  return cdma_signalstrength_ != NULL ? *cdma_signalstrength_ : *default_instance_->cdma_signalstrength_;
}
inline ::ril_proto::RILCDMASignalStrength* RspSignalStrength::mutable_cdma_signalstrength() {
  _set_bit(1);
  if (cdma_signalstrength_ == NULL) cdma_signalstrength_ = new ::ril_proto::RILCDMASignalStrength;
  return cdma_signalstrength_;
}

// optional .ril_proto.RILEVDOSignalStrength evdo_signalstrength = 3;
inline bool RspSignalStrength::has_evdo_signalstrength() const {
  return _has_bit(2);
}
inline void RspSignalStrength::clear_evdo_signalstrength() {
  if (evdo_signalstrength_ != NULL) evdo_signalstrength_->::ril_proto::RILEVDOSignalStrength::Clear();
  _clear_bit(2);
}
inline const ::ril_proto::RILEVDOSignalStrength& RspSignalStrength::evdo_signalstrength() const {
  return evdo_signalstrength_ != NULL ? *evdo_signalstrength_ : *default_instance_->evdo_signalstrength_;
}
inline ::ril_proto::RILEVDOSignalStrength* RspSignalStrength::mutable_evdo_signalstrength() {
  _set_bit(2);
  if (evdo_signalstrength_ == NULL) evdo_signalstrength_ = new ::ril_proto::RILEVDOSignalStrength;
  return evdo_signalstrength_;
}

// -------------------------------------------------------------------

// RspOperator

// optional string long_alpha_ons = 1;
inline bool RspOperator::has_long_alpha_ons() const {
  return _has_bit(0);
}
inline void RspOperator::clear_long_alpha_ons() {
  if (long_alpha_ons_ != &_default_long_alpha_ons_) {
    long_alpha_ons_->clear();
  }
  _clear_bit(0);
}
inline const ::std::string& RspOperator::long_alpha_ons() const {
  return *long_alpha_ons_;
}
inline void RspOperator::set_long_alpha_ons(const ::std::string& value) {
  _set_bit(0);
  if (long_alpha_ons_ == &_default_long_alpha_ons_) {
    long_alpha_ons_ = new ::std::string;
  }
  long_alpha_ons_->assign(value);
}
inline void RspOperator::set_long_alpha_ons(const char* value) {
  _set_bit(0);
  if (long_alpha_ons_ == &_default_long_alpha_ons_) {
    long_alpha_ons_ = new ::std::string;
  }
  long_alpha_ons_->assign(value);
}
inline void RspOperator::set_long_alpha_ons(const char* value, size_t size) {
  _set_bit(0);
  if (long_alpha_ons_ == &_default_long_alpha_ons_) {
    long_alpha_ons_ = new ::std::string;
  }
  long_alpha_ons_->assign(reinterpret_cast<const char*>(value), size);
}
inline ::std::string* RspOperator::mutable_long_alpha_ons() {
  _set_bit(0);
  if (long_alpha_ons_ == &_default_long_alpha_ons_) {
    long_alpha_ons_ = new ::std::string;
  }
  return long_alpha_ons_;
}

// optional string short_alpha_ons = 2;
inline bool RspOperator::has_short_alpha_ons() const {
  return _has_bit(1);
}
inline void RspOperator::clear_short_alpha_ons() {
  if (short_alpha_ons_ != &_default_short_alpha_ons_) {
    short_alpha_ons_->clear();
  }
  _clear_bit(1);
}
inline const ::std::string& RspOperator::short_alpha_ons() const {
  return *short_alpha_ons_;
}
inline void RspOperator::set_short_alpha_ons(const ::std::string& value) {
  _set_bit(1);
  if (short_alpha_ons_ == &_default_short_alpha_ons_) {
    short_alpha_ons_ = new ::std::string;
  }
  short_alpha_ons_->assign(value);
}
inline void RspOperator::set_short_alpha_ons(const char* value) {
  _set_bit(1);
  if (short_alpha_ons_ == &_default_short_alpha_ons_) {
    short_alpha_ons_ = new ::std::string;
  }
  short_alpha_ons_->assign(value);
}
inline void RspOperator::set_short_alpha_ons(const char* value, size_t size) {
  _set_bit(1);
  if (short_alpha_ons_ == &_default_short_alpha_ons_) {
    short_alpha_ons_ = new ::std::string;
  }
  short_alpha_ons_->assign(reinterpret_cast<const char*>(value), size);
}
inline ::std::string* RspOperator::mutable_short_alpha_ons() {
  _set_bit(1);
  if (short_alpha_ons_ == &_default_short_alpha_ons_) {
    short_alpha_ons_ = new ::std::string;
  }
  return short_alpha_ons_;
}

// optional string mcc_mnc = 3;
inline bool RspOperator::has_mcc_mnc() const {
  return _has_bit(2);
}
inline void RspOperator::clear_mcc_mnc() {
  if (mcc_mnc_ != &_default_mcc_mnc_) {
    mcc_mnc_->clear();
  }
  _clear_bit(2);
}
inline const ::std::string& RspOperator::mcc_mnc() const {
  return *mcc_mnc_;
}
inline void RspOperator::set_mcc_mnc(const ::std::string& value) {
  _set_bit(2);
  if (mcc_mnc_ == &_default_mcc_mnc_) {
    mcc_mnc_ = new ::std::string;
  }
  mcc_mnc_->assign(value);
}
inline void RspOperator::set_mcc_mnc(const char* value) {
  _set_bit(2);
  if (mcc_mnc_ == &_default_mcc_mnc_) {
    mcc_mnc_ = new ::std::string;
  }
  mcc_mnc_->assign(value);
}
inline void RspOperator::set_mcc_mnc(const char* value, size_t size) {
  _set_bit(2);
  if (mcc_mnc_ == &_default_mcc_mnc_) {
    mcc_mnc_ = new ::std::string;
  }
  mcc_mnc_->assign(reinterpret_cast<const char*>(value), size);
}
inline ::std::string* RspOperator::mutable_mcc_mnc() {
  _set_bit(2);
  if (mcc_mnc_ == &_default_mcc_mnc_) {
    mcc_mnc_ = new ::std::string;
  }
  return mcc_mnc_;
}

// -------------------------------------------------------------------

// ReqSeparateConnection

// required int32 index = 1;
inline bool ReqSeparateConnection::has_index() const {
  return _has_bit(0);
}
inline void ReqSeparateConnection::clear_index() {
  index_ = 0;
  _clear_bit(0);
}
inline ::google::protobuf::int32 ReqSeparateConnection::index() const {
  return index_;
}
inline void ReqSeparateConnection::set_index(::google::protobuf::int32 value) {
  _set_bit(0);
  index_ = value;
}

// -------------------------------------------------------------------

// ReqSetMute

// required bool state = 1;
inline bool ReqSetMute::has_state() const {
  return _has_bit(0);
}
inline void ReqSetMute::clear_state() {
  state_ = false;
  _clear_bit(0);
}
inline bool ReqSetMute::state() const {
  return state_;
}
inline void ReqSetMute::set_state(bool value) {
  _set_bit(0);
  state_ = value;
}

// -------------------------------------------------------------------

// ReqScreenState

// required bool state = 1;
inline bool ReqScreenState::has_state() const {
  return _has_bit(0);
}
inline void ReqScreenState::clear_state() {
  state_ = false;
  _clear_bit(0);
}
inline bool ReqScreenState::state() const {
  return state_;
}
inline void ReqScreenState::set_state(bool value) {
  _set_bit(0);
  state_ = value;
}


// @@protoc_insertion_point(namespace_scope)

}  // namespace ril_proto

#ifndef SWIG
namespace google {
namespace protobuf {

template <>
inline const EnumDescriptor* GetEnumDescriptor< ril_proto::RadioState>() {
  return ril_proto::RadioState_descriptor();
}
template <>
inline const EnumDescriptor* GetEnumDescriptor< ril_proto::RilCardState>() {
  return ril_proto::RilCardState_descriptor();
}
template <>
inline const EnumDescriptor* GetEnumDescriptor< ril_proto::RilPersoSubstate>() {
  return ril_proto::RilPersoSubstate_descriptor();
}
template <>
inline const EnumDescriptor* GetEnumDescriptor< ril_proto::RilAppState>() {
  return ril_proto::RilAppState_descriptor();
}
template <>
inline const EnumDescriptor* GetEnumDescriptor< ril_proto::RilPinState>() {
  return ril_proto::RilPinState_descriptor();
}
template <>
inline const EnumDescriptor* GetEnumDescriptor< ril_proto::RilAppType>() {
  return ril_proto::RilAppType_descriptor();
}
template <>
inline const EnumDescriptor* GetEnumDescriptor< ril_proto::RilUusType>() {
  return ril_proto::RilUusType_descriptor();
}
template <>
inline const EnumDescriptor* GetEnumDescriptor< ril_proto::RilUusDcs>() {
  return ril_proto::RilUusDcs_descriptor();
}
template <>
inline const EnumDescriptor* GetEnumDescriptor< ril_proto::RilCallState>() {
  return ril_proto::RilCallState_descriptor();
}

}  // namespace google
}  // namespace protobuf
#endif  // SWIG

// @@protoc_insertion_point(global_scope)

#endif  // PROTOBUF_ril_2eproto__INCLUDED
