Apache Thrift
Sign in to savedata serialization format
Official website
Apache Thrift - Home
thrift.apache.org →Link to the official site · 7,690 chars · not written by Vinony
Described at
dance,focusingonthekey typesavailableinallprogramminglan- guages,ommittingany nichetypesavailableonlyinspecificlan- guages. ThebasetypessupportedbyThriftare: boolA booleanvalue,trueorfalse byteA signedbyte i16A 16-bitsignedinteger i32A 32-bitsignedinteger i64A 64-bitsignedinteger doubleA 64-bitfloatingpointnumber stringAnencoding-agnostictextorbinarystring Ofparticularnoteis theabsenceofunsignedintegertypes.Because thesetypeshave nodirecttranslationtonative primitive types inmany languages,theadvantagesthey affordarelost.Further, thereis nowaytopreventtheapplicationdeveloperina language like Pythonfromassigninga negative valuetoanintegervariable, leadingtounpredictablebehavior. Froma designstandpoint,we observedthatunsignedintegerswereveryrarely, if ever, usedfor arithmeticpurposes,butinpracticeweremuchmoreoftenused askeysoridentifiers.Inthiscase,thesignisirrelevant.Signed integersserve thissamepurposeandcanbesafelycasttotheir unsignedcounterparts(mostcommonlyinC++)whenabsolutely necessary. 2.2Structs AThriftstructdefinesa commonobjecttobeusedacrosslan- guages.Astructisessentiallyequivalenttoa classinobjectori- entedprogramminglanguages.A structhasa setofstronglytyped fields,eachwitha uniquenameidentifier. Thebasicsyntaxfor defininga Thriftstructlooksverysimilartoa C structdefinition. Fieldsmaybeannotatedwithanintegerfieldidentifier(uniqueto thescopeofthatstruct)andoptionaldefaultvalues.Fieldidentifiers willbeautomaticallyassignedif omitted,thoughthey arestrongly encouragedforversioningreasonsdiscussedlater. 2.3Containers Thriftcontainersarestronglytypedcontainersthatmaptothemost commonlyusedcontainersincommonprogramminglanguages. They areannotatedusingtheC++template(orJava Generics)style. Therearethreetypesavailable: list<type>Anorderedlistofelements.Translatesdirectly intoanSTLvector, JavaArrayList, ornative arrayinscript- inglanguages.Maycontainduplicates. set<type>Anunorderedsetofuniqueelements.Translates intoanSTLset, JavaHashSet,setinPython,ornative dictionaryinPHP/Ruby. map<type1,type2>Amapofstrictlyuniquekeystovalues TranslatesintoanSTLmap, JavaHashMap, PHPassociative array, orPython/Rubydictionary. Whiledefaultsareprovided,thetypemappingsarenotexplic- itlyfixed.Customcodegeneratordirectiveshave beenaddedto substitutecustomtypesindestinationlanguages(i.e.hash mapor Google’s sparsehashmapcanbeusedinC++).Theonlyrequire- mentisthatthecustomtypessupportallthenecessaryiteration primitives.Containerelementsmaybeofany validThrifttype,in- cludingothercontainersorstructs. structExample{ 1:i32number=10, 2:i64bigNumber, 3:doubledecimals, 4:stringname="thrifty" } Inthetargetlanguage,eachdefinitiongeneratesa typewithtwo methods,readandwrite, whichperformserializationandtrans- portoftheobjectsusinga ThriftTProtocolobject. 2.4Exceptions Exceptionsaresyntacticallyandfunctionallyequivalenttostructs exceptthatthey aredeclaredusingtheexceptionkeywordinstead ofthestructkeyword. Thegeneratedobjectsinheritfromanexceptionbaseclassasap- propriateineachtargetprogramminglanguage,inordertoseam- lesslyintegratewithnative exceptionhandlinginany givenlan- guage.Again,thedesignemphasisis onmakingthecodefamiliar totheapplicationdeveloper. 2.5Services ServicesaredefinedusingThrifttypes.Definitionofa serviceis semanticallyequivalenttodefininganinterface(ora purevirtual abstractclass)in objectorientedprogramming.TheThriftcompiler generatesfullyfunctionalclientandserver stubsthatimplementthe interface.Servicesaredefinedasfollows: service<name>{ <returntype><name>(<arguments>) [throws(<exceptions>)] ... } Anexample: serviceStringCache{ voidset(1:i32key,2:stringvalue), stringget(1:i32key)throws(1:KeyNotFoundknf), voiddelete(1:i32key) } Notethatvoidisa validtypefora functionreturn,inaddition toallotherdefinedThrifttypes.Additionally, anasyncmodifier keywordmaybeaddedtoavoidfunction,whichwillgenerate codethatdoesnotwaitfora responsefromtheserver. Notethata purevoidfunctionwillretur
Excerpt from a page describing this subject · 38,933 chars · not written by Vinony
Wikidata facts
- Official website
- thrift.apache.org
Show 8 more facts
- described at URL
- thrift.apache.org/static/files/thrift-20070401.pdf
- software version identifier
- 0.22.0
- source code repository URL
- github.com/apache/thrift.git
- publication date
- 2007-00-00
- issue tracker URL
- issues.apache.org/jira/browse/THRIFT
- inception
- 2012-04-14
- download URL
- thrift.apache.org/download
- Commons category
- Apache Thrift
Sources (3)
via Wikidata · CC0