Apache Thrift - Home
thrift.apache.org →Link to the official site · 7,690 chars · not written by Vinony
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
via Wikidata · CC0
Discovered by embedding cosine similarity (sentence-transformers MiniLM, 384-dim).