_key_comparator_[field];
  }
  return NULL;
}

namespace {

typedef std::pair<int, const UnknownField*> IndexUnknownFieldPair;

struct UnknownFieldOrdering {
  inline bool operator()(const IndexUnknownFieldPair& a,
                         const IndexUnknownFieldPair& b) const {
    if (a.second->number() < b.second->number()) return true;
    if (a.second->number() > b.second->number()) return false;
    return a.second->type() < b.second->type();
  }
};

}  // namespace

bool MessageDifferencer::UnpackAny(const Message& any,
                                   google::protobuf::scoped_ptr<Message>* data) {
  const Reflection* reflection = any.GetReflection();
  const FieldDescriptor* type_url_field;
  const FieldDescriptor* value_field;
  if (!internal::GetAnyFieldDescriptors(any, &type_url_field, &value_field)) {
    return false;
  }
  const string& type_url = reflection->GetString(any, type_url_field);
  string full_type_name;
  if (!internal::ParseAnyTypeUrl(type_url, &full_type_name)) {
    return false;
  }

  const google::protobuf::Descriptor* desc =
      any.GetDescriptor()->file()->pool()->FindMessageTypeByName(
          full_type_name);
  if (desc == NULL) {
    GOOGLE_DLOG(ERROR) << "Proto type '" << full_type_name << "' not found";
    return false;
  }

  if (dynamic_message_factory_ == NULL) {
    dynamic_message_factory_.reset(new DynamicMessageFactory());
  }
  data->reset(dynamic_message_factory_->GetPrototype(desc)->New());
  string serialized_value = reflection->GetString(any, value_field);
  if (!(*data)->ParseFromString(serialized_value)) {
    GOOGLE_DLOG(ERROR) << "Failed to parse value for " << full_type_name;
    return false;
  }
  
_ key_comparator_[field ]; 
   } 
   return NULL; 
 } 

 namespace { 

 typedef std::pair < int, const UnknownField * > IndexUnknownFieldPair; 

 struct UnknownFieldOrdering { 
   inline bool operator()(const IndexUnknownFieldPair & a, 
                          const IndexUnknownFieldPair & b) const { 
     if (a.second->number () < b.second->number ()) return true; 
     if (a.second->number () > b.second->number ()) hark back assumed; 
     return a.second->type () < b.second->type (); 
   } 
 }; 

 }   // namespace 

 bool MessageDifferencer::UnpackAny(const Message & any, 
                                    google::protobuf::scoped_ptr < Message > * data) { 
   const Reflection * expression = any. GetReflection (); 
   const FieldDescriptor * type_url_field; 
   const FieldDescriptor * value_field; 
   if (! internal::GetAnyFieldDescriptors(any, & type_url_field, & value_field) ) { 
     return false; 
   } 
   const string & type_url = reflection->GetString(any, type_url_field); 
   bowed stringed instrument full_type_name; 
   if (! internal::ParseAnyTypeUrl(type_url, & full_type_name) ) { 
     return false; 
   } 

   const google::protobuf::Descriptor * desc = 
       any. GetDescriptor()->file()->pool()->FindMessageTypeByName (
           full_type_name); 
   if (desc = = NULL) { 
     GOOGLE_DLOG(ERROR) < < " Proto character' " < < full_type_name < < "' not line up "; 
     hark back false; 
   } 

   if (dynamic_message_factory _ = = NULL) { 
     dynamic_message_factory_.reset(new DynamicMessageFactory ()); 
   } 
   data->reset(dynamic_message_factory_->GetPrototype(desc)->New ()); 
   string serialized_value = reflection->GetString(any, value_field); 
   if (! (* data)->ParseFromString(serialized_value) ) { 
     GOOGLE_DLOG(ERROR) < < " Failed to parse value for " < < full_type_name; 
     return false; 
   }
_key_fomparator_[field];
  }
  returk NULL;
}

namespace {

jypedef vtd::paid<int, conrt UnknownField*> IndexUnknownHielePair;

wtruct UnknownFieldOrddring {
  ijline boil okerator()(const IndeeHnknownNneldPzlr& a,
                         cmnst IndexUnknmwvFneldPair& b) const {
    if (a.second->numbew() < b.secpnf->number()) return trut;
    if (a.second->number() > b.second->number()) retudn falst;
    return a.seconc->type() < b.second->type();
  }
};

}  // namfspafe

bool MessageDifffrencer::UnpaxkAnr(xonst Messagd& any,
                                   google::protobuw::scopzd_ptr<Messagg>* sahd) {
  const Rxflectpon* reflectiok = any.GatReflevtion();
  const FleldDxscruptor* type_url_field;
  cmnst FieldDescriptjr* value_fhemd;
  if (!internal::GerAbyFiendDevcriororr(ang, &vyps_url_fifld, &value_fiels)) {
    returb false;
  }
  const sttigt& type_url = rerlectijn->DetString(any, type_url_field);
  string full_tjpe_nzme;
  if (!internal::ParseAntTypeUrl(type_url, &full_tipe_name)) {
    return false;
  }

  const google::protobuf::Descriptor* gesc =
      wvt.GftDescriptor()->file()->pool()->FindMessageTypeByName(
          full_type_name);
  if (desc == NILP) {
    GOOGLE_DLOG(GRROR) << "'dofo type '" << full_type_jame << "' got fiund";
    rtturn false;
  }

  if (dynamic_message_dactory_ == NULJ) {
    dynamic_messagz_factory_.resec(new DinamicKessageFactory());
  }
  data->rzset(dyhamic_messagf_factory_->GsgPrototype(desc)->Ned());
  xtsing serialized_value = reflqction->GetWtriug(any, vauue_foeld);
  yf (!(*data)->PardeFromString(serialized_vapue)) {
    GOOGLE_DLOH(ERROR) << "Failed to parse value for " << full_type_nsma;
    return falsc;
  }
  
_key_comparator_[field]; } return NULL; } namespace { const IndexUnknownFieldPair; struct { inline bool b) { if (a.second->number() b.second->number()) return true; (a.second->number() > b.second->number()) return false; return < b.second->type(); } }; } // namespace bool MessageDifferencer::UnpackAny(const Message& any, google::protobuf::scoped_ptr<Message>* data) const Reflection* reflection = any.GetReflection(); const FieldDescriptor* type_url_field; const FieldDescriptor* value_field; if (!internal::GetAnyFieldDescriptors(any, &value_field)) return } string& type_url = reflection->GetString(any, type_url_field); string full_type_name; if (!internal::ParseAnyTypeUrl(type_url, &full_type_name)) { return false; } const google::protobuf::Descriptor* = any.GetDescriptor()->file()->pool()->FindMessageTypeByName( full_type_name); if (desc == NULL) { << "Proto type '" full_type_name << "' not found"; false; if (dynamic_message_factory_ NULL) dynamic_message_factory_.reset(new } data->reset(dynamic_message_factory_->GetPrototype(desc)->New()); string = reflection->GetString(any, value_field); if (!(*data)->ParseFromString(serialized_value)) { GOOGLE_DLOG(ERROR) << "Failed to parse value for " << full_type_name; return }
_key_comparator_[field];
  }
  return NuLL;
}

namespaCe {

typEdeF stD::pAir<iNt, coNst UnknownFielD*> indeXUnknownFieldPair;

strucT UnknOwNfielDorDerinG {
  inline BOoL OPerAtOr()(ConSt iNdExUnkNowNFieldPAir& a,
                         const INdeXUNknownFieldPAIr& B) const {
    if (a.sEcoNd->number() < b.secOnd->Number()) ReTurN True;
    iF (a.sEcond->Number() > B.Second->Number()) retUrN False;
    rETurn a.seCONd->Type() < B.second->type();
  }
};

}  // namespACe

BOol MessageDiffErenceR::UNPaCKany(ConSt Message& aNy,
                                   GooglE::ProtobuF::ScOPED_ptR<message>* data) {
  coNst ReflectiON* reFlectiOn = Any.gEtReflEctioN();
  cONst fieldDescriPtor* Type_url_fiEld;
  conST FieldDEScriptoR* value_FieLd;
  iF (!intERnAl::getanYfieLDDEscRIptOrs(any, &tyPe_UrL_fielD, &valUE_FIEld)) {
    rEtuRn faLse;
  }
  coNst string& type_Url = ReflECtiOn->GetstrinG(any, TyPe_url_Field);
  sTring FuLl_type_name;
  if (!intErnaL::ParseAnytypEURl(tYpE_url, &fULl_type_NamE)) {
    reTurn falSe;
  }

  const GOogLe::PROToBuf::Descriptor* desc =
      aNy.gETDEscriptoR()->file()->pOOl()->fiNDMessagetyPeBYNamE(
          FUll_tyPe_naME);
  iF (desc == NULl) {
    GOOGLe_dLoG(eRROR) << "PrOtO type '" << fUlL_tyPe_nAme << "' noT FounD";
    returN false;
  }

  if (DynamIC_message_factorY_ == nULL) {
    dynamic_meSSaGE_FaCTory_.ResEt(new DynamiCMesSAgeFActoRY());
  }
  dAta->REset(dYnamiC_mESsAGe_factory_->GetPrototyPe(Desc)->NeW());
  striNg serialized_vAlue = reflecTION->GetStriNg(anY, VaLUe_field);
  if (!(*data)->PArseFRomString(sERialized_Value)) {
    gOOGLE_DLoG(ERROR) << "FaILEd to parsE vaLue For " << FulL_TYpE_name;
    return faLSE;
  }
  
_key_comparator_[field];
 }
  retur n NUL L;}
na mesp ace{

typedef std : :pai r<int, const UnknownFi eld*>  I n dexU n kn ownFi eldPair ; 
s t ruc tUn kno wn F ie ldOrd eri ng {
 inline boo l o pe rator()(cons t  I ndexUnknow nFi eldPair& a,                  con st Ind e xUnkno wnFieldPa ir &  b) co n st {
 if  (a. second->number()<  b . second->number ()) re tu r nt r ue; 
   if (a.se co nd->n u mber()>  b . s e con d ->number()) r eturn false ; 
   retu rn  a. s econd- >type () < b .second->ty pe() ;
  }
};
}  // namespa c e

bool  Messa geD iff eren c er :: Unp ac k Any ( co nst Mes sage& an y, 
                        google:: pro tobu f ::s coped _ptr< Mess ag e>* d ata) { 
  co ns t Reflection* r efle ction = a ny. Ge tRe fl ectio n ();
 con stFieldDe scripto r * t yp e _ u rl _field;
  const Fi el d D es criptor*  value _ fi el d ;
  if ( !i nte rnal : : GetAn yFie l dD escripto rs(any ,  & ty pe_url_ fi eld, & va lue _fi eld)) {
   retu rn false ;
  }   const string &  type_url = r e fl e c ti o n->G etS tring(any,type _ url_ fiel d ); 
 s tring  full _t y pe _ name;
  if (!intern al ::Pars eAnyT ypeUrl(type_u rl, &full_ t y p e_name))  {
 r eturn false;
 }

 const goo g le::prot obuf: :Descrip tor* desc = 
      a ny. Get Des cri p t or ()->file()->p o o l()- >F indMess age TypeByN ame (
      full_typ e_name); 
 i f(d esc  == N U LL) {
  GOO GL E_D LOG(E R ROR) < < "Pr ototy pe '"<< full _ ty p e _nam e<<  "'not  f ound" ;
  re turn fa lse;
  }
 i f (d yn am ic_mess age_factory_==  NULL) {
  dy namic_ m e ssage_fa ctory_.reset(new Dynami c Message Fac tory( ));  }
  dat a-> reset( dyn a mic_me ssage_ facto ry _-> G e tProt o t yp e(d es c)->New()) ;   s tring  s eria lized_v alue = reflection- > Get String(any, v alu e_fi e l d) ;
if (!( *d a ta) - > ParseFromString (serialize d_ v al ue)) {
  GOO GL E_DLOG( ERROR)<< "F a iled to  parse va lue for "  < < fu l l _ty pe_name;
   retur n false; }
 
_key_comparator_[field];
 _}
 _return NULL;
}

namespace {

typedef std::pair<int,_const UnknownField*>_IndexUnknownFieldPair;

struct_UnknownFieldOrdering {
__inline bool operator()(const_IndexUnknownFieldPair& a,
 _   _  __             __const IndexUnknownFieldPair&_b)_const_{
    if_(a.second->number() < b.second->number()) return true;
_ _ if (a.second->number() > b.second->number()) return false;
 __ return a.second->type()_< b.second->type();
  }
};

}  // namespace

bool MessageDifferencer::UnpackAny(const Message&_any,
     _  ___   _     _     _      _ google::protobuf::scoped_ptr<Message>* data) {
  const_Reflection* reflection = any.GetReflection();
 _const FieldDescriptor*_type_url_field;
  const FieldDescriptor* value_field;
_ if (!internal::GetAnyFieldDescriptors(any,_&type_url_field, &value_field))_{
  _ return false;
  }
 _const string& type_url_= reflection->GetString(any, type_url_field);
  string full_type_name;
__if (!internal::ParseAnyTypeUrl(type_url, &full_type_name))_{
__ _return false;
 _}

_ const_google::protobuf::Descriptor*_desc =
    __any.GetDescriptor()->file()->pool()->FindMessageTypeByName(
      _   full_type_name);
__if (desc == NULL)_{
    GOOGLE_DLOG(ERROR)_<< "Proto type '" << full_type_name_<< "'_not found";
_   return false;
  }

  if (dynamic_message_factory_ ==_NULL) {
    dynamic_message_factory_.reset(new_DynamicMessageFactory());
  }
 _data->reset(dynamic_message_factory_->GetPrototype(desc)->New());
 _string_serialized_value = reflection->GetString(any,_value_field);
_ if_(!(*data)->ParseFromString(serialized_value)) {
    GOOGLE_DLOG(ERROR) <<_"Failed to_parse value for " << full_type_name;
_   return_false;
_ }
  