资源描述:
《protobuf guide》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、DeveloperGuideWelcometothedeveloperdocumentationforprotocolbuffers–alanguage-neutral,platform-neutral,extensiblewayofserializingstructureddataforuseincommunicationsprotocols,datastorage,andmore.ThisdocumentationisaimedatJava,C++,orPythondeveloperswhowanttouseprotocolbuffersintheirapplications.Thi
2、soverviewintroducesprotocolbuffersandtellsyouwhatyouneedtodotogetstarted–youcanthengoontofollowthetutorialsordelvedeeperintoprotocolbufferencoding.APIreferencedocumentationisalsoprovidedforallthreelanguages,aswellaslanguageandstyleguidesforwriting.protofiles.Whatareprotocolbuffers?Protocolbuffers
3、areaflexible,efficient,automatedmechanismforserializingstructureddata–thinkXML,butsmaller,faster,andsimpler.Youdefinehowyouwantyourdatatobestructuredonce,thenyoucanusespecialgeneratedsourcecodetoeasilywriteandreadyourstructureddatatoandfromavarietyofdatastreamsandusingavarietyoflanguages.Youcanev
4、enupdateyourdatastructurewithoutbreakingdeployedprogramsthatarecompiledagainstthe"old"format.Howdotheywork?Youspecifyhowyouwanttheinformationyou'reserializingtobestructuredbydefiningprotocolbuffermessagetypesin.protofiles.Eachprotocolbuffermessageisasmalllogicalrecordofinformation,containingaseri
5、esofname-valuepairs.Here'saverybasicexampleofa.protofilethatdefinesamessagecontaininginformationaboutaperson:messagePerson{requiredstringname=1;requiredint32id=2;optionalstringemail=3;enumPhoneType{MOBILE=0;HOME=1;WORK=2;}messagePhoneNumber{requiredstringnumber=1;optionalPhoneTypetype=2[default=H
6、OME];}repeatedPhoneNumberphone=4;}Asyoucansee,themessageformatissimple–eachmessagetypehasoneormoreuniquelynumberedfields,andeachfieldhasanameandavaluetype,wherevaluetypescanbenumbers(integerorfloating-point),booleans,strings,rawbytes,oreven(asintheexampleabove)otherprotocolbuffermessagetypes,allo
7、wingyoutostructureyourdatahierarchically.Youcanspecifyoptionalfields,requiredfields,andrepeatedfields.Youcanfindmoreinformationaboutwriting.protofilesintheProtocolBufferLanguageGuide.Onceyou'vedefinedyourmessages,youru