rtlfield.cpp 128 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include "platform.h"
  14. #include <math.h>
  15. #include <stdio.h>
  16. #include "jmisc.hpp"
  17. #include "jlib.hpp"
  18. #include "eclhelper.hpp"
  19. #include "eclrtl_imp.hpp"
  20. #include "rtlfield.hpp"
  21. #include "rtlds_imp.hpp"
  22. #include "nbcd.hpp"
  23. static const char * queryXPath(const RtlFieldInfo * field)
  24. {
  25. const char * xpath = field->xpath;
  26. if (xpath)
  27. {
  28. const char * sep = strchr(xpath, xpathCompoundSeparatorChar);
  29. if (!sep)
  30. return xpath;
  31. return sep+1;
  32. }
  33. return field->name;
  34. }
  35. static const char * queryScalarXPath(const RtlFieldInfo * field)
  36. {
  37. if (field->hasNonScalarXpath())
  38. return field->name;
  39. return queryXPath(field);
  40. }
  41. static bool hasOuterXPath(const RtlFieldInfo * field)
  42. {
  43. const char * xpath = field->xpath;
  44. assertex(xpath);
  45. return (*xpath != xpathCompoundSeparatorChar);
  46. }
  47. static void queryNestedOuterXPath(StringAttr & ret, const RtlFieldInfo * field)
  48. {
  49. const char * xpath = field->xpath;
  50. assertex(xpath);
  51. const char * sep = strchr(xpath, xpathCompoundSeparatorChar);
  52. assertex(sep);
  53. ret.set(xpath, (size32_t)(sep-xpath));
  54. }
  55. inline const char * queryName(const RtlFieldInfo * field) { return field ? field->name : nullptr; }
  56. //-------------------------------------------------------------------------------------------------------------------
  57. class DummyFieldProcessor : public CInterfaceOf<IFieldProcessor>
  58. {
  59. public:
  60. virtual void processString(unsigned len, const char *value, const RtlFieldInfo * field) {}
  61. virtual void processBool(bool value, const RtlFieldInfo * field) {}
  62. virtual void processData(unsigned len, const void *value, const RtlFieldInfo * field) {}
  63. virtual void processInt(__int64 value, const RtlFieldInfo * field) {}
  64. virtual void processUInt(unsigned __int64 value, const RtlFieldInfo * field) {}
  65. virtual void processReal(double value, const RtlFieldInfo * field) {}
  66. virtual void processDecimal(const void *value, unsigned digits, unsigned precision, const RtlFieldInfo * field) {}
  67. virtual void processUDecimal(const void *value, unsigned digits, unsigned precision, const RtlFieldInfo * field) {}
  68. virtual void processUnicode(unsigned len, const UChar *value, const RtlFieldInfo * field) {}
  69. virtual void processQString(unsigned len, const char *value, const RtlFieldInfo * field) {}
  70. virtual void processUtf8(unsigned len, const char *value, const RtlFieldInfo * field) {}
  71. virtual bool processBeginSet(const RtlFieldInfo * field, unsigned numElements, bool isAll, const byte *data) { return false; }
  72. virtual bool processBeginDataset(const RtlFieldInfo * field, unsigned numRows) { return true; }
  73. virtual bool processBeginRow(const RtlFieldInfo * field) { return true; }
  74. virtual void processEndSet(const RtlFieldInfo * field) {}
  75. virtual void processEndDataset(const RtlFieldInfo * field) {}
  76. virtual void processEndRow(const RtlFieldInfo * field) {}
  77. };
  78. //-------------------------------------------------------------------------------------------------------------------
  79. size32_t ECLRTL_API getMinSize(const RtlFieldInfo * const * fields)
  80. {
  81. size32_t minSize = 0;
  82. for(;;)
  83. {
  84. const RtlFieldInfo * cur = *fields;
  85. if (!cur)
  86. return minSize;
  87. minSize += cur->type->getMinSize();
  88. fields++;
  89. }
  90. }
  91. //-------------------------------------------------------------------------------------------------------------------
  92. size32_t RtlTypeInfoBase::getMinSize() const
  93. {
  94. return length;
  95. }
  96. size32_t RtlTypeInfoBase::size(const byte * self, const byte * selfrow) const
  97. {
  98. return length;
  99. }
  100. size32_t RtlTypeInfoBase::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  101. {
  102. rtlFailUnexpected();
  103. return 0;
  104. }
  105. size32_t RtlTypeInfoBase::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & out) const
  106. {
  107. rtlFailUnexpected();
  108. return 0;
  109. }
  110. size32_t RtlTypeInfoBase::build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const
  111. {
  112. rtlFailUnexpected();
  113. return 0;
  114. }
  115. size32_t RtlTypeInfoBase::buildNull(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field) const
  116. {
  117. if (field->initializer)
  118. {
  119. size32_t initSize = size(field->initializer, nullptr);
  120. builder.ensureCapacity(offset+initSize, queryName(field));
  121. memcpy(builder.getSelf()+offset, field->initializer, initSize);
  122. return offset+initSize;
  123. }
  124. else
  125. {
  126. // This code covers a lot (though not all) of the derived cases
  127. size32_t initSize = getMinSize();
  128. builder.ensureCapacity(offset+initSize, queryName(field));
  129. memset(builder.getSelf() + offset, 0, initSize);
  130. return offset + initSize;
  131. }
  132. }
  133. size32_t RtlTypeInfoBase::buildInt(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, __int64 val) const
  134. {
  135. size32_t newLen;
  136. rtlDataAttr temp;
  137. rtlInt8ToStrX(newLen, temp.refstr(), val);
  138. return buildString(builder, offset, field, newLen, temp.getstr());
  139. }
  140. size32_t RtlTypeInfoBase::buildReal(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, double val) const
  141. {
  142. size32_t newLen;
  143. rtlDataAttr temp;
  144. rtlRealToStrX(newLen, temp.refstr(), val);
  145. return buildString(builder, offset, field, newLen, temp.getstr());
  146. }
  147. double RtlTypeInfoBase::getReal(const void * ptr) const
  148. {
  149. size32_t len;
  150. rtlDataAttr value;
  151. getString(len, value.refstr(), ptr);
  152. return rtlStrToReal(len, value.getstr());
  153. }
  154. const char * RtlTypeInfoBase::queryLocale() const
  155. {
  156. return NULL;
  157. }
  158. bool RtlTypeInfoBase::isScalar() const
  159. {
  160. return true;
  161. }
  162. const RtlFieldInfo * const * RtlTypeInfoBase::queryFields() const
  163. {
  164. return NULL;
  165. }
  166. const RtlTypeInfo * RtlTypeInfoBase::queryChildType() const
  167. {
  168. return NULL;
  169. }
  170. size32_t RtlTypeInfoBase::deserialize(ARowBuilder & builder, IRowDeserializerSource & in, size32_t offset) const
  171. {
  172. size32_t thisSize = size(nullptr, nullptr);
  173. byte * dest = builder.ensureCapacity(offset + thisSize, nullptr) + offset;
  174. in.read(thisSize, dest);
  175. return offset + thisSize;
  176. }
  177. void RtlTypeInfoBase::readAhead(IRowDeserializerSource & in) const
  178. {
  179. size32_t thisSize = size(nullptr, nullptr);
  180. in.skip(thisSize);
  181. }
  182. size32_t RtlTypeInfoBase::buildUtf8ViaString(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t len, const char *value) const
  183. {
  184. size32_t newLen;
  185. rtlDataAttr temp;
  186. rtlUtf8ToStrX(newLen, temp.refstr(), len, value);
  187. return buildString(builder, offset, field, newLen, temp.getstr());
  188. }
  189. void RtlTypeInfoBase::getUtf8ViaString(size32_t & resultLen, char * & result, const void * ptr) const
  190. {
  191. size32_t newLen;
  192. rtlDataAttr temp;
  193. getString(newLen, temp.refstr(), ptr);
  194. rtlStrToUtf8X(resultLen, result, newLen, temp.getstr());
  195. }
  196. //-------------------------------------------------------------------------------------------------------------------
  197. size32_t RtlBoolTypeInfo::build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const
  198. {
  199. builder.ensureCapacity(sizeof(bool)+offset, queryName(field));
  200. bool val = source.getBooleanResult(field);
  201. * (bool *) (builder.getSelf() + offset) = val;
  202. offset += sizeof(bool);
  203. return offset;
  204. }
  205. size32_t RtlBoolTypeInfo::buildInt(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, __int64 val) const
  206. {
  207. builder.ensureCapacity(sizeof(bool)+offset, queryName(field));
  208. * (bool *) (builder.getSelf() + offset) = val != 0;
  209. offset += sizeof(bool);
  210. return offset;
  211. }
  212. size32_t RtlBoolTypeInfo::buildString(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t len, const char *value) const
  213. {
  214. return buildInt(builder, offset, field, rtlStrToBool(len, value));
  215. }
  216. size32_t RtlBoolTypeInfo::buildUtf8(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t len, const char *value) const
  217. {
  218. size32_t size = rtlUtf8Length(len, value);
  219. return buildInt(builder, offset, field, rtlStrToBool(size, value));
  220. }
  221. size32_t RtlBoolTypeInfo::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  222. {
  223. target.processBool(*(const bool *)self, field);
  224. return sizeof(bool);
  225. }
  226. size32_t RtlBoolTypeInfo::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const
  227. {
  228. target.outputBool(*(const bool *)self, queryScalarXPath(field));
  229. return sizeof(bool);
  230. }
  231. void RtlBoolTypeInfo::getString(size32_t & resultLen, char * & result, const void * ptr) const
  232. {
  233. const bool * cast = static_cast<const bool *>(ptr);
  234. rtlBoolToStrX(resultLen, result, *cast);
  235. }
  236. void RtlBoolTypeInfo::getUtf8(size32_t & resultLen, char * & result, const void * ptr) const
  237. {
  238. getString(resultLen, result, ptr);
  239. }
  240. __int64 RtlBoolTypeInfo::getInt(const void * ptr) const
  241. {
  242. const bool * cast = static_cast<const bool *>(ptr);
  243. return (__int64)*cast;
  244. }
  245. bool RtlBoolTypeInfo::getBool(const void * ptr) const
  246. {
  247. const bool * cast = static_cast<const bool *>(ptr);
  248. return *cast;
  249. }
  250. int RtlBoolTypeInfo::compare(const byte * left, const byte * right) const
  251. {
  252. bool leftValue = getBool(left);
  253. bool rightValue = getBool (right);
  254. return (!leftValue && rightValue) ? -1 : (leftValue && !rightValue) ? +1 : 0;
  255. }
  256. unsigned RtlBoolTypeInfo::hash(const byte *self, unsigned inhash) const
  257. {
  258. __int64 val = getInt(self);
  259. return rtlHash32Data8(&val, inhash);
  260. }
  261. //-------------------------------------------------------------------------------------------------------------------
  262. double RtlRealTypeInfo::value(const void * self) const
  263. {
  264. if (length == 4)
  265. return *(const float *)self;
  266. return *(const double *)self;
  267. }
  268. size32_t RtlRealTypeInfo::build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const
  269. {
  270. builder.ensureCapacity(length+offset, queryName(field));
  271. double val = source.getRealResult(field);
  272. return buildReal(builder, offset, field, val);
  273. }
  274. size32_t RtlRealTypeInfo::buildReal(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, double val) const
  275. {
  276. byte *dest = builder.getSelf() + offset;
  277. if (length == 4)
  278. *(float *) dest = (float) val;
  279. else
  280. *(double *) dest = val;
  281. offset += length;
  282. return offset;
  283. }
  284. size32_t RtlRealTypeInfo::buildString(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t len, const char *value) const
  285. {
  286. return buildReal(builder, offset, field, rtlStrToReal(len, value));
  287. }
  288. size32_t RtlRealTypeInfo::buildUtf8(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t len, const char *value) const
  289. {
  290. size32_t size = rtlUtf8Length(len, value);
  291. return buildReal(builder, offset, field, rtlStrToReal(size, value));
  292. }
  293. size32_t RtlRealTypeInfo::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  294. {
  295. target.processReal(value(self), field);
  296. return length;
  297. }
  298. size32_t RtlRealTypeInfo::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const
  299. {
  300. target.outputReal(value(self), queryScalarXPath(field));
  301. return length;
  302. }
  303. void RtlRealTypeInfo::getString(size32_t & resultLen, char * & result, const void * ptr) const
  304. {
  305. double num = value(ptr);
  306. rtlRealToStrX(resultLen, result, num);
  307. }
  308. void RtlRealTypeInfo::getUtf8(size32_t & resultLen, char * & result, const void * ptr) const
  309. {
  310. getString(resultLen, result, ptr);
  311. }
  312. __int64 RtlRealTypeInfo::getInt(const void * ptr) const
  313. {
  314. double num = value(ptr);
  315. return (__int64)num;
  316. }
  317. double RtlRealTypeInfo::getReal(const void * ptr) const
  318. {
  319. return value(ptr);
  320. }
  321. int RtlRealTypeInfo::compare(const byte * left, const byte * right) const
  322. {
  323. double leftValue = getReal(left);
  324. double rightValue = getReal(right);
  325. return (leftValue < rightValue) ? -1 : (leftValue > rightValue) ? +1 : 0;
  326. }
  327. unsigned RtlRealTypeInfo::hash(const byte *self, unsigned inhash) const
  328. {
  329. double val = getReal(self);
  330. return rtlHash32Data8(&val, inhash);
  331. }
  332. //-------------------------------------------------------------------------------------------------------------------
  333. size32_t RtlIntTypeInfo::build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const
  334. {
  335. builder.ensureCapacity(length+offset, queryName(field));
  336. __int64 val = isUnsigned() ? (__int64) source.getUnsignedResult(field) : source.getSignedResult(field);
  337. rtlWriteInt(builder.getSelf() + offset, val, length);
  338. offset += length;
  339. return offset;
  340. }
  341. size32_t RtlIntTypeInfo::buildInt(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, __int64 val) const
  342. {
  343. builder.ensureCapacity(length+offset, queryName(field));
  344. rtlWriteInt(builder.getSelf() + offset, val, length);
  345. offset += length;
  346. return offset;
  347. }
  348. size32_t RtlIntTypeInfo::buildString(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t size, const char *value) const
  349. {
  350. return buildInt(builder, offset, field, rtlStrToInt8(size, value));
  351. }
  352. size32_t RtlIntTypeInfo::buildUtf8(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t len, const char *value) const
  353. {
  354. size32_t size = rtlUtf8Length(len, value);
  355. return buildInt(builder, offset, field, rtlStrToInt8(size, value));
  356. }
  357. size32_t RtlIntTypeInfo::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  358. {
  359. if (isUnsigned())
  360. target.processUInt(rtlReadUInt(self, length), field);
  361. else
  362. target.processInt(rtlReadInt(self, length), field);
  363. return length;
  364. }
  365. size32_t RtlIntTypeInfo::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const
  366. {
  367. if (isUnsigned())
  368. target.outputUInt(rtlReadUInt(self, length), length, queryScalarXPath(field));
  369. else
  370. target.outputInt(rtlReadInt(self, length), length, queryScalarXPath(field));
  371. return length;
  372. }
  373. void RtlIntTypeInfo::getString(size32_t & resultLen, char * & result, const void * ptr) const
  374. {
  375. if (isUnsigned())
  376. rtlUInt8ToStrX(resultLen, result, rtlReadUInt(ptr, length));
  377. else
  378. rtlInt8ToStrX(resultLen, result, rtlReadInt(ptr, length));
  379. }
  380. void RtlIntTypeInfo::getUtf8(size32_t & resultLen, char * & result, const void * ptr) const
  381. {
  382. getString(resultLen, result, ptr);
  383. }
  384. __int64 RtlIntTypeInfo::getInt(const void * ptr) const
  385. {
  386. if (isUnsigned())
  387. return rtlReadUInt(ptr, length);
  388. else
  389. return rtlReadInt(ptr, length);
  390. }
  391. double RtlIntTypeInfo::getReal(const void * ptr) const
  392. {
  393. if (isUnsigned())
  394. return (double) rtlReadUInt(ptr, length);
  395. else
  396. return (double) rtlReadInt(ptr, length);
  397. }
  398. int RtlIntTypeInfo::compare(const byte * left, const byte * right) const
  399. {
  400. if (isUnsigned())
  401. {
  402. unsigned __int64 leftValue = rtlReadUInt(left, length);
  403. unsigned __int64 rightValue = rtlReadUInt(right, length);
  404. return (leftValue < rightValue) ? -1 : (leftValue > rightValue) ? +1 : 0;
  405. }
  406. else
  407. {
  408. __int64 leftValue = rtlReadInt(left, length);
  409. __int64 rightValue = rtlReadInt(right, length);
  410. return (leftValue < rightValue) ? -1 : (leftValue > rightValue) ? +1 : 0;
  411. }
  412. }
  413. bool RtlIntTypeInfo::canMemCmp() const
  414. {
  415. #if __BYTE_ORDER == __LITTLE_ENDIAN
  416. return false;
  417. #else
  418. return isUnsigned();
  419. #endif
  420. }
  421. unsigned RtlIntTypeInfo::hash(const byte *self, unsigned inhash) const
  422. {
  423. __int64 val = getInt(self);
  424. return rtlHash32Data8(&val, inhash);
  425. }
  426. bool RtlIntTypeInfo::canTruncate() const
  427. {
  428. #if __BYTE_ORDER == __LITTLE_ENDIAN
  429. return true;
  430. #else
  431. return false;
  432. #endif
  433. }
  434. bool RtlIntTypeInfo::canExtend(char &fillChar) const
  435. {
  436. #if __BYTE_ORDER == __LITTLE_ENDIAN
  437. fillChar = 0;
  438. return true;
  439. #else
  440. return false;
  441. #endif
  442. }
  443. //-------------------------------------------------------------------------------------------------------------------
  444. size32_t RtlBlobTypeInfo::getMinSize() const
  445. {
  446. return sizeof(offset_t);
  447. }
  448. size32_t RtlBlobTypeInfo::build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const
  449. {
  450. throwUnexpected(); // This is only expected to be used for reading at present
  451. }
  452. size32_t RtlBlobTypeInfo::buildInt(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, __int64 val) const
  453. {
  454. throwUnexpected(); // This is only expected to be used for reading at present
  455. }
  456. size32_t RtlBlobTypeInfo::buildString(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t size, const char *value) const
  457. {
  458. throwUnexpected(); // This is only expected to be used for reading at present
  459. }
  460. size32_t RtlBlobTypeInfo::buildUtf8(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t len, const char *value) const
  461. {
  462. throwUnexpected(); // This is only expected to be used for reading at present
  463. }
  464. size32_t RtlBlobTypeInfo::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  465. {
  466. assertex(callback);
  467. UNIMPLEMENTED;
  468. }
  469. size32_t RtlBlobTypeInfo::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const
  470. {
  471. assertex(callback);
  472. UNIMPLEMENTED;
  473. }
  474. void RtlBlobTypeInfo::getString(size32_t & resultLen, char * & result, const void * ptr) const
  475. {
  476. assertex(callback);
  477. UNIMPLEMENTED;
  478. }
  479. void RtlBlobTypeInfo::getUtf8(size32_t & resultLen, char * & result, const void * ptr) const
  480. {
  481. UNIMPLEMENTED;
  482. }
  483. __int64 RtlBlobTypeInfo::getInt(const void * ptr) const
  484. {
  485. UNIMPLEMENTED;
  486. }
  487. double RtlBlobTypeInfo::getReal(const void * ptr) const
  488. {
  489. UNIMPLEMENTED;
  490. }
  491. bool RtlBlobTypeInfo::canTruncate() const
  492. {
  493. return false;
  494. }
  495. bool RtlBlobTypeInfo::canExtend(char &fillChar) const
  496. {
  497. return false;
  498. }
  499. void RtlBlobTypeInfo::setCallback(IThorIndexCallback *_callback)
  500. {
  501. callback = _callback;
  502. }
  503. int RtlBlobTypeInfo::compare(const byte * left, const byte * right) const
  504. {
  505. UNIMPLEMENTED;
  506. }
  507. unsigned RtlBlobTypeInfo::hash(const byte *self, unsigned inhash) const
  508. {
  509. UNIMPLEMENTED;
  510. }
  511. //-------------------------------------------------------------------------------------------------------------------
  512. size32_t RtlSwapIntTypeInfo::build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const
  513. {
  514. builder.ensureCapacity(length+offset, queryName(field));
  515. __int64 val = isUnsigned() ? (__int64) source.getUnsignedResult(field) : source.getSignedResult(field);
  516. // NOTE - we assume that the value returned from the source is NOT already a swapped int - source doesn't know that we are going to store it swapped
  517. rtlWriteSwapInt(builder.getSelf() + offset, val, length);
  518. offset += length;
  519. return offset;
  520. }
  521. size32_t RtlSwapIntTypeInfo::buildInt(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, __int64 val) const
  522. {
  523. builder.ensureCapacity(length+offset, queryName(field));
  524. rtlWriteSwapInt(builder.getSelf() + offset, val, length);
  525. offset += length;
  526. return offset;
  527. }
  528. size32_t RtlSwapIntTypeInfo::buildString(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t size, const char *value) const
  529. {
  530. return buildInt(builder, offset, field, rtlStrToInt8(size, value));
  531. }
  532. size32_t RtlSwapIntTypeInfo::buildUtf8(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t len, const char *value) const
  533. {
  534. size32_t size = rtlUtf8Length(len, value);
  535. return buildInt(builder, offset, field, rtlStrToInt8(size, value));
  536. }
  537. size32_t RtlSwapIntTypeInfo::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  538. {
  539. if (isUnsigned())
  540. target.processUInt(rtlReadSwapUInt(self, length), field);
  541. else
  542. target.processInt(rtlReadSwapInt(self, length), field);
  543. return length;
  544. }
  545. size32_t RtlSwapIntTypeInfo::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const
  546. {
  547. if (isUnsigned())
  548. target.outputUInt(rtlReadSwapUInt(self, length), length, queryScalarXPath(field));
  549. else
  550. target.outputInt(rtlReadSwapInt(self, length), length, queryScalarXPath(field));
  551. return length;
  552. }
  553. void RtlSwapIntTypeInfo::getString(size32_t & resultLen, char * & result, const void * ptr) const
  554. {
  555. if (isUnsigned())
  556. rtlUInt8ToStrX(resultLen, result, rtlReadSwapUInt(ptr, length));
  557. else
  558. rtlInt8ToStrX(resultLen, result, rtlReadSwapInt(ptr, length));
  559. }
  560. void RtlSwapIntTypeInfo::getUtf8(size32_t & resultLen, char * & result, const void * ptr) const
  561. {
  562. getString(resultLen, result, ptr);
  563. }
  564. __int64 RtlSwapIntTypeInfo::getInt(const void * ptr) const
  565. {
  566. if (isUnsigned())
  567. return rtlReadSwapUInt(ptr, length);
  568. else
  569. return rtlReadSwapInt(ptr, length);
  570. }
  571. double RtlSwapIntTypeInfo::getReal(const void * ptr) const
  572. {
  573. if (isUnsigned())
  574. return (double) rtlReadSwapUInt(ptr, length);
  575. else
  576. return (double) (rtlReadSwapInt(ptr, length));
  577. }
  578. int RtlSwapIntTypeInfo::compare(const byte * left, const byte * right) const
  579. {
  580. if (isUnsigned())
  581. {
  582. unsigned __int64 leftValue = rtlReadSwapUInt(left, length);
  583. unsigned __int64 rightValue = rtlReadSwapUInt(right, length);
  584. return (leftValue < rightValue) ? -1 : (leftValue > rightValue) ? +1 : 0;
  585. }
  586. else
  587. {
  588. __int64 leftValue = rtlReadSwapInt(left, length);
  589. __int64 rightValue = rtlReadSwapInt(right, length);
  590. return (leftValue < rightValue) ? -1 : (leftValue > rightValue) ? +1 : 0;
  591. }
  592. }
  593. bool RtlSwapIntTypeInfo::canMemCmp() const
  594. {
  595. #if __BYTE_ORDER == __LITTLE_ENDIAN
  596. return isUnsigned();
  597. #else
  598. return false;
  599. #endif
  600. }
  601. unsigned RtlSwapIntTypeInfo::hash(const byte *self, unsigned inhash) const
  602. {
  603. __int64 val = getInt(self);
  604. return rtlHash32Data8(&val, inhash);
  605. }
  606. bool RtlSwapIntTypeInfo::canTruncate() const
  607. {
  608. #if __BYTE_ORDER == __LITTLE_ENDIAN
  609. return false;
  610. #else
  611. return true;
  612. #endif
  613. }
  614. bool RtlSwapIntTypeInfo::canExtend(char &fillChar) const
  615. {
  616. #if __BYTE_ORDER == __LITTLE_ENDIAN
  617. return false;
  618. #else
  619. fillChar = 0;
  620. return true;
  621. #endif
  622. }
  623. //-------------------------------------------------------------------------------------------------------------------
  624. size32_t RtlKeyedIntTypeInfo::build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const
  625. {
  626. __int64 val = isUnsigned() ? (__int64) source.getUnsignedResult(field) : source.getSignedResult(field);
  627. return buildInt(builder, offset, field, val);
  628. }
  629. size32_t RtlKeyedIntTypeInfo::buildInt(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, __int64 val) const
  630. {
  631. builder.ensureCapacity(length+offset, queryName(field));
  632. if (isUnsigned())
  633. #if __BYTE_ORDER == __LITTLE_ENDIAN
  634. rtlWriteSwapInt(builder.getSelf() + offset, val, length);
  635. #else
  636. rtlWriteInt(builder.getSelf() + offset, val, length);
  637. #endif
  638. else
  639. #if __BYTE_ORDER == __LITTLE_ENDIAN
  640. rtlWriteSwapInt(builder.getSelf() + offset, addBias(val, length), length);
  641. #else
  642. rtlWriteInt(builder.getSelf() + offset, addBias(val, length), length);
  643. #endif
  644. offset += length;
  645. return offset;
  646. }
  647. size32_t RtlKeyedIntTypeInfo::buildString(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t size, const char *value) const
  648. {
  649. return buildInt(builder, offset, field, rtlStrToInt8(size, value));
  650. }
  651. size32_t RtlKeyedIntTypeInfo::buildUtf8(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t len, const char *value) const
  652. {
  653. size32_t size = rtlUtf8Length(len, value);
  654. return buildInt(builder, offset, field, rtlStrToInt8(size, value));
  655. }
  656. size32_t RtlKeyedIntTypeInfo::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  657. {
  658. if (isUnsigned())
  659. target.processUInt(getUInt(self), field);
  660. else
  661. target.processInt(getInt(self), field);
  662. return length;
  663. }
  664. size32_t RtlKeyedIntTypeInfo::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const
  665. {
  666. if (isUnsigned())
  667. target.outputUInt(getUInt(self), length, queryScalarXPath(field));
  668. else
  669. target.outputInt(getInt(self), length, queryScalarXPath(field));
  670. return length;
  671. }
  672. void RtlKeyedIntTypeInfo::getString(size32_t & resultLen, char * & result, const void * ptr) const
  673. {
  674. if (isUnsigned())
  675. rtlUInt8ToStrX(resultLen, result, getUInt(ptr));
  676. else
  677. rtlInt8ToStrX(resultLen, result, getInt(ptr));
  678. }
  679. void RtlKeyedIntTypeInfo::getUtf8(size32_t & resultLen, char * & result, const void * ptr) const
  680. {
  681. getString(resultLen, result, ptr);
  682. }
  683. __int64 RtlKeyedIntTypeInfo::getInt(const void * ptr) const
  684. {
  685. #if __BYTE_ORDER == __LITTLE_ENDIAN
  686. if (isUnsigned())
  687. return rtlReadSwapUInt(ptr, length);
  688. else
  689. return removeBias(rtlReadSwapUInt(ptr, length), length);
  690. #else
  691. if (isUnsigned())
  692. return rtlReadUInt(ptr, length);
  693. else
  694. return removeBias(rtlReadInt(ptr, length), length);
  695. #endif
  696. }
  697. double RtlKeyedIntTypeInfo::getReal(const void * ptr) const
  698. {
  699. if (isUnsigned())
  700. return (double) getUInt(ptr);
  701. else
  702. return (double) getInt(ptr);
  703. }
  704. int RtlKeyedIntTypeInfo::compare(const byte * left, const byte * right) const
  705. {
  706. // The whole point of biased ints is that we can do this:
  707. return memcmp(left, right, length);
  708. }
  709. unsigned RtlKeyedIntTypeInfo::hash(const byte *self, unsigned inhash) const
  710. {
  711. __int64 val = getInt(self);
  712. return rtlHash32Data8(&val, inhash);
  713. }
  714. unsigned __int64 RtlKeyedIntTypeInfo::addBias(__int64 value, unsigned length)
  715. {
  716. return value + ((unsigned __int64)1 << (length*8-1));
  717. }
  718. __int64 RtlKeyedIntTypeInfo::removeBias(unsigned __int64 value, unsigned length)
  719. {
  720. return value - ((unsigned __int64)1 << (length*8-1));
  721. }
  722. //-------------------------------------------------------------------------------------------------------------------
  723. size32_t RtlPackedIntTypeInfo::getMinSize() const
  724. {
  725. return 1;
  726. }
  727. size32_t RtlPackedIntTypeInfo::size(const byte * self, const byte * selfrow) const
  728. {
  729. return rtlGetPackedSize(self);
  730. }
  731. size32_t RtlPackedIntTypeInfo::build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const
  732. {
  733. __int64 value = isUnsigned() ? (__int64) source.getUnsignedResult(field) : source.getSignedResult(field);
  734. return buildInt(builder, offset, field, value);
  735. }
  736. size32_t RtlPackedIntTypeInfo::buildInt(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, __int64 val) const
  737. {
  738. size32_t sizeInBytes = rtlGetPackedSize(&val);
  739. builder.ensureCapacity(sizeInBytes+offset, queryName(field));
  740. rtlSetPackedUnsigned(builder.getSelf() + offset, val);
  741. offset += sizeInBytes;
  742. return offset;
  743. }
  744. size32_t RtlPackedIntTypeInfo::buildString(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t size, const char *value) const
  745. {
  746. return buildInt(builder, offset, field, rtlStrToInt8(size, value));
  747. }
  748. size32_t RtlPackedIntTypeInfo::buildUtf8(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t len, const char *value) const
  749. {
  750. size32_t size = rtlUtf8Length(len, value);
  751. return buildInt(builder, offset, field, rtlStrToInt8(size, value));
  752. }
  753. size32_t RtlPackedIntTypeInfo::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  754. {
  755. if (isUnsigned())
  756. target.processUInt(rtlGetPackedUnsigned(self), field);
  757. else
  758. target.processInt(rtlGetPackedSigned(self), field);
  759. return rtlGetPackedSize(self);
  760. }
  761. size32_t RtlPackedIntTypeInfo::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const
  762. {
  763. size32_t fieldsize = rtlGetPackedSize(self);
  764. if (isUnsigned())
  765. target.outputUInt(rtlGetPackedUnsigned(self), fieldsize, queryScalarXPath(field));
  766. else
  767. target.outputInt(rtlGetPackedSigned(self), fieldsize, queryScalarXPath(field));
  768. return fieldsize;
  769. }
  770. size32_t RtlPackedIntTypeInfo::deserialize(ARowBuilder & builder, IRowDeserializerSource & in, size32_t offset) const
  771. {
  772. char temp[9];
  773. size32_t size = in.readPackedInt(temp);
  774. byte * dest = builder.ensureCapacity(offset + size, nullptr) + offset;
  775. memcpy(dest, temp, size);
  776. return offset + size;
  777. }
  778. void RtlPackedIntTypeInfo::readAhead(IRowDeserializerSource & in) const
  779. {
  780. in.skipPackedInt();
  781. }
  782. void RtlPackedIntTypeInfo::getString(size32_t & resultLen, char * & result, const void * ptr) const
  783. {
  784. if (isUnsigned())
  785. rtlUInt8ToStrX(resultLen, result, rtlGetPackedUnsigned(ptr));
  786. else
  787. rtlInt8ToStrX(resultLen, result, rtlGetPackedSigned(ptr));
  788. }
  789. void RtlPackedIntTypeInfo::getUtf8(size32_t & resultLen, char * & result, const void * ptr) const
  790. {
  791. getString(resultLen, result, ptr);
  792. }
  793. __int64 RtlPackedIntTypeInfo::getInt(const void * ptr) const
  794. {
  795. if (isUnsigned())
  796. return rtlGetPackedUnsigned(ptr);
  797. else
  798. return rtlGetPackedSigned(ptr);
  799. }
  800. double RtlPackedIntTypeInfo::getReal(const void * ptr) const
  801. {
  802. if (isUnsigned())
  803. return (double) rtlGetPackedUnsigned(ptr);
  804. else
  805. return (double) rtlGetPackedSigned(ptr);
  806. }
  807. int RtlPackedIntTypeInfo::compare(const byte * left, const byte * right) const
  808. {
  809. if (isUnsigned())
  810. {
  811. unsigned __int64 leftValue = rtlGetPackedUnsigned(left);
  812. unsigned __int64 rightValue = rtlGetPackedUnsigned(right);
  813. return (leftValue < rightValue) ? -1 : (leftValue > rightValue) ? +1 : 0;
  814. }
  815. else
  816. {
  817. __int64 leftValue = rtlGetPackedSigned(left);
  818. __int64 rightValue = rtlGetPackedSigned(right);
  819. return (leftValue < rightValue) ? -1 : (leftValue > rightValue) ? +1 : 0;
  820. }
  821. }
  822. unsigned RtlPackedIntTypeInfo::hash(const byte *self, unsigned inhash) const
  823. {
  824. __int64 val = getInt(self);
  825. return rtlHash32Data8(&val, inhash);
  826. }
  827. //-------------------------------------------------------------------------------------------------------------------
  828. size32_t RtlStringTypeInfo::getMinSize() const
  829. {
  830. if (isFixedSize())
  831. return length;
  832. return sizeof(size32_t);
  833. }
  834. size32_t RtlStringTypeInfo::size(const byte * self, const byte * selfrow) const
  835. {
  836. if (isFixedSize())
  837. return length;
  838. return sizeof(size32_t) + rtlReadSize32t(self);
  839. }
  840. size32_t RtlStringTypeInfo::build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const
  841. {
  842. size32_t size;
  843. rtlDataAttr value;
  844. source.getStringResult(field, size, value.refstr());
  845. return buildString(builder, offset, field, size, value.getstr());
  846. }
  847. size32_t RtlStringTypeInfo::buildString(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t size, const char *value) const
  848. {
  849. if (!isFixedSize())
  850. {
  851. builder.ensureCapacity(offset+size+sizeof(size32_t), queryName(field));
  852. byte *dest = builder.getSelf()+offset;
  853. rtlWriteInt4(dest, size);
  854. // NOTE - it has been the subject of debate whether we should convert the incoming data to EBCDIC, or expect the IFieldSource to have already returned ebcdic
  855. // In order to be symmetrical with the passing of ecl data to a IFieldProcessor the former interpretation is preferred.
  856. // Expecting source.getStringResult to somehow "know" that EBCDIC was expected seems odd.
  857. if (isEbcdic())
  858. rtlStrToEStr(size, (char *) dest+sizeof(size32_t), size, (char *)value);
  859. else
  860. memcpy(dest+sizeof(size32_t), value, size);
  861. offset += size+sizeof(size32_t);
  862. }
  863. else
  864. {
  865. builder.ensureCapacity(offset+length, queryName(field));
  866. byte *dest = builder.getSelf()+offset;
  867. if (isEbcdic())
  868. rtlStrToEStr(length, (char *) dest, size, (char *) value);
  869. else
  870. rtlStrToStr(length, dest, size, value);
  871. offset += length;
  872. }
  873. return offset;
  874. }
  875. size32_t RtlStringTypeInfo::buildUtf8(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t codepoints, const char *value) const
  876. {
  877. if (isEbcdic())
  878. return buildUtf8ViaString(builder, offset, field, codepoints, value);
  879. if (!isFixedSize())
  880. {
  881. builder.ensureCapacity(offset+codepoints+sizeof(size32_t), queryName(field));
  882. char *dest = (char *) builder.getSelf()+offset;
  883. rtlWriteInt4(dest, codepoints);
  884. rtlUtf8ToStr(codepoints, dest+sizeof(size32_t), codepoints, value);
  885. offset += codepoints+sizeof(size32_t);
  886. }
  887. else
  888. {
  889. builder.ensureCapacity(offset+length, queryName(field));
  890. char *dest = (char *) builder.getSelf()+offset;
  891. rtlUtf8ToStr(length, dest, codepoints, value);
  892. offset += length;
  893. }
  894. return offset;
  895. }
  896. size32_t RtlStringTypeInfo::buildNull(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field) const
  897. {
  898. if (field->initializer || !isFixedSize())
  899. return RtlTypeInfoBase::buildNull(builder, offset, field);
  900. else
  901. {
  902. builder.ensureCapacity(offset+length, queryName(field));
  903. memset(builder.getSelf()+offset, isEbcdic() ? 0x40 : ' ', length);
  904. return offset + length;
  905. }
  906. }
  907. size32_t RtlStringTypeInfo::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  908. {
  909. const char * str = reinterpret_cast<const char *>(self);
  910. unsigned thisLength;
  911. unsigned thisSize;
  912. if (isFixedSize())
  913. {
  914. thisLength = length;
  915. thisSize = thisLength;
  916. }
  917. else
  918. {
  919. str = reinterpret_cast<const char *>(self + sizeof(size32_t));
  920. thisLength = rtlReadSize32t(self);
  921. thisSize = sizeof(size32_t) + thisLength;
  922. }
  923. if (isEbcdic())
  924. {
  925. unsigned lenAscii;
  926. rtlDataAttr ascii;
  927. rtlEStrToStrX(lenAscii, ascii.refstr(), thisLength, str);
  928. target.processString(lenAscii, ascii.getstr(), field);
  929. }
  930. else
  931. {
  932. target.processString(thisLength, str, field);
  933. }
  934. return thisSize;
  935. }
  936. size32_t RtlStringTypeInfo::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const
  937. {
  938. const char * str = reinterpret_cast<const char *>(self);
  939. unsigned thisLength;
  940. unsigned thisSize;
  941. if (isFixedSize())
  942. {
  943. thisLength = length;
  944. thisSize = thisLength;
  945. }
  946. else
  947. {
  948. str = reinterpret_cast<const char *>(self + sizeof(size32_t));
  949. thisLength = rtlReadSize32t(self);
  950. thisSize = sizeof(size32_t) + thisLength;
  951. }
  952. if (isEbcdic())
  953. {
  954. unsigned lenAscii;
  955. rtlDataAttr ascii;
  956. rtlEStrToStrX(lenAscii, ascii.refstr(), thisLength, str);
  957. target.outputString(lenAscii, ascii.getstr(), queryScalarXPath(field));
  958. }
  959. else
  960. {
  961. target.outputString(thisLength, str, queryScalarXPath(field));
  962. }
  963. return thisSize;
  964. }
  965. size32_t RtlStringTypeInfo::deserialize(ARowBuilder & builder, IRowDeserializerSource & in, size32_t offset) const
  966. {
  967. if (isFixedSize())
  968. {
  969. size32_t size = length;
  970. byte * dest = builder.ensureCapacity(offset+size, nullptr) + offset;
  971. in.read(size, dest);
  972. offset += size;
  973. }
  974. else
  975. {
  976. size32_t size = in.readSize();
  977. byte * dest = builder.ensureCapacity(offset+sizeof(size32_t)+size, nullptr) + offset;
  978. rtlWriteSize32t(dest, size);
  979. in.read(size, dest + sizeof(size32_t));
  980. offset += sizeof(size32_t)+size;
  981. }
  982. return offset;
  983. }
  984. void RtlStringTypeInfo::readAhead(IRowDeserializerSource & in) const
  985. {
  986. if (isFixedSize())
  987. {
  988. in.skip(length);
  989. }
  990. else
  991. {
  992. size32_t thisLength = in.readSize();
  993. in.skip(thisLength);
  994. }
  995. }
  996. void RtlStringTypeInfo::getString(size32_t & resultLen, char * & result, const void * ptr) const
  997. {
  998. if (isFixedSize())
  999. {
  1000. if (isEbcdic())
  1001. return rtlEStrToStrX(resultLen, result, length, (const char *)ptr);
  1002. else
  1003. return rtlStrToStrX(resultLen, result, length, (const char *)ptr);
  1004. }
  1005. else
  1006. {
  1007. size32_t len = rtlReadSize32t(ptr);
  1008. if (isEbcdic())
  1009. return rtlEStrToStrX(resultLen, result, len, (const char *)ptr + sizeof(size32_t));
  1010. else
  1011. return rtlStrToStrX(resultLen, result, len, (const char *)ptr + sizeof(size32_t));
  1012. }
  1013. }
  1014. void RtlStringTypeInfo::getUtf8(size32_t & resultLen, char * & result, const void * ptr) const
  1015. {
  1016. if (isEbcdic())
  1017. {
  1018. getUtf8ViaString(resultLen, result, ptr);
  1019. return;
  1020. }
  1021. if (isFixedSize())
  1022. {
  1023. return rtlStrToUtf8X(resultLen, result, length, (const char *)ptr);
  1024. }
  1025. else
  1026. {
  1027. size32_t len = rtlReadSize32t(ptr);
  1028. return rtlStrToUtf8X(resultLen, result, len, (const char *)ptr + sizeof(size32_t));
  1029. }
  1030. }
  1031. __int64 RtlStringTypeInfo::getInt(const void * ptr) const
  1032. {
  1033. //Utf8 output is the same as string output, so avoid the intermediate translation
  1034. if (isFixedSize())
  1035. return rtlStrToInt8(length, (const char *)ptr);
  1036. size32_t len = rtlReadSize32t(ptr);
  1037. return rtlStrToInt8(len, (const char *)ptr + sizeof(size32_t));
  1038. }
  1039. int RtlStringTypeInfo::compare(const byte * left, const byte * right) const
  1040. {
  1041. if (isFixedSize())
  1042. return memcmp(left, right, length);
  1043. else if (isEbcdic())
  1044. {
  1045. // Logically this should be
  1046. // if (isFixedSize())
  1047. // return rtlCompareEStrEStr(length, (const char *)left, length, (const char *)right);
  1048. // but that's the same as a memcmp if lengths match
  1049. size32_t lenLeft = rtlReadSize32t(left);
  1050. size32_t lenRight = rtlReadSize32t(right);
  1051. return rtlCompareEStrEStr(lenLeft, (const char *)left + sizeof(size32_t), lenRight, (const char *)right + sizeof(size32_t));
  1052. }
  1053. else
  1054. {
  1055. // Logically this should be
  1056. // if (isFixedSize())
  1057. // return rtlCompareStrStr(length, (const char *)left, length, (const char *)right); // Actually this is a memcmp
  1058. // but that's the same as a memcmp if lengths match
  1059. size32_t lenLeft = rtlReadSize32t(left);
  1060. size32_t lenRight = rtlReadSize32t(right);
  1061. return rtlCompareStrStr(lenLeft, (const char *)left + sizeof(size32_t), lenRight, (const char *)right + sizeof(size32_t));
  1062. }
  1063. }
  1064. bool RtlStringTypeInfo::canMemCmp() const
  1065. {
  1066. return isFixedSize();
  1067. }
  1068. unsigned RtlStringTypeInfo::hash(const byte * self, unsigned inhash) const
  1069. {
  1070. size32_t len;
  1071. if (isFixedSize())
  1072. len = length;
  1073. else
  1074. {
  1075. len = rtlReadSize32t(self);
  1076. self += sizeof(size32_t);
  1077. }
  1078. return rtlHash32Data(rtlTrimStrLen(len, (const char *) self), self, inhash);
  1079. }
  1080. bool RtlStringTypeInfo::canExtend(char &fillChar) const
  1081. {
  1082. if (isFixedSize())
  1083. {
  1084. fillChar = isEbcdic() ? 0x40 : ' ';
  1085. return true;
  1086. }
  1087. return false;
  1088. }
  1089. //-------------------------------------------------------------------------------------------------------------------
  1090. size32_t RtlDataTypeInfo::getMinSize() const
  1091. {
  1092. if (isFixedSize())
  1093. return length;
  1094. return sizeof(size32_t);
  1095. }
  1096. size32_t RtlDataTypeInfo::size(const byte * self, const byte * selfrow) const
  1097. {
  1098. if (isFixedSize())
  1099. return length;
  1100. return sizeof(size32_t) + rtlReadSize32t(self);
  1101. }
  1102. size32_t RtlDataTypeInfo::build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const
  1103. {
  1104. size32_t size;
  1105. rtlDataAttr value;
  1106. source.getDataResult(field, size, value.refdata());
  1107. return buildString(builder, offset, field, size, value.getstr());
  1108. }
  1109. size32_t RtlDataTypeInfo::buildString(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t size, const char *value) const
  1110. {
  1111. if (!isFixedSize())
  1112. {
  1113. builder.ensureCapacity(offset+size+sizeof(size32_t), queryName(field));
  1114. byte *dest = builder.getSelf()+offset;
  1115. rtlWriteInt4(dest, size);
  1116. memcpy(dest+sizeof(size32_t), value, size);
  1117. offset += size+sizeof(size32_t);
  1118. }
  1119. else
  1120. {
  1121. builder.ensureCapacity(offset+length, queryName(field));
  1122. byte *dest = builder.getSelf()+offset;
  1123. rtlDataToData(length, dest, size, value);
  1124. offset += length;
  1125. }
  1126. return offset;
  1127. }
  1128. size32_t RtlDataTypeInfo::buildUtf8(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t codepoints, const char *value) const
  1129. {
  1130. return buildUtf8ViaString(builder, offset, field, codepoints, value);
  1131. }
  1132. size32_t RtlDataTypeInfo::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  1133. {
  1134. const char * str = reinterpret_cast<const char *>(self);
  1135. unsigned thisLength;
  1136. unsigned thisSize;
  1137. if (isFixedSize())
  1138. {
  1139. thisLength = length;
  1140. thisSize = thisLength;
  1141. }
  1142. else
  1143. {
  1144. str = reinterpret_cast<const char *>(self + sizeof(size32_t));
  1145. thisLength = rtlReadSize32t(self);
  1146. thisSize = sizeof(size32_t) + thisLength;
  1147. }
  1148. target.processData(thisLength, str, field);
  1149. return thisSize;
  1150. }
  1151. size32_t RtlDataTypeInfo::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const
  1152. {
  1153. const char * str = reinterpret_cast<const char *>(self);
  1154. unsigned thisLength;
  1155. unsigned thisSize;
  1156. if (isFixedSize())
  1157. {
  1158. thisLength = length;
  1159. thisSize = thisLength;
  1160. }
  1161. else
  1162. {
  1163. str = reinterpret_cast<const char *>(self + sizeof(size32_t));
  1164. thisLength = rtlReadSize32t(self);
  1165. thisSize = sizeof(size32_t) + thisLength;
  1166. }
  1167. target.outputData(thisLength, str, queryScalarXPath(field));
  1168. return thisSize;
  1169. }
  1170. size32_t RtlDataTypeInfo::deserialize(ARowBuilder & builder, IRowDeserializerSource & in, size32_t offset) const
  1171. {
  1172. if (isFixedSize())
  1173. {
  1174. size32_t size = length;
  1175. byte * dest = builder.ensureCapacity(offset+size, nullptr) + offset;
  1176. in.read(size, dest);
  1177. offset += size;
  1178. }
  1179. else
  1180. {
  1181. size32_t size = in.readSize();
  1182. byte * dest = builder.ensureCapacity(offset+sizeof(size32_t)+size, nullptr) + offset;
  1183. rtlWriteSize32t(dest, size);
  1184. in.read(size, dest + sizeof(size32_t));
  1185. offset += sizeof(size32_t)+size;
  1186. }
  1187. return offset;
  1188. }
  1189. void RtlDataTypeInfo::readAhead(IRowDeserializerSource & in) const
  1190. {
  1191. if (isFixedSize())
  1192. {
  1193. in.skip(length);
  1194. }
  1195. else
  1196. {
  1197. size32_t thisLength = in.readSize();
  1198. in.skip(thisLength);
  1199. }
  1200. }
  1201. void RtlDataTypeInfo::getString(size32_t & resultLen, char * & result, const void * ptr) const
  1202. {
  1203. if (isFixedSize())
  1204. {
  1205. return rtlStrToStrX(resultLen, result, length, (const char *)ptr);
  1206. }
  1207. else
  1208. {
  1209. size32_t len = rtlReadSize32t(ptr);
  1210. return rtlStrToStrX(resultLen, result, len, (const char *)ptr + sizeof(size32_t));
  1211. }
  1212. }
  1213. void RtlDataTypeInfo::getUtf8(size32_t & resultLen, char * & result, const void * ptr) const
  1214. {
  1215. if (isFixedSize())
  1216. {
  1217. return rtlStrToUtf8X(resultLen, result, length, (const char *)ptr);
  1218. }
  1219. else
  1220. {
  1221. size32_t len = rtlReadSize32t(ptr);
  1222. return rtlStrToUtf8X(resultLen, result, len, (const char *)ptr + sizeof(size32_t));
  1223. }
  1224. }
  1225. __int64 RtlDataTypeInfo::getInt(const void * ptr) const
  1226. {
  1227. //Utf8 output is the same as string output, so avoid the intermediate translation
  1228. if (isFixedSize())
  1229. return rtlStrToInt8(length, (const char *)ptr);
  1230. size32_t len = rtlReadSize32t(ptr);
  1231. return rtlStrToInt8(len, (const char *)ptr + sizeof(size32_t));
  1232. }
  1233. int RtlDataTypeInfo::compare(const byte * left, const byte * right) const
  1234. {
  1235. if (isFixedSize())
  1236. // Logically this should be return rtlCompareDataData(length, (const char *)left, length, (const char *)right);
  1237. // but that acts as a memcmp if lengths match
  1238. return memcmp(left, right, length);
  1239. size32_t lenLeft = rtlReadSize32t(left);
  1240. size32_t lenRight = rtlReadSize32t(right);
  1241. return rtlCompareDataData(lenLeft, (const char *)left + sizeof(size32_t), lenRight, (const char *)right + sizeof(size32_t));
  1242. }
  1243. bool RtlDataTypeInfo::canMemCmp() const
  1244. {
  1245. return isFixedSize();
  1246. }
  1247. unsigned RtlDataTypeInfo::hash(const byte *self, unsigned inhash) const
  1248. {
  1249. size32_t len;
  1250. if (isFixedSize())
  1251. len = length;
  1252. else
  1253. {
  1254. len = rtlReadSize32t(self);
  1255. self += sizeof(size32_t);
  1256. }
  1257. return rtlHash32Data(len, self, inhash);
  1258. }
  1259. bool RtlDataTypeInfo::canExtend(char &fillChar) const
  1260. {
  1261. if (isFixedSize())
  1262. {
  1263. fillChar = 0;
  1264. return true;
  1265. }
  1266. return false;
  1267. }
  1268. //-------------------------------------------------------------------------------------------------------------------
  1269. size32_t RtlVarStringTypeInfo::getMinSize() const
  1270. {
  1271. if (isFixedSize())
  1272. return length+1;
  1273. return 1;
  1274. }
  1275. size32_t RtlVarStringTypeInfo::size(const byte * self, const byte * selfrow) const
  1276. {
  1277. if (isFixedSize())
  1278. return length + 1;
  1279. const char * str = reinterpret_cast<const char *>(self);
  1280. return (size32_t)strlen(str)+1;
  1281. }
  1282. size32_t RtlVarStringTypeInfo::build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const
  1283. {
  1284. size32_t size;
  1285. rtlDataAttr value;
  1286. source.getStringResult(field, size, value.refstr());
  1287. return buildString(builder, offset, field, size, value.getstr());
  1288. }
  1289. size32_t RtlVarStringTypeInfo::buildString(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t size, const char *value) const
  1290. {
  1291. if (!isFixedSize())
  1292. {
  1293. builder.ensureCapacity(offset+size+1, queryName(field));
  1294. // See notes re EBCDIC conversion in RtlStringTypeInfo code
  1295. byte *dest = builder.getSelf()+offset;
  1296. if (isEbcdic())
  1297. rtlStrToEStr(size, (char *) dest, size, (char *)value);
  1298. else
  1299. memcpy(dest, value, size);
  1300. dest[size] = '\0';
  1301. offset += size+1;
  1302. }
  1303. else
  1304. {
  1305. builder.ensureCapacity(offset+length+1, queryName(field));
  1306. byte *dest = builder.getSelf()+offset;
  1307. if (isEbcdic())
  1308. rtlEStrToVStr(length+1, dest, size, value);
  1309. else
  1310. rtlStrToVStr(length+1, dest, size, value);
  1311. offset += length+1;
  1312. }
  1313. return offset;
  1314. }
  1315. size32_t RtlVarStringTypeInfo::buildUtf8(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t codepoints, const char *value) const
  1316. {
  1317. return buildUtf8ViaString(builder, offset, field, codepoints, value);
  1318. }
  1319. size32_t RtlVarStringTypeInfo::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  1320. {
  1321. const char * str = reinterpret_cast<const char *>(self);
  1322. unsigned thisLength = (size32_t)strlen(str);
  1323. unsigned thisSize;
  1324. if (isFixedSize())
  1325. thisSize = length+1;
  1326. else
  1327. thisSize = thisLength+1;
  1328. if (isEbcdic())
  1329. {
  1330. unsigned lenAscii;
  1331. rtlDataAttr ascii;
  1332. rtlEStrToStrX(lenAscii, ascii.refstr(), thisLength, str);
  1333. target.processString(lenAscii, ascii.getstr(), field);
  1334. }
  1335. else
  1336. target.processString(thisLength, str, field);
  1337. return thisSize;
  1338. }
  1339. size32_t RtlVarStringTypeInfo::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const
  1340. {
  1341. const char * str = reinterpret_cast<const char *>(self);
  1342. unsigned thisLength = (size32_t)strlen(str);
  1343. unsigned thisSize;
  1344. if (isFixedSize())
  1345. thisSize = length+1;
  1346. else
  1347. thisSize = thisLength+1;
  1348. if (isEbcdic())
  1349. {
  1350. unsigned lenAscii;
  1351. rtlDataAttr ascii;
  1352. rtlEStrToStrX(lenAscii, ascii.refstr(), thisLength, str);
  1353. target.outputString(lenAscii, ascii.getstr(), queryScalarXPath(field));
  1354. }
  1355. else
  1356. target.outputString(thisLength, str, queryScalarXPath(field));
  1357. return thisSize;
  1358. }
  1359. size32_t RtlVarStringTypeInfo::deserialize(ARowBuilder & builder, IRowDeserializerSource & in, size32_t offset) const
  1360. {
  1361. if (isFixedSize())
  1362. {
  1363. size32_t size = length+1;
  1364. byte * dest = builder.ensureCapacity(offset+size, nullptr) + offset;
  1365. in.read(size, dest);
  1366. return offset + size;
  1367. }
  1368. else
  1369. return offset + in.readVStr(builder, offset, 0);
  1370. }
  1371. void RtlVarStringTypeInfo::readAhead(IRowDeserializerSource & in) const
  1372. {
  1373. if (isFixedSize())
  1374. {
  1375. in.skip(length+1);
  1376. }
  1377. else
  1378. {
  1379. in.skipVStr();
  1380. }
  1381. }
  1382. void RtlVarStringTypeInfo::getString(size32_t & resultLen, char * & result, const void * ptr) const
  1383. {
  1384. const char * str = (const char *)ptr;
  1385. return rtlStrToStrX(resultLen, result, strlen(str), str);
  1386. }
  1387. void RtlVarStringTypeInfo::getUtf8(size32_t & resultLen, char * & result, const void * ptr) const
  1388. {
  1389. const char * str = (const char *)ptr;
  1390. return rtlStrToUtf8X(resultLen, result, strlen(str), str);
  1391. }
  1392. __int64 RtlVarStringTypeInfo::getInt(const void * ptr) const
  1393. {
  1394. const char * str = (const char *)ptr;
  1395. return rtlVStrToInt8(str);
  1396. }
  1397. int RtlVarStringTypeInfo::compare(const byte * left, const byte * right) const
  1398. {
  1399. if (isEbcdic())
  1400. {
  1401. const char * leftValue = (const char *)left;
  1402. const char * rightValue = (const char *)right;
  1403. return rtlCompareEStrEStr(strlen(leftValue), leftValue, strlen(rightValue), rightValue);
  1404. }
  1405. return rtlCompareVStrVStr((const char *)left, (const char *)right);
  1406. }
  1407. unsigned RtlVarStringTypeInfo::hash(const byte * self, unsigned inhash) const
  1408. {
  1409. return rtlHash32VStr((const char *) self, inhash);
  1410. }
  1411. bool RtlVarStringTypeInfo::canExtend(char &fillChar) const
  1412. {
  1413. if (isFixedSize())
  1414. {
  1415. fillChar = 0;
  1416. return true;
  1417. }
  1418. return false;
  1419. }
  1420. //-------------------------------------------------------------------------------------------------------------------
  1421. size32_t RtlQStringTypeInfo::getMinSize() const
  1422. {
  1423. if (isFixedSize())
  1424. return rtlQStrSize(length);
  1425. return sizeof(size32_t);
  1426. }
  1427. size32_t RtlQStringTypeInfo::size(const byte * self, const byte * selfrow) const
  1428. {
  1429. if (isFixedSize())
  1430. return rtlQStrSize(length);
  1431. return sizeof(size32_t) + rtlQStrSize(rtlReadSize32t(self));
  1432. }
  1433. size32_t RtlQStringTypeInfo::build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const
  1434. {
  1435. size32_t size;
  1436. rtlDataAttr value;
  1437. source.getStringResult(field, size, value.refstr());
  1438. return buildString(builder, offset, field, size, value.getstr());
  1439. }
  1440. size32_t RtlQStringTypeInfo::buildString(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t size, const char *value) const
  1441. {
  1442. if (!isFixedSize())
  1443. {
  1444. size32_t sizeInBytes = rtlQStrSize(size) + sizeof(size32_t);
  1445. builder.ensureCapacity(offset+sizeInBytes, queryName(field));
  1446. byte *dest = builder.getSelf()+offset;
  1447. rtlWriteInt4(dest, size);
  1448. rtlStrToQStr(size, (char *) dest+sizeof(size32_t), size, value);
  1449. offset += sizeInBytes;
  1450. }
  1451. else
  1452. {
  1453. size32_t sizeInBytes = rtlQStrSize(length);
  1454. builder.ensureCapacity(offset+sizeInBytes, queryName(field));
  1455. byte *dest = builder.getSelf()+offset;
  1456. rtlStrToQStr(length, (char *) dest, size, value);
  1457. offset += sizeInBytes;
  1458. }
  1459. return offset;
  1460. }
  1461. size32_t RtlQStringTypeInfo::buildUtf8(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t codepoints, const char *value) const
  1462. {
  1463. return buildUtf8ViaString(builder, offset, field, codepoints, value);
  1464. }
  1465. size32_t RtlQStringTypeInfo::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  1466. {
  1467. const char * str = reinterpret_cast<const char *>(self);
  1468. unsigned thisLength;
  1469. unsigned thisSize;
  1470. if (isFixedSize())
  1471. {
  1472. thisLength = length;
  1473. thisSize = rtlQStrSize(thisLength);
  1474. }
  1475. else
  1476. {
  1477. str = reinterpret_cast<const char *>(self + sizeof(size32_t));
  1478. thisLength = rtlReadSize32t(self);
  1479. thisSize = sizeof(size32_t) + rtlQStrSize(thisLength);
  1480. }
  1481. target.processQString(thisLength, str, field);
  1482. return thisSize;
  1483. }
  1484. size32_t RtlQStringTypeInfo::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const
  1485. {
  1486. const char * str = reinterpret_cast<const char *>(self);
  1487. unsigned thisLength;
  1488. unsigned thisSize;
  1489. if (isFixedSize())
  1490. {
  1491. thisLength = length;
  1492. thisSize = rtlQStrSize(thisLength);
  1493. }
  1494. else
  1495. {
  1496. str = reinterpret_cast<const char *>(self + sizeof(size32_t));
  1497. thisLength = rtlReadSize32t(self);
  1498. thisSize = sizeof(size32_t) + rtlQStrSize(thisLength);
  1499. }
  1500. target.outputQString(thisLength, str, queryScalarXPath(field));
  1501. return thisSize;
  1502. }
  1503. size32_t RtlQStringTypeInfo::deserialize(ARowBuilder & builder, IRowDeserializerSource & in, size32_t offset) const
  1504. {
  1505. if (isFixedSize())
  1506. {
  1507. size32_t size = rtlQStrSize(length);
  1508. byte * dest = builder.ensureCapacity(offset+size, nullptr) + offset;
  1509. in.read(size, dest);
  1510. offset += size;
  1511. }
  1512. else
  1513. {
  1514. size32_t thisLength = in.readSize();
  1515. size32_t size = rtlQStrSize(thisLength);
  1516. byte * dest = builder.ensureCapacity(offset+sizeof(size32_t)+size, nullptr) + offset;
  1517. rtlWriteSize32t(dest, thisLength);
  1518. in.read(size, dest + sizeof(size32_t));
  1519. offset += sizeof(size32_t)+size;
  1520. }
  1521. return offset;
  1522. }
  1523. void RtlQStringTypeInfo::readAhead(IRowDeserializerSource & in) const
  1524. {
  1525. if (isFixedSize())
  1526. {
  1527. size32_t size = rtlQStrSize(length);
  1528. in.skip(size);
  1529. }
  1530. else
  1531. {
  1532. size32_t thisLength = in.readSize();
  1533. size32_t size = rtlQStrSize(thisLength);
  1534. in.skip(size);
  1535. }
  1536. }
  1537. void RtlQStringTypeInfo::getString(size32_t & resultLen, char * & result, const void * ptr) const
  1538. {
  1539. if (isFixedSize())
  1540. {
  1541. return rtlQStrToStrX(resultLen, result, length, (const char *)ptr);
  1542. }
  1543. else
  1544. {
  1545. size32_t len = rtlReadSize32t(ptr);
  1546. return rtlQStrToStrX(resultLen, result, len, (const char *)ptr + sizeof(size32_t));
  1547. }
  1548. }
  1549. void RtlQStringTypeInfo::getUtf8(size32_t & resultLen, char * & result, const void * ptr) const
  1550. {
  1551. //NOTE: QStrings cannot contain non-string characters, so converting to str is the same as utf8
  1552. getString(resultLen, result, ptr);
  1553. }
  1554. __int64 RtlQStringTypeInfo::getInt(const void * ptr) const
  1555. {
  1556. size32_t lenTemp;
  1557. rtlDataAttr temp;
  1558. getUtf8(lenTemp, temp.refstr(), ptr);
  1559. return rtlStrToInt8(lenTemp, temp.getstr());
  1560. }
  1561. int RtlQStringTypeInfo::compare(const byte * left, const byte * right) const
  1562. {
  1563. if (isFixedSize())
  1564. // Logically this should be return rtlCompareQStrQStr(length, left, length, right);
  1565. // but that acts as a memcmp if lengths match
  1566. return memcmp(left, right, length);
  1567. size32_t lenLeft = rtlReadSize32t(left);
  1568. size32_t lenRight = rtlReadSize32t(right);
  1569. return rtlCompareQStrQStr(lenLeft, left + sizeof(size32_t), lenRight, right + sizeof(size32_t));
  1570. }
  1571. bool RtlQStringTypeInfo::canMemCmp() const
  1572. {
  1573. return isFixedSize();
  1574. }
  1575. unsigned RtlQStringTypeInfo::hash(const byte * self, unsigned inhash) const
  1576. {
  1577. rtlDataAttr val;
  1578. unsigned len;
  1579. getString(len, val.refstr(), self);
  1580. return rtlHash32Data(rtlTrimStrLen(len, val.getstr()), val.getstr(), inhash);
  1581. }
  1582. bool RtlQStringTypeInfo::canExtend(char &fillChar) const
  1583. {
  1584. if (isFixedSize())
  1585. {
  1586. fillChar = 0;
  1587. return true;
  1588. }
  1589. return false;
  1590. }
  1591. //-------------------------------------------------------------------------------------------------------------------
  1592. size32_t RtlDecimalTypeInfo::calcSize() const
  1593. {
  1594. if (isUnsigned())
  1595. return (getDecimalDigits()+1)/2;
  1596. return (getDecimalDigits()+2)/2;
  1597. }
  1598. size32_t RtlDecimalTypeInfo::getMinSize() const
  1599. {
  1600. return calcSize();
  1601. }
  1602. size32_t RtlDecimalTypeInfo::size(const byte * self, const byte * selfrow) const
  1603. {
  1604. return calcSize();
  1605. }
  1606. size32_t RtlDecimalTypeInfo::build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const
  1607. {
  1608. Decimal value;
  1609. source.getDecimalResult(field, value);
  1610. size32_t sizeInBytes = calcSize();
  1611. builder.ensureCapacity(sizeInBytes+offset, queryName(field));
  1612. if (isUnsigned())
  1613. value.getUDecimal(sizeInBytes, getDecimalPrecision(), builder.getSelf()+offset);
  1614. else
  1615. value.getDecimal(sizeInBytes, getDecimalPrecision(), builder.getSelf()+offset);
  1616. offset += sizeInBytes;
  1617. return offset;
  1618. }
  1619. size32_t RtlDecimalTypeInfo::buildNull(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field) const
  1620. {
  1621. if (field->initializer)
  1622. return RtlTypeInfoBase::buildNull(builder, offset, field);
  1623. Decimal value;
  1624. size32_t sizeInBytes = calcSize();
  1625. builder.ensureCapacity(sizeInBytes+offset, queryName(field));
  1626. if (isUnsigned())
  1627. value.getUDecimal(sizeInBytes, getDecimalPrecision(), builder.getSelf()+offset);
  1628. else
  1629. value.getDecimal(sizeInBytes, getDecimalPrecision(), builder.getSelf()+offset);
  1630. offset += sizeInBytes;
  1631. return offset;
  1632. }
  1633. size32_t RtlDecimalTypeInfo::buildString(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t len, const char *value) const
  1634. {
  1635. Decimal dvalue;
  1636. dvalue.setString(len, value);
  1637. size32_t sizeInBytes = calcSize();
  1638. builder.ensureCapacity(sizeInBytes+offset, queryName(field));
  1639. if (isUnsigned())
  1640. dvalue.getUDecimal(sizeInBytes, getDecimalPrecision(), builder.getSelf()+offset);
  1641. else
  1642. dvalue.getDecimal(sizeInBytes, getDecimalPrecision(), builder.getSelf()+offset);
  1643. offset += sizeInBytes;
  1644. return offset;
  1645. }
  1646. size32_t RtlDecimalTypeInfo::buildUtf8(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t len, const char *value) const
  1647. {
  1648. size32_t size = rtlUtf8Length(len, value);
  1649. return buildString(builder, offset, field, size, value);
  1650. }
  1651. size32_t RtlDecimalTypeInfo::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  1652. {
  1653. size32_t thisSize = calcSize();
  1654. if (isUnsigned())
  1655. target.processUDecimal(self, thisSize, getDecimalPrecision(), field);
  1656. else
  1657. target.processDecimal(self, thisSize, getDecimalPrecision(), field);
  1658. return thisSize;
  1659. }
  1660. size32_t RtlDecimalTypeInfo::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const
  1661. {
  1662. size32_t thisSize = calcSize();
  1663. if (isUnsigned())
  1664. target.outputUDecimal(self, thisSize, getDecimalPrecision(), queryScalarXPath(field));
  1665. else
  1666. target.outputDecimal(self, thisSize, getDecimalPrecision(), queryScalarXPath(field));
  1667. return thisSize;
  1668. }
  1669. void RtlDecimalTypeInfo::getString(size32_t & resultLen, char * & result, const void * ptr) const
  1670. {
  1671. Decimal temp;
  1672. size32_t sizeInBytes = calcSize();
  1673. if (isUnsigned())
  1674. temp.setUDecimal(sizeInBytes, getDecimalPrecision(), ptr);
  1675. else
  1676. temp.setDecimal(sizeInBytes, getDecimalPrecision(), ptr);
  1677. temp.getStringX(resultLen, result);
  1678. }
  1679. void RtlDecimalTypeInfo::getUtf8(size32_t & resultLen, char * & result, const void * ptr) const
  1680. {
  1681. getString(resultLen, result, ptr);
  1682. }
  1683. __int64 RtlDecimalTypeInfo::getInt(const void * ptr) const
  1684. {
  1685. Decimal temp;
  1686. size32_t sizeInBytes = calcSize();
  1687. if (isUnsigned())
  1688. temp.setUDecimal(sizeInBytes, getDecimalPrecision(), ptr);
  1689. else
  1690. temp.setDecimal(sizeInBytes, getDecimalPrecision(), ptr);
  1691. return temp.getInt64();
  1692. }
  1693. double RtlDecimalTypeInfo::getReal(const void * ptr) const
  1694. {
  1695. Decimal temp;
  1696. size32_t sizeInBytes = calcSize();
  1697. if (isUnsigned())
  1698. temp.setUDecimal(sizeInBytes, getDecimalPrecision(), ptr);
  1699. else
  1700. temp.setDecimal(sizeInBytes, getDecimalPrecision(), ptr);
  1701. return temp.getReal();
  1702. }
  1703. int RtlDecimalTypeInfo::compare(const byte * left, const byte * right) const
  1704. {
  1705. if (isUnsigned())
  1706. return decCompareUDecimal(calcSize(), left, right);
  1707. else
  1708. return decCompareDecimal(calcSize(), left, right);
  1709. }
  1710. unsigned RtlDecimalTypeInfo::hash(const byte * self, unsigned inhash) const
  1711. {
  1712. return rtlHash32Data(calcSize(), self, inhash);
  1713. }
  1714. //-------------------------------------------------------------------------------------------------------------------
  1715. size32_t RtlCharTypeInfo::build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const
  1716. {
  1717. throwUnexpected(); // Can't have a field of type char
  1718. }
  1719. size32_t RtlCharTypeInfo::buildString(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t size, const char *value) const
  1720. {
  1721. rtlFailUnexpected();
  1722. }
  1723. size32_t RtlCharTypeInfo::buildUtf8(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t len, const char *value) const
  1724. {
  1725. return buildUtf8ViaString(builder, offset, field, len, value);
  1726. }
  1727. size32_t RtlCharTypeInfo::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  1728. {
  1729. const char * str = reinterpret_cast<const char *>(self);
  1730. char c;
  1731. if (isEbcdic())
  1732. rtlEStrToStr(1, &c, 1, str);
  1733. else
  1734. c = *str;
  1735. target.processString(1, &c, field);
  1736. return 1;
  1737. }
  1738. size32_t RtlCharTypeInfo::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const
  1739. {
  1740. const char * str = reinterpret_cast<const char *>(self);
  1741. char c;
  1742. if (isEbcdic())
  1743. rtlEStrToStr(1, &c, 1, str);
  1744. else
  1745. c = *str;
  1746. target.outputString(1, &c, queryScalarXPath(field));
  1747. return 1;
  1748. }
  1749. void RtlCharTypeInfo::getString(size32_t & resultLen, char * & result, const void * ptr) const
  1750. {
  1751. const char * str = (const char *)ptr;
  1752. return rtlStrToStrX(resultLen, result, 1, str);
  1753. }
  1754. void RtlCharTypeInfo::getUtf8(size32_t & resultLen, char * & result, const void * ptr) const
  1755. {
  1756. const char * str = (const char *)ptr;
  1757. return rtlStrToUtf8X(resultLen, result, 1, str);
  1758. }
  1759. __int64 RtlCharTypeInfo::getInt(const void * ptr) const
  1760. {
  1761. const char * str = (const char *)ptr;
  1762. return rtlStrToInt8(1, str);
  1763. }
  1764. int RtlCharTypeInfo::compare(const byte * left, const byte * right) const
  1765. {
  1766. if (isEbcdic())
  1767. return rtlCompareEStrEStr(1, (const char *)left, 1, (const char *)right);
  1768. else
  1769. return rtlCompareStrStr(1, (const char *)left, 1, (const char *)right);
  1770. }
  1771. unsigned RtlCharTypeInfo::hash(const byte * self, unsigned inhash) const
  1772. {
  1773. return rtlHash32Data(1, self, inhash); // MORE - should we trim?
  1774. }
  1775. //-------------------------------------------------------------------------------------------------------------------
  1776. size32_t RtlUnicodeTypeInfo::getMinSize() const
  1777. {
  1778. if (isFixedSize())
  1779. return length * sizeof(UChar);
  1780. return sizeof(size32_t);
  1781. }
  1782. size32_t RtlUnicodeTypeInfo::size(const byte * self, const byte * selfrow) const
  1783. {
  1784. if (isFixedSize())
  1785. return length * sizeof(UChar);
  1786. return sizeof(size32_t) + rtlReadSize32t(self) * sizeof(UChar);
  1787. }
  1788. size32_t RtlUnicodeTypeInfo::build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const
  1789. {
  1790. size32_t sizeInChars;
  1791. UChar *value;
  1792. source.getUnicodeResult(field, sizeInChars, value);
  1793. if (!isFixedSize())
  1794. {
  1795. size32_t sizeInBytes = sizeInChars * sizeof(UChar);
  1796. builder.ensureCapacity(offset+sizeInBytes+sizeof(size32_t), queryName(field));
  1797. byte *dest = builder.getSelf()+offset;
  1798. rtlWriteInt4(dest, sizeInChars); // NOTE - in chars!
  1799. memcpy(dest+sizeof(size32_t), value, sizeInBytes);
  1800. offset += sizeInBytes+sizeof(size32_t);
  1801. }
  1802. else
  1803. {
  1804. size32_t sizeInBytes = length * sizeof(UChar);
  1805. builder.ensureCapacity(offset+sizeInBytes, queryName(field));
  1806. byte *dest = builder.getSelf()+offset;
  1807. rtlUnicodeToUnicode(length, (UChar *) dest, sizeInChars, value);
  1808. offset += sizeInBytes;
  1809. }
  1810. rtlFree(value);
  1811. return offset;
  1812. }
  1813. size32_t RtlUnicodeTypeInfo::buildNull(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field) const
  1814. {
  1815. if (field->initializer || !isFixedSize())
  1816. return RtlTypeInfoBase::buildNull(builder, offset, field);
  1817. else
  1818. {
  1819. size32_t sizeInBytes = length * sizeof(UChar);
  1820. builder.ensureCapacity(offset+sizeInBytes, queryName(field));
  1821. byte *dest = builder.getSelf()+offset;
  1822. rtlUnicodeToUnicode(length, (UChar *) dest, 0, nullptr);
  1823. return offset + sizeInBytes;
  1824. }
  1825. }
  1826. size32_t RtlUnicodeTypeInfo::buildUtf8(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t sizeInChars, const char *value) const
  1827. {
  1828. if (!isFixedSize())
  1829. {
  1830. size32_t sizeInBytes = sizeInChars * sizeof(UChar);
  1831. builder.ensureCapacity(offset+sizeInBytes+sizeof(size32_t), queryName(field));
  1832. byte *dest = builder.getSelf()+offset;
  1833. rtlWriteInt4(dest, sizeInChars); // NOTE - in chars!
  1834. rtlUtf8ToUnicode(sizeInChars, (UChar *) (dest+sizeof(size32_t)), sizeInChars, value);
  1835. offset += sizeInBytes+sizeof(size32_t);
  1836. }
  1837. else
  1838. {
  1839. size32_t sizeInBytes = length * sizeof(UChar);
  1840. builder.ensureCapacity(offset+sizeInBytes, queryName(field));
  1841. byte *dest = builder.getSelf()+offset;
  1842. rtlUtf8ToUnicode(length, (UChar *) dest, sizeInChars, value);
  1843. offset += sizeInBytes;
  1844. }
  1845. return offset;
  1846. }
  1847. size32_t RtlUnicodeTypeInfo::buildString(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t sizeInChars, const char *value) const
  1848. {
  1849. if (!isFixedSize())
  1850. {
  1851. size32_t sizeInBytes = sizeInChars * sizeof(UChar);
  1852. builder.ensureCapacity(offset+sizeInBytes+sizeof(size32_t), queryName(field));
  1853. byte *dest = builder.getSelf()+offset;
  1854. rtlWriteSize32t(dest, sizeInChars); // NOTE - in chars!
  1855. rtlStrToUnicode(sizeInChars, (UChar *) (dest+sizeof(size32_t)), sizeInChars, value);
  1856. offset += sizeInBytes+sizeof(size32_t);
  1857. }
  1858. else
  1859. {
  1860. size32_t sizeInBytes = length * sizeof(UChar);
  1861. builder.ensureCapacity(offset+sizeInBytes, queryName(field));
  1862. byte *dest = builder.getSelf()+offset;
  1863. rtlStrToUnicode(length, (UChar *) dest, sizeInChars, value);
  1864. offset += sizeInBytes;
  1865. }
  1866. return offset;
  1867. }
  1868. size32_t RtlUnicodeTypeInfo::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  1869. {
  1870. const UChar * ustr = reinterpret_cast<const UChar *>(self);
  1871. unsigned thisLength;
  1872. unsigned thisSize;
  1873. if (isFixedSize())
  1874. {
  1875. thisLength = length;
  1876. thisSize = thisLength * sizeof(UChar);
  1877. }
  1878. else
  1879. {
  1880. ustr = reinterpret_cast<const UChar *>(self + sizeof(size32_t));
  1881. thisLength = rtlReadSize32t(self);
  1882. thisSize = sizeof(size32_t) + thisLength * sizeof(UChar);
  1883. }
  1884. target.processUnicode(thisLength, ustr, field);
  1885. return thisSize;
  1886. }
  1887. size32_t RtlUnicodeTypeInfo::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const
  1888. {
  1889. const UChar * ustr = reinterpret_cast<const UChar *>(self);
  1890. unsigned thisLength;
  1891. unsigned thisSize;
  1892. if (isFixedSize())
  1893. {
  1894. thisLength = length;
  1895. thisSize = thisLength * sizeof(UChar);
  1896. }
  1897. else
  1898. {
  1899. ustr = reinterpret_cast<const UChar *>(self + sizeof(size32_t));
  1900. thisLength = rtlReadSize32t(self);
  1901. thisSize = sizeof(size32_t) + thisLength * sizeof(UChar);
  1902. }
  1903. target.outputUnicode(thisLength, ustr, queryScalarXPath(field));
  1904. return thisSize;
  1905. }
  1906. size32_t RtlUnicodeTypeInfo::deserialize(ARowBuilder & builder, IRowDeserializerSource & in, size32_t offset) const
  1907. {
  1908. if (isFixedSize())
  1909. {
  1910. size32_t size = length * sizeof(UChar);
  1911. byte * dest = builder.ensureCapacity(offset+size, nullptr) + offset;
  1912. in.read(size, dest);
  1913. offset += size;
  1914. }
  1915. else
  1916. {
  1917. size32_t thisLength = in.readSize();
  1918. size32_t size = thisLength * sizeof(UChar);
  1919. byte * dest = builder.ensureCapacity(offset+sizeof(size32_t)+size, nullptr) + offset;
  1920. rtlWriteSize32t(dest, thisLength);
  1921. in.read(size, dest + sizeof(size32_t));
  1922. offset += sizeof(size32_t)+size;
  1923. }
  1924. return offset;
  1925. }
  1926. void RtlUnicodeTypeInfo::readAhead(IRowDeserializerSource & in) const
  1927. {
  1928. if (isFixedSize())
  1929. {
  1930. size32_t size = length * sizeof(UChar);
  1931. in.skip(size);
  1932. }
  1933. else
  1934. {
  1935. size32_t thisLength = in.readSize();
  1936. size32_t size = thisLength * sizeof(UChar);
  1937. in.skip(size);
  1938. }
  1939. }
  1940. void RtlUnicodeTypeInfo::getString(size32_t & resultLen, char * & result, const void * ptr) const
  1941. {
  1942. if (isFixedSize())
  1943. {
  1944. return rtlUnicodeToStrX(resultLen, result, length, (const UChar *)ptr);
  1945. }
  1946. else
  1947. {
  1948. size32_t len = rtlReadSize32t(ptr);
  1949. const char * str = (const char *)ptr + sizeof(size32_t);
  1950. return rtlUnicodeToStrX(resultLen, result, len, (const UChar *)str);
  1951. }
  1952. }
  1953. void RtlUnicodeTypeInfo::getUtf8(size32_t & resultLen, char * & result, const void * ptr) const
  1954. {
  1955. if (isFixedSize())
  1956. {
  1957. return rtlUnicodeToUtf8X(resultLen, result, length, (const UChar *)ptr);
  1958. }
  1959. else
  1960. {
  1961. size32_t len = rtlReadSize32t(ptr);
  1962. const char * str = (const char *)ptr + sizeof(size32_t);
  1963. return rtlUnicodeToUtf8X(resultLen, result, len, (const UChar *)str);
  1964. }
  1965. }
  1966. __int64 RtlUnicodeTypeInfo::getInt(const void * ptr) const
  1967. {
  1968. //Utf8 output is the same as string output, so avoid the intermediate translation
  1969. if (isFixedSize())
  1970. return rtlUnicodeToInt8(length, (const UChar *)ptr);
  1971. size32_t len = rtlReadSize32t(ptr);
  1972. const char * str = (const char *)ptr + sizeof(size32_t);
  1973. return rtlUnicodeToInt8(len, (const UChar *)str);
  1974. }
  1975. int RtlUnicodeTypeInfo::compare(const byte * left, const byte * right) const
  1976. {
  1977. if (isFixedSize())
  1978. return rtlCompareUnicodeUnicode(length, (const UChar *)left, length, (const UChar *)right, locale);
  1979. size32_t lenLeft = rtlReadSize32t(left);
  1980. size32_t lenRight = rtlReadSize32t(right);
  1981. const UChar * valueLeft = reinterpret_cast<const UChar *>(left + sizeof(size32_t));
  1982. const UChar * valueRight = reinterpret_cast<const UChar *>(right + sizeof(size32_t));
  1983. return rtlCompareUnicodeUnicode(lenLeft, valueLeft, lenRight, valueRight, locale);
  1984. }
  1985. unsigned RtlUnicodeTypeInfo::hash(const byte * self, unsigned inhash) const
  1986. {
  1987. size32_t len;
  1988. if (isFixedSize())
  1989. len = length;
  1990. else
  1991. {
  1992. len = rtlReadSize32t(self);
  1993. self += sizeof(size32_t);
  1994. }
  1995. const UChar * uself = reinterpret_cast<const UChar *>(self);
  1996. return rtlHash32Unicode(rtlTrimUnicodeStrLen(len, uself), uself, inhash);
  1997. }
  1998. //-------------------------------------------------------------------------------------------------------------------
  1999. size32_t RtlVarUnicodeTypeInfo::getMinSize() const
  2000. {
  2001. if (isFixedSize())
  2002. return (length+1) * sizeof(UChar);
  2003. return sizeof(UChar);
  2004. }
  2005. size32_t RtlVarUnicodeTypeInfo::size(const byte * self, const byte * selfrow) const
  2006. {
  2007. if (isFixedSize())
  2008. return (length+1) * sizeof(UChar);
  2009. const UChar * ustr = reinterpret_cast<const UChar *>(self);
  2010. return (rtlUnicodeStrlen(ustr)+1) * sizeof(UChar);
  2011. }
  2012. size32_t RtlVarUnicodeTypeInfo::build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const
  2013. {
  2014. size32_t sizeInChars;
  2015. UChar *value;
  2016. source.getUnicodeResult(field, sizeInChars, value);
  2017. if (!isFixedSize())
  2018. {
  2019. size32_t sizeInBytes = (sizeInChars+1) * sizeof(UChar);
  2020. builder.ensureCapacity(offset+sizeInBytes, queryName(field));
  2021. UChar *dest = (UChar *) (builder.getSelf()+offset);
  2022. memcpy(dest, value, sizeInBytes - sizeof(UChar));
  2023. dest[sizeInChars] = 0;
  2024. offset += sizeInBytes;
  2025. }
  2026. else
  2027. {
  2028. size32_t sizeInBytes = (length+1) * sizeof(UChar);
  2029. builder.ensureCapacity(offset+sizeInBytes, queryName(field));
  2030. byte *dest = builder.getSelf()+offset;
  2031. rtlUnicodeToVUnicode(length+1, (UChar *) dest, sizeInChars, value);
  2032. offset += sizeInBytes;
  2033. }
  2034. rtlFree(value);
  2035. return offset;
  2036. }
  2037. size32_t RtlVarUnicodeTypeInfo::buildUtf8(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t sizeInChars, const char *value) const
  2038. {
  2039. size32_t usize;
  2040. rtlDataAttr uvalue;
  2041. rtlUtf8ToUnicodeX(usize, uvalue.refustr(), sizeInChars, value);
  2042. if (!isFixedSize())
  2043. {
  2044. size32_t sizeInBytes = (usize+1) * sizeof(UChar);
  2045. builder.ensureCapacity(offset+sizeInBytes, queryName(field));
  2046. UChar *dest = (UChar *) (builder.getSelf()+offset);
  2047. memcpy(dest, uvalue.getustr(), sizeInBytes - sizeof(UChar));
  2048. dest[usize] = 0;
  2049. offset += sizeInBytes;
  2050. }
  2051. else
  2052. {
  2053. size32_t sizeInBytes = (length+1) * sizeof(UChar);
  2054. builder.ensureCapacity(offset+sizeInBytes, queryName(field));
  2055. byte *dest = builder.getSelf()+offset;
  2056. rtlUnicodeToVUnicode(length+1, (UChar *) dest, usize, uvalue.getustr());
  2057. offset += sizeInBytes;
  2058. }
  2059. return offset;
  2060. }
  2061. size32_t RtlVarUnicodeTypeInfo::buildString(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t sizeInChars, const char *value) const
  2062. {
  2063. size32_t lengthTarget;
  2064. if (!isFixedSize())
  2065. {
  2066. lengthTarget = (sizeInChars + 1);
  2067. }
  2068. else
  2069. {
  2070. lengthTarget = (length + 1);
  2071. }
  2072. size32_t sizeTarget = lengthTarget * sizeof(UChar);
  2073. builder.ensureCapacity(offset+sizeTarget, queryName(field));
  2074. byte *dest = builder.getSelf()+offset;
  2075. rtlStrToVUnicode(lengthTarget, (UChar *) dest, sizeInChars, value);
  2076. offset += sizeTarget;
  2077. return offset;
  2078. }
  2079. size32_t RtlVarUnicodeTypeInfo::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  2080. {
  2081. const UChar * ustr = reinterpret_cast<const UChar *>(self);
  2082. unsigned thisLength = rtlUnicodeStrlen(ustr);
  2083. unsigned thisSize;
  2084. if (isFixedSize())
  2085. thisSize = (length + 1) * sizeof(UChar);
  2086. else
  2087. thisSize = (thisLength + 1) * sizeof(UChar);
  2088. target.processUnicode(thisLength, ustr, field);
  2089. return thisSize;
  2090. }
  2091. size32_t RtlVarUnicodeTypeInfo::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const
  2092. {
  2093. const UChar * ustr = reinterpret_cast<const UChar *>(self);
  2094. unsigned thisLength = rtlUnicodeStrlen(ustr);
  2095. unsigned thisSize;
  2096. if (isFixedSize())
  2097. thisSize = (length + 1) * sizeof(UChar);
  2098. else
  2099. thisSize = (thisLength + 1) * sizeof(UChar);
  2100. target.outputUnicode(thisLength, ustr, queryScalarXPath(field));
  2101. return thisSize;
  2102. }
  2103. size32_t RtlVarUnicodeTypeInfo::deserialize(ARowBuilder & builder, IRowDeserializerSource & in, size32_t offset) const
  2104. {
  2105. if (isFixedSize())
  2106. {
  2107. size32_t size = (length+1)*sizeof(UChar);
  2108. byte * dest = builder.ensureCapacity(offset+size, nullptr) + offset;
  2109. in.read(size, dest);
  2110. return offset + size;
  2111. }
  2112. else
  2113. return offset + in.readVUni(builder, offset, 0);
  2114. }
  2115. void RtlVarUnicodeTypeInfo::readAhead(IRowDeserializerSource & in) const
  2116. {
  2117. if (isFixedSize())
  2118. {
  2119. size32_t size = (length+1)*sizeof(UChar);
  2120. in.skip(size);
  2121. }
  2122. else
  2123. {
  2124. in.skipVUni();
  2125. }
  2126. }
  2127. void RtlVarUnicodeTypeInfo::getString(size32_t & resultLen, char * & result, const void * ptr) const
  2128. {
  2129. const UChar * str = (const UChar *)ptr;
  2130. rtlUnicodeToStrX(resultLen, result, rtlUnicodeStrlen(str), str);
  2131. }
  2132. void RtlVarUnicodeTypeInfo::getUtf8(size32_t & resultLen, char * & result, const void * ptr) const
  2133. {
  2134. const UChar * str = (const UChar *)ptr;
  2135. rtlUnicodeToUtf8X(resultLen, result, rtlUnicodeStrlen(str), str);
  2136. }
  2137. __int64 RtlVarUnicodeTypeInfo::getInt(const void * ptr) const
  2138. {
  2139. const UChar * str = (const UChar *)ptr;
  2140. return rtlUnicodeToInt8(rtlUnicodeStrlen(str), str);
  2141. }
  2142. int RtlVarUnicodeTypeInfo::compare(const byte * left, const byte * right) const
  2143. {
  2144. const UChar * valueLeft = reinterpret_cast<const UChar *>(left);
  2145. const UChar * valueRight = reinterpret_cast<const UChar *>(right);
  2146. size32_t lenLeft = rtlUnicodeStrlen(valueLeft);
  2147. size32_t lenRight = rtlUnicodeStrlen(valueRight);
  2148. return rtlCompareUnicodeUnicode(lenLeft, valueLeft, lenRight, valueRight, locale);
  2149. }
  2150. unsigned RtlVarUnicodeTypeInfo::hash(const byte * _self, unsigned inhash) const
  2151. {
  2152. const UChar * self = reinterpret_cast<const UChar *>(_self);
  2153. return rtlHash32VUnicode(self, inhash);
  2154. }
  2155. //-------------------------------------------------------------------------------------------------------------------
  2156. size32_t RtlUtf8TypeInfo::getMinSize() const
  2157. {
  2158. return sizeof(size32_t);
  2159. }
  2160. size32_t RtlUtf8TypeInfo::size(const byte * self, const byte * selfrow) const
  2161. {
  2162. assertex(!isFixedSize());
  2163. return sizeof(size32_t) + rtlUtf8Size(rtlReadSize32t(self), self+sizeof(unsigned));
  2164. }
  2165. size32_t RtlUtf8TypeInfo::build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const
  2166. {
  2167. size32_t sizeInChars;
  2168. rtlDataAttr value;
  2169. source.getUTF8Result(field, sizeInChars, value.refstr());
  2170. return buildUtf8(builder, offset, field, sizeInChars, value.getstr());
  2171. }
  2172. size32_t RtlUtf8TypeInfo::buildUtf8(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t sizeInChars, const char *value) const
  2173. {
  2174. size32_t sizeInBytes = rtlUtf8Size(sizeInChars, value);
  2175. assertex(!isFixedSize());
  2176. builder.ensureCapacity(offset+sizeInBytes+sizeof(size32_t), queryName(field));
  2177. byte *dest = builder.getSelf()+offset;
  2178. rtlWriteSize32t(dest, sizeInChars); // NOTE - in chars!
  2179. memcpy(dest+sizeof(size32_t), value, sizeInBytes);
  2180. return offset + sizeInBytes+sizeof(size32_t);
  2181. }
  2182. size32_t RtlUtf8TypeInfo::buildString(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t sizeInChars, const char *value) const
  2183. {
  2184. assertex(!isFixedSize());
  2185. //MORE: The target size could be precalculated - which would avoid creating a temporary
  2186. size32_t tempLen;
  2187. rtlDataAttr temp;
  2188. rtlStrToUtf8X(tempLen, temp.refstr(), sizeInChars, value);
  2189. size32_t sizeInBytes = rtlUtf8Size(tempLen, temp.getstr());
  2190. builder.ensureCapacity(offset+sizeInBytes+sizeof(size32_t), queryName(field));
  2191. byte *dest = builder.getSelf()+offset;
  2192. rtlWriteSize32t(dest, sizeInChars); // NOTE - in chars!
  2193. memcpy((dest+sizeof(size32_t)), temp.getstr(), sizeInBytes);
  2194. return offset + sizeInBytes+sizeof(size32_t);
  2195. }
  2196. size32_t RtlUtf8TypeInfo::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  2197. {
  2198. assertex(!isFixedSize());
  2199. const char * str = reinterpret_cast<const char *>(self + sizeof(size32_t));
  2200. unsigned thisLength = rtlReadSize32t(self);
  2201. unsigned thisSize = sizeof(size32_t) + rtlUtf8Size(thisLength, str);
  2202. target.processUtf8(thisLength, str, field);
  2203. return thisSize;
  2204. }
  2205. size32_t RtlUtf8TypeInfo::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const
  2206. {
  2207. assertex(!isFixedSize());
  2208. const char * str = reinterpret_cast<const char *>(self + sizeof(size32_t));
  2209. unsigned thisLength = rtlReadSize32t(self);
  2210. unsigned thisSize = sizeof(size32_t) + rtlUtf8Size(thisLength, str);
  2211. target.outputUtf8(thisLength, str, queryScalarXPath(field));
  2212. return thisSize;
  2213. }
  2214. size32_t RtlUtf8TypeInfo::deserialize(ARowBuilder & builder, IRowDeserializerSource & in, size32_t offset) const
  2215. {
  2216. assertex(!isFixedSize());
  2217. size32_t thisLength = in.readSize();
  2218. size32_t size = in.readUtf8(builder, offset + sizeof(size_t), 0, thisLength);
  2219. rtlWriteSize32t(builder.getSelf() + offset, thisLength);
  2220. return offset + sizeof(size32_t) + size;
  2221. }
  2222. void RtlUtf8TypeInfo::readAhead(IRowDeserializerSource & in) const
  2223. {
  2224. assertex(!isFixedSize());
  2225. size32_t thisLength = in.readSize();
  2226. in.skipUtf8(thisLength);
  2227. }
  2228. void RtlUtf8TypeInfo::getString(size32_t & resultLen, char * & result, const void * ptr) const
  2229. {
  2230. if (isFixedSize())
  2231. {
  2232. rtlUtf8ToStrX(resultLen, result, length, (const char *)ptr);
  2233. }
  2234. else
  2235. {
  2236. size32_t len = rtlReadSize32t(ptr);
  2237. rtlUtf8ToStrX(resultLen, result, len, (const char *)ptr + sizeof(size32_t));
  2238. }
  2239. }
  2240. void RtlUtf8TypeInfo::getUtf8(size32_t & resultLen, char * & result, const void * ptr) const
  2241. {
  2242. if (isFixedSize())
  2243. {
  2244. rtlUtf8ToUtf8X(resultLen, result, length, (const char *)ptr);
  2245. }
  2246. else
  2247. {
  2248. size32_t len = rtlReadSize32t(ptr);
  2249. rtlUtf8ToUtf8X(resultLen, result, len, (const char *)ptr + sizeof(size32_t));
  2250. }
  2251. }
  2252. __int64 RtlUtf8TypeInfo::getInt(const void * ptr) const
  2253. {
  2254. //Utf8 output is the same as string output, so avoid the intermediate translation
  2255. if (isFixedSize())
  2256. return rtlUtf8ToInt(length, (const char *)ptr);
  2257. size32_t len = rtlReadSize32t(ptr);
  2258. return rtlUtf8ToInt(len, (const char *)ptr + sizeof(size32_t));
  2259. }
  2260. int RtlUtf8TypeInfo::compare(const byte * left, const byte * right) const
  2261. {
  2262. assertex(!isFixedSize());
  2263. size32_t lenLeft = rtlReadSize32t(left);
  2264. size32_t lenRight = rtlReadSize32t(right);
  2265. const char * valueLeft = reinterpret_cast<const char *>(left) + sizeof(size32_t);
  2266. const char * valueRight = reinterpret_cast<const char *>(right) + sizeof(size32_t);
  2267. return rtlCompareUtf8Utf8(lenLeft, valueLeft, lenRight, valueRight, locale);
  2268. }
  2269. unsigned RtlUtf8TypeInfo::hash(const byte * self, unsigned inhash) const
  2270. {
  2271. assertex(!isFixedSize());
  2272. size32_t len = rtlReadSize32t(self);
  2273. const char * uself = reinterpret_cast<const char *>(self + sizeof(size32_t));
  2274. return rtlHash32Utf8(rtlTrimUtf8StrLen(len, uself), uself,inhash);
  2275. }
  2276. //-------------------------------------------------------------------------------------------------------------------
  2277. inline size32_t sizeFields(const RtlFieldInfo * const * cur, const byte * self, const byte * selfrow)
  2278. {
  2279. unsigned offset = 0;
  2280. for (;;)
  2281. {
  2282. const RtlFieldInfo * child = *cur;
  2283. if (!child)
  2284. break;
  2285. offset += child->size(self+offset, selfrow);
  2286. cur++;
  2287. }
  2288. return offset;
  2289. }
  2290. static size32_t processFields(const RtlFieldInfo * const * cur, const byte * self, const byte * selfrow, IFieldProcessor & target)
  2291. {
  2292. unsigned offset = 0;
  2293. for (;;)
  2294. {
  2295. const RtlFieldInfo * child = *cur;
  2296. if (!child)
  2297. break;
  2298. child->process(self+offset, selfrow, target);
  2299. offset += child->size(self+offset, selfrow);
  2300. cur++;
  2301. }
  2302. return offset;
  2303. }
  2304. static size32_t buildFields(const RtlFieldInfo * const * cur, ARowBuilder &builder, size32_t offset, IFieldSource &source)
  2305. {
  2306. for (;;)
  2307. {
  2308. const RtlFieldInfo * child = *cur;
  2309. if (!child)
  2310. break;
  2311. offset = child->build(builder, offset, source);
  2312. cur++;
  2313. }
  2314. return offset;
  2315. }
  2316. static size32_t toXMLFields(const RtlFieldInfo * const * cur, const byte * self, const byte * selfrow, IXmlWriter & target)
  2317. {
  2318. size32_t offset = 0;
  2319. for (;;)
  2320. {
  2321. const RtlFieldInfo * child = *cur;
  2322. if (!child)
  2323. break;
  2324. size32_t size = child->toXML(self+offset, selfrow, target);
  2325. offset += size;
  2326. cur++;
  2327. }
  2328. return offset;
  2329. }
  2330. static size32_t deserializeFields(const RtlFieldInfo * const * cur, ARowBuilder & builder, IRowDeserializerSource & in, size32_t offset)
  2331. {
  2332. for (;;)
  2333. {
  2334. const RtlFieldInfo * child = *cur;
  2335. if (!child)
  2336. break;
  2337. offset = child->type->deserialize(builder, in, offset);
  2338. cur++;
  2339. }
  2340. return offset;
  2341. }
  2342. static void readAheadFields(const RtlFieldInfo * const * cur, IRowDeserializerSource & in)
  2343. {
  2344. for (;;)
  2345. {
  2346. const RtlFieldInfo * child = *cur;
  2347. if (!child)
  2348. break;
  2349. child->type->readAhead(in);
  2350. cur++;
  2351. }
  2352. }
  2353. int ECLRTL_API compareFields(const RtlFieldInfo * const * cur, const byte * left, const byte * right, bool excludePayload)
  2354. {
  2355. size32_t leftOffset = 0;
  2356. size32_t rightOffset = 0;
  2357. for (;;)
  2358. {
  2359. const RtlFieldInfo * child = *cur;
  2360. if (!child || (excludePayload && (child->flags & RFTMispayloadfield)))
  2361. return 0;
  2362. auto type = child->type;
  2363. int rc = type->compare(left + leftOffset, right + rightOffset);
  2364. if (rc != 0)
  2365. return rc;
  2366. leftOffset += type->size(left + leftOffset, left);
  2367. rightOffset += type->size(right + rightOffset, right);
  2368. cur++;
  2369. }
  2370. }
  2371. unsigned ECLRTL_API hashFields(const RtlFieldInfo * const * cur, const byte *self, unsigned inhash, bool excludePayload)
  2372. {
  2373. size32_t offset = 0;
  2374. for (;;)
  2375. {
  2376. const RtlFieldInfo * child = *cur;
  2377. if (!child || (excludePayload && (child->flags & RFTMispayloadfield)))
  2378. break;
  2379. auto type = child->type;
  2380. inhash = type->hash(self + offset, inhash);
  2381. offset += type->size(self + offset, self);
  2382. cur++;
  2383. }
  2384. return inhash;
  2385. }
  2386. extern bool ECLRTL_API hasTrailingFileposition(const RtlFieldInfo * const * fields)
  2387. {
  2388. if (!*fields)
  2389. return false;
  2390. while (*fields)
  2391. fields++;
  2392. return (fields[-1]->type->getType() == type_filepos); // note - filepos is created as an RtlSwapIntTypeInfo with type set to type_filepos
  2393. }
  2394. extern bool ECLRTL_API hasTrailingFileposition(const RtlTypeInfo * type)
  2395. {
  2396. switch (type->getType())
  2397. {
  2398. case type_record:
  2399. {
  2400. const RtlRecordTypeInfo * record = static_cast<const RtlRecordTypeInfo *>(type);
  2401. return hasTrailingFileposition(record->fields);
  2402. }
  2403. }
  2404. return false;
  2405. }
  2406. //-------------------------------------------------------------------------------------------------------------------
  2407. size32_t RtlRecordTypeInfo::getMinSize() const
  2408. {
  2409. return ::getMinSize(fields);
  2410. }
  2411. size32_t RtlRecordTypeInfo::size(const byte * self, const byte * selfrow) const
  2412. {
  2413. return sizeFields(fields, self, self);
  2414. }
  2415. size32_t RtlRecordTypeInfo::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  2416. {
  2417. if (target.processBeginRow(field))
  2418. {
  2419. unsigned offset = processFields(fields, self, self, target);
  2420. target.processEndRow(field);
  2421. return offset;
  2422. }
  2423. return size(self, selfrow);
  2424. }
  2425. size32_t RtlRecordTypeInfo::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const
  2426. {
  2427. const char * xpath = queryXPath(field);
  2428. if (*xpath)
  2429. target.outputBeginNested(xpath, false);
  2430. unsigned thisSize = toXMLFields(fields, self, self, target);
  2431. if (*xpath)
  2432. target.outputEndNested(xpath);
  2433. return thisSize;
  2434. }
  2435. size32_t RtlRecordTypeInfo::deserialize(ARowBuilder & builder, IRowDeserializerSource & in, size32_t offset) const
  2436. {
  2437. //Will not generally be called because it will have been expanded
  2438. return deserializeFields(fields, builder, in, offset);
  2439. }
  2440. void RtlRecordTypeInfo::readAhead(IRowDeserializerSource & in) const
  2441. {
  2442. //Will not generally be called because it will have been expanded
  2443. return readAheadFields(fields, in);
  2444. }
  2445. size32_t RtlRecordTypeInfo::build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const
  2446. {
  2447. source.processBeginRow(field);
  2448. offset = buildFields(fields, builder, offset, source);
  2449. source.processEndRow(field);
  2450. return offset;
  2451. }
  2452. size32_t RtlRecordTypeInfo::buildNull(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field) const
  2453. {
  2454. const RtlFieldInfo * const * cur = fields;
  2455. for (;;)
  2456. {
  2457. const RtlFieldInfo * child = *cur;
  2458. if (!child)
  2459. break;
  2460. offset = child->type->buildNull(builder, offset, child);
  2461. cur++;
  2462. }
  2463. return offset;
  2464. }
  2465. size32_t RtlRecordTypeInfo::buildString(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t size, const char *value) const
  2466. {
  2467. throwUnexpected();
  2468. }
  2469. size32_t RtlRecordTypeInfo::buildUtf8(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t len, const char *value) const
  2470. {
  2471. throwUnexpected();
  2472. }
  2473. void RtlRecordTypeInfo::getString(size32_t & resultLen, char * & result, const void * ptr) const
  2474. {
  2475. resultLen = 0;
  2476. result = nullptr;
  2477. }
  2478. void RtlRecordTypeInfo::getUtf8(size32_t & resultLen, char * & result, const void * ptr) const
  2479. {
  2480. resultLen = 0;
  2481. result = nullptr;
  2482. }
  2483. __int64 RtlRecordTypeInfo::getInt(const void * ptr) const
  2484. {
  2485. return 0;
  2486. }
  2487. int RtlRecordTypeInfo::compare(const byte * left, const byte * right) const
  2488. {
  2489. return compareFields(fields, left, right);
  2490. }
  2491. unsigned RtlRecordTypeInfo::hash(const byte * self, unsigned inhash) const
  2492. {
  2493. return hashFields(fields, self, inhash);
  2494. }
  2495. //-------------------------------------------------------------------------------------------------------------------
  2496. size32_t RtlCompoundTypeInfo::buildString(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t size, const char *value) const
  2497. {
  2498. UNIMPLEMENTED;
  2499. }
  2500. size32_t RtlCompoundTypeInfo::buildUtf8(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t len, const char *value) const
  2501. {
  2502. UNIMPLEMENTED;
  2503. }
  2504. void RtlCompoundTypeInfo::getString(size32_t & resultLen, char * & result, const void * ptr) const
  2505. {
  2506. //MORE: Should this fail instead?
  2507. resultLen = 0;
  2508. result = nullptr;
  2509. }
  2510. void RtlCompoundTypeInfo::getUtf8(size32_t & resultLen, char * & result, const void * ptr) const
  2511. {
  2512. //MORE: Should this fail instead?
  2513. resultLen = 0;
  2514. result = nullptr;
  2515. }
  2516. __int64 RtlCompoundTypeInfo::getInt(const void * ptr) const
  2517. {
  2518. //MORE: Should this fail instead?
  2519. return 0;
  2520. }
  2521. //-------------------------------------------------------------------------------------------------------------------
  2522. size32_t RtlSetTypeInfo::getMinSize() const
  2523. {
  2524. return sizeof(bool) + sizeof(size32_t);
  2525. }
  2526. size32_t RtlSetTypeInfo::size(const byte * self, const byte * selfrow) const
  2527. {
  2528. return sizeof(bool) + sizeof(size32_t) + rtlReadSize32t(self + sizeof(bool));
  2529. }
  2530. size32_t RtlSetTypeInfo::build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const
  2531. {
  2532. bool isAll;
  2533. source.processBeginSet(field, isAll);
  2534. size32_t sizeInBytes = sizeof(bool) + sizeof(size32_t);
  2535. builder.ensureCapacity(offset+sizeInBytes, queryName(field));
  2536. byte *dest = builder.getSelf()+offset;
  2537. if (isAll)
  2538. {
  2539. * (bool *) dest = true;
  2540. rtlWriteInt4(dest+1, 0);
  2541. offset += sizeInBytes;
  2542. }
  2543. else
  2544. {
  2545. * (bool *) dest = false;
  2546. size32_t newOffset = offset + sizeInBytes;
  2547. RtlFieldStrInfo dummyField("<set element>", NULL, child);
  2548. while (source.processNextSet(field))
  2549. {
  2550. newOffset = child->build(builder, newOffset, &dummyField, source);
  2551. }
  2552. // Go back in and patch the size, remembering it may have moved
  2553. rtlWriteInt4(builder.getSelf()+offset+1, newOffset - (offset+sizeInBytes));
  2554. offset = newOffset;
  2555. }
  2556. source.processEndSet(field);
  2557. return offset;
  2558. }
  2559. size32_t RtlSetTypeInfo::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  2560. {
  2561. unsigned offset = sizeof(bool) + sizeof(size32_t);
  2562. unsigned max = offset + rtlReadSize32t(self + sizeof(bool));
  2563. unsigned elements = 0;
  2564. if (!*(bool *)self)
  2565. {
  2566. unsigned tempOffset = sizeof(bool) + sizeof(size32_t);
  2567. if (child->isFixedSize())
  2568. {
  2569. unsigned elemSize = child->size(NULL, NULL);
  2570. elements = (max-offset) / elemSize;
  2571. assert(elements*elemSize == max-offset);
  2572. }
  2573. else
  2574. {
  2575. DummyFieldProcessor dummy;
  2576. while (tempOffset < max)
  2577. {
  2578. tempOffset += child->process(self+tempOffset, selfrow, field, dummy); // NOTE - good thing we can't have a set of sets, or this would recurse
  2579. elements++;
  2580. }
  2581. }
  2582. }
  2583. if (target.processBeginSet(field, elements, *(bool *)self, self+offset))
  2584. {
  2585. while (offset < max)
  2586. {
  2587. offset += child->process(self+offset, selfrow, field, target);
  2588. }
  2589. }
  2590. target.processEndSet(field);
  2591. return max;
  2592. }
  2593. size32_t RtlSetTypeInfo::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const
  2594. {
  2595. unsigned offset = sizeof(bool) + sizeof(size32_t);
  2596. unsigned max = offset + rtlReadSize32t(self + sizeof(bool));
  2597. StringAttr outerTag;
  2598. if (hasOuterXPath(field))
  2599. {
  2600. queryNestedOuterXPath(outerTag, field);
  2601. target.outputBeginNested(outerTag, false);
  2602. }
  2603. if (*(bool *)self)
  2604. target.outputSetAll();
  2605. else
  2606. {
  2607. const char *innerPath = queryXPath(field);
  2608. target.outputBeginArray(innerPath);
  2609. while (offset < max)
  2610. {
  2611. child->toXML(self+offset, selfrow, field, target);
  2612. offset += child->size(self+offset, selfrow);
  2613. }
  2614. target.outputEndArray(innerPath);
  2615. }
  2616. if (outerTag)
  2617. target.outputEndNested(outerTag);
  2618. return max;
  2619. }
  2620. size32_t RtlSetTypeInfo::deserialize(ARowBuilder & builder, IRowDeserializerSource & in, size32_t offset) const
  2621. {
  2622. bool isAll;
  2623. in.read(1, &isAll);
  2624. size32_t size = in.readSize();
  2625. byte * dest = builder.ensureCapacity(offset+sizeof(bool)+sizeof(size32_t)+size, nullptr) + offset;
  2626. *dest = isAll;
  2627. rtlWriteSize32t(dest + sizeof(bool), size);
  2628. in.read(size, dest + sizeof(bool) + sizeof(size32_t));
  2629. return offset+sizeof(bool)+sizeof(size32_t)+size;
  2630. }
  2631. void RtlSetTypeInfo::readAhead(IRowDeserializerSource & in) const
  2632. {
  2633. in.skip(1);
  2634. size32_t thisLength = in.readSize();
  2635. in.skip(thisLength);
  2636. }
  2637. int RtlSetTypeInfo::compare(const byte * left, const byte * right) const
  2638. {
  2639. const bool allLeft = *(const bool *)left;
  2640. const bool allRight = *(const bool *)right;
  2641. if (allLeft || allRight)
  2642. {
  2643. if (allLeft && allRight)
  2644. return 0;
  2645. if (allLeft)
  2646. return +1;
  2647. else
  2648. return -1;
  2649. }
  2650. size32_t sizeLeft = rtlReadSize32t(left + sizeof(bool));
  2651. const byte * ptrLeft = left + sizeof(bool) + sizeof(size32_t);
  2652. size32_t sizeRight = rtlReadSize32t(right + sizeof(bool));
  2653. const byte * ptrRight = right + sizeof(bool) + sizeof(size32_t);
  2654. size32_t offLeft = 0;
  2655. size32_t offRight = 0;
  2656. for (;;)
  2657. {
  2658. if ((offLeft == sizeLeft) || (offRight == sizeRight))
  2659. {
  2660. if ((offLeft == sizeLeft) && (offRight == sizeRight))
  2661. return 0;
  2662. if (offLeft == sizeLeft)
  2663. return -1;
  2664. else
  2665. return +1;
  2666. }
  2667. int rc = child->compare(ptrLeft + offLeft, ptrRight + offRight);
  2668. if (rc != 0)
  2669. return rc;
  2670. offLeft += child->size(ptrLeft + offLeft, ptrLeft + offLeft);
  2671. offRight += child->size(ptrRight + offRight, ptrRight + offRight);
  2672. }
  2673. }
  2674. unsigned RtlSetTypeInfo::hash(const byte * self, unsigned inhash) const
  2675. {
  2676. const bool allLeft = *(const bool *) self;
  2677. self += sizeof(bool);
  2678. if (allLeft)
  2679. {
  2680. // Nothing - this is unfortunate as it means hash(all) and hash([]) are the same...
  2681. // But it matches generated code
  2682. }
  2683. else
  2684. {
  2685. size32_t size = rtlReadSize32t(self);
  2686. self += sizeof(size32_t);
  2687. #if 0
  2688. // This might be the smart way to hash - since it means that the hash depends on the value, not the type,
  2689. // and that things that compare equal will hash equal. But that is not what the code generator does
  2690. for (size32_t offset = 0; offset < size; offset += child->size(self + offset, self + offset))
  2691. {
  2692. inhash = child->hash(self + offset, inhash);
  2693. }
  2694. #else
  2695. inhash = rtlHash32Data(size, self, inhash);
  2696. #endif
  2697. }
  2698. return inhash;
  2699. }
  2700. //-------------------------------------------------------------------------------------------------------------------
  2701. size32_t RtlRowTypeInfo::getMinSize() const
  2702. {
  2703. if (isLinkCounted())
  2704. return sizeof(void *);
  2705. return child->getMinSize();
  2706. }
  2707. size32_t RtlRowTypeInfo::size(const byte * self, const byte * selfrow) const
  2708. {
  2709. if (isLinkCounted())
  2710. return sizeof(void *);
  2711. return child->size(self, selfrow);
  2712. }
  2713. size32_t RtlRowTypeInfo::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  2714. {
  2715. if (isLinkCounted())
  2716. {
  2717. const byte * row = *(const byte * *)self;
  2718. if (row)
  2719. child->process(row, row, field, target);
  2720. return sizeof(row);
  2721. }
  2722. return child->process(self, self, field, target);
  2723. }
  2724. size32_t RtlRowTypeInfo::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const
  2725. {
  2726. if (isLinkCounted())
  2727. {
  2728. const byte * row = *(const byte * *)self;
  2729. child->toXML(row, row, field, target);
  2730. return sizeof(row);
  2731. }
  2732. return child->toXML(self, self, field, target);
  2733. }
  2734. size32_t RtlRowTypeInfo::deserialize(ARowBuilder & builder, IRowDeserializerSource & in, size32_t offset) const
  2735. {
  2736. //Link counted isn't yet implemented in the code generator
  2737. if (isLinkCounted())
  2738. UNIMPLEMENTED;
  2739. return child->deserialize(builder, in, offset);
  2740. }
  2741. void RtlRowTypeInfo::readAhead(IRowDeserializerSource & in) const
  2742. {
  2743. return child->readAhead(in);
  2744. }
  2745. int RtlRowTypeInfo::compare(const byte * left, const byte * right) const
  2746. {
  2747. if (isLinkCounted())
  2748. {
  2749. const byte * leftRow = *(const byte * *)left;
  2750. const byte * rightRow = *(const byte * *)right;
  2751. if (leftRow && rightRow)
  2752. return child->compare(leftRow, rightRow);
  2753. if (leftRow)
  2754. return +1;
  2755. if (rightRow)
  2756. return -1;
  2757. return 0;
  2758. }
  2759. return child->compare(left, right);
  2760. }
  2761. unsigned RtlRowTypeInfo::hash(const byte * self, unsigned inhash) const
  2762. {
  2763. if (isLinkCounted())
  2764. {
  2765. const byte * selfRow = *(const byte * *)self;
  2766. if (selfRow)
  2767. inhash = child->hash(selfRow, inhash);
  2768. return inhash;
  2769. }
  2770. return child->hash(self, inhash);
  2771. }
  2772. //-------------------------------------------------------------------------------------------------------------------
  2773. size32_t RtlDatasetTypeInfo::getMinSize() const
  2774. {
  2775. if (isLinkCounted())
  2776. return sizeof(size32_t) + sizeof(void * *);
  2777. return sizeof(size32_t);
  2778. }
  2779. size32_t RtlDatasetTypeInfo::size(const byte * self, const byte * selfrow) const
  2780. {
  2781. if (isLinkCounted())
  2782. return sizeof(size32_t) + sizeof(void * *);
  2783. return sizeof(size32_t) + rtlReadSize32t(self);
  2784. }
  2785. size32_t RtlDatasetTypeInfo::build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const
  2786. {
  2787. source.processBeginDataset(field);
  2788. if (isLinkCounted())
  2789. {
  2790. // a 32-bit record count, and a pointer to an array of record pointers
  2791. size32_t sizeInBytes = sizeof(size32_t) + sizeof(void *);
  2792. builder.ensureCapacity(offset+sizeInBytes, queryName(field));
  2793. size32_t numRows = 0;
  2794. Owned<IEngineRowAllocator> childAllocator = builder.queryAllocator()->createChildRowAllocator(child);
  2795. const byte **childRows = NULL;
  2796. RtlFieldStrInfo dummyField("<nested row>", NULL, child);
  2797. while (source.processNextRow(field))
  2798. {
  2799. RtlDynamicRowBuilder childBuilder(*childAllocator);
  2800. size32_t childLen = child->build(childBuilder, 0, &dummyField, source);
  2801. childRows = childAllocator->appendRowOwn(childRows, ++numRows, (void *) childBuilder.finalizeRowClear(childLen));
  2802. }
  2803. // Go back in and patch the count, remembering it may have moved
  2804. rtlWriteInt4(builder.getSelf()+offset, numRows);
  2805. * ( const void * * ) (builder.getSelf()+offset+sizeof(size32_t)) = childRows;
  2806. offset += sizeInBytes;
  2807. }
  2808. else
  2809. {
  2810. // a 32-bit size, then rows inline
  2811. size32_t sizeInBytes = sizeof(size32_t);
  2812. builder.ensureCapacity(offset+sizeInBytes, queryName(field));
  2813. size32_t newOffset = offset + sizeInBytes;
  2814. RtlFieldStrInfo dummyField("<nested row>", NULL, child);
  2815. while (source.processNextRow(field))
  2816. newOffset = child->build(builder, newOffset, &dummyField, source);
  2817. // Go back in and patch the size, remembering it may have moved
  2818. rtlWriteInt4(builder.getSelf()+offset, newOffset - (offset+sizeInBytes));
  2819. offset = newOffset;
  2820. }
  2821. source.processEndDataset(field);
  2822. return offset;
  2823. }
  2824. size32_t RtlDatasetTypeInfo::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  2825. {
  2826. if (isLinkCounted())
  2827. {
  2828. size32_t thisCount = rtlReadSize32t(self);
  2829. if (target.processBeginDataset(field, thisCount))
  2830. {
  2831. const byte * * rows = *reinterpret_cast<const byte * * const *>(self + sizeof(size32_t));
  2832. for (unsigned i= 0; i < thisCount; i++)
  2833. {
  2834. const byte * row = rows[i];
  2835. child->process(row, row, field, target);
  2836. }
  2837. target.processEndDataset(field);
  2838. }
  2839. return sizeof(size32_t) + sizeof(void * *);
  2840. }
  2841. else
  2842. {
  2843. unsigned offset = sizeof(size32_t);
  2844. unsigned max = offset + rtlReadSize32t(self);
  2845. unsigned thisCount = 0;
  2846. DummyFieldProcessor dummy;
  2847. while (offset < max)
  2848. {
  2849. offset += child->process(self+offset, self+offset, field, dummy);
  2850. thisCount++;
  2851. }
  2852. offset = sizeof(size32_t);
  2853. if (target.processBeginDataset(field, thisCount))
  2854. {
  2855. while (offset < max)
  2856. {
  2857. offset += child->process(self+offset, self+offset, field, target);
  2858. }
  2859. target.processEndDataset(field);
  2860. }
  2861. return max;
  2862. }
  2863. }
  2864. size32_t RtlDatasetTypeInfo::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const
  2865. {
  2866. StringAttr outerTag;
  2867. if (hasOuterXPath(field))
  2868. {
  2869. queryNestedOuterXPath(outerTag, field);
  2870. target.outputBeginNested(outerTag, false);
  2871. }
  2872. const char *innerPath = queryXPath(field);
  2873. target.outputBeginArray(innerPath);
  2874. unsigned thisSize;
  2875. if (isLinkCounted())
  2876. {
  2877. size32_t thisCount = rtlReadSize32t(self);
  2878. const byte * * rows = *reinterpret_cast<const byte * * const *>(self + sizeof(size32_t));
  2879. for (unsigned i= 0; i < thisCount; i++)
  2880. {
  2881. const byte * row = rows[i];
  2882. if (row)
  2883. child->toXML(row, row, field, target);
  2884. }
  2885. thisSize = sizeof(size32_t) + sizeof(void * *);
  2886. }
  2887. else
  2888. {
  2889. unsigned offset = sizeof(size32_t);
  2890. unsigned max = offset + rtlReadSize32t(self);
  2891. while (offset < max)
  2892. {
  2893. child->toXML(self+offset, self+offset, field, target);
  2894. offset += child->size(self+offset, self+offset);
  2895. }
  2896. thisSize = max;
  2897. }
  2898. target.outputEndArray(innerPath);
  2899. if (outerTag)
  2900. target.outputEndNested(outerTag);
  2901. return thisSize;
  2902. }
  2903. size32_t RtlDatasetTypeInfo::deserialize(ARowBuilder & builder, IRowDeserializerSource & in, size32_t offset) const
  2904. {
  2905. const bool canUseMemcpy = true;
  2906. if (canUseMemcpy && !isLinkCounted())
  2907. {
  2908. size32_t size = in.readSize();
  2909. byte * dest = builder.ensureCapacity(offset+sizeof(size32_t)+size, nullptr) + offset;
  2910. rtlWriteSize32t(dest, size);
  2911. in.read(size, dest + sizeof(size32_t));
  2912. return offset + sizeof(size32_t) + size;
  2913. }
  2914. else
  2915. {
  2916. if (isLinkCounted())
  2917. {
  2918. //Currently inefficient because it is recreating deserializers and resolving child allocators each time it is called.
  2919. ICodeContext * ctx = nullptr; // Slightly dodgy, but not needed if the child deserializers are also calculated
  2920. unsigned activityId = 0;
  2921. // a 32-bit record count, and a pointer to an hash table with record pointers
  2922. size32_t sizeInBytes = sizeof(size32_t) + sizeof(void *);
  2923. byte * dest = builder.ensureCapacity(offset+sizeInBytes, nullptr) + offset;
  2924. Owned<IEngineRowAllocator> childAllocator = builder.queryAllocator()->createChildRowAllocator(child);
  2925. Owned<IOutputRowDeserializer> deserializer = childAllocator->queryOutputMeta()->createDiskDeserializer(ctx, activityId);
  2926. rtlDeserializeChildRowset(*(size32_t *)dest, *(const byte * * *)(dest + sizeof(size32_t)), childAllocator, deserializer, in);
  2927. return offset + sizeInBytes;
  2928. }
  2929. else
  2930. {
  2931. size32_t startOffset = offset + sizeof(size32_t);
  2932. size32_t nextOffset = startOffset;
  2933. offset_t endOffset = in.beginNested();
  2934. while (in.finishedNested(endOffset))
  2935. nextOffset = child->deserialize(builder, in, nextOffset);
  2936. rtlWriteSize32t(builder.getSelf() + offset, nextOffset - startOffset);
  2937. return nextOffset;
  2938. }
  2939. }
  2940. }
  2941. void RtlDatasetTypeInfo::readAhead(IRowDeserializerSource & in) const
  2942. {
  2943. size32_t size = in.readSize();
  2944. in.skip(size);
  2945. }
  2946. int RtlDatasetTypeInfo::compare(const byte * left, const byte * right) const
  2947. {
  2948. if (isLinkCounted())
  2949. {
  2950. const size32_t countLeft = rtlReadSize32t(left);
  2951. const size32_t countRight = rtlReadSize32t(right);
  2952. const byte * * rowsLeft = (const byte * *)((const byte *)left + sizeof(size32_t));
  2953. const byte * * rowsRight = (const byte * *)((const byte *)right + sizeof(size32_t));
  2954. size32_t row = 0;
  2955. for (;;)
  2956. {
  2957. if ((row == countLeft) || (row == countRight))
  2958. {
  2959. if (countLeft == countRight)
  2960. return 0;
  2961. if (row == countLeft)
  2962. return -1;
  2963. else
  2964. return +1;
  2965. }
  2966. int rc = child->compare(rowsLeft[row], rowsRight[row]);
  2967. if (rc != 0)
  2968. return rc;
  2969. row++;
  2970. }
  2971. }
  2972. size32_t lenLeft = rtlReadSize32t(left);
  2973. size32_t lenRight = rtlReadSize32t(right);
  2974. const byte * ptrLeft = left + sizeof(size32_t);
  2975. const byte * ptrRight = right + sizeof(size32_t);
  2976. size32_t offLeft = 0;
  2977. size32_t offRight = 0;
  2978. for (;;)
  2979. {
  2980. if ((offLeft == lenLeft) || (offRight == lenRight))
  2981. {
  2982. if ((offLeft == lenLeft) && (offRight == lenRight))
  2983. return 0;
  2984. if (offLeft == lenLeft)
  2985. return -1;
  2986. else
  2987. return +1;
  2988. }
  2989. int rc = child->compare(ptrLeft + offLeft, ptrRight + offRight);
  2990. if (rc != 0)
  2991. return rc;
  2992. offLeft += child->size(ptrLeft + offLeft, ptrLeft + offLeft);
  2993. offRight += child->size(ptrRight + offRight, ptrRight + offRight);
  2994. }
  2995. }
  2996. unsigned RtlDatasetTypeInfo::hash(const byte * self, unsigned inhash) const
  2997. {
  2998. if (isLinkCounted())
  2999. {
  3000. const size32_t count = rtlReadSize32t(self);
  3001. self += sizeof(size32_t);
  3002. const byte * * rows = (const byte * *) self;
  3003. for (size32_t row = 0; row < count; row++)
  3004. {
  3005. inhash = child->hash(rows[row], inhash);
  3006. row++;
  3007. }
  3008. }
  3009. else
  3010. {
  3011. size32_t len = rtlReadSize32t(self);
  3012. self += sizeof(size32_t);
  3013. for (size32_t offset = 0; offset < len; offset += child->size(self + offset, self + offset))
  3014. {
  3015. inhash = child->hash(self + offset, inhash);
  3016. }
  3017. }
  3018. return inhash;
  3019. }
  3020. //-------------------------------------------------------------------------------------------------------------------
  3021. size32_t RtlDictionaryTypeInfo::getMinSize() const
  3022. {
  3023. if (isLinkCounted())
  3024. return sizeof(size32_t) + sizeof(void * *);
  3025. return sizeof(size32_t);
  3026. }
  3027. size32_t RtlDictionaryTypeInfo::size(const byte * self, const byte * selfrow) const
  3028. {
  3029. if (isLinkCounted())
  3030. return sizeof(size32_t) + sizeof(void * *);
  3031. return sizeof(size32_t) + rtlReadSize32t(self);
  3032. }
  3033. size32_t RtlDictionaryTypeInfo::build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const
  3034. {
  3035. source.processBeginDataset(field);
  3036. if (isLinkCounted())
  3037. {
  3038. // a 32-bit record count, and a pointer to an hash table with record pointers
  3039. size32_t sizeInBytes = sizeof(size32_t) + sizeof(void *);
  3040. builder.ensureCapacity(offset+sizeInBytes, queryName(field));
  3041. Owned<IEngineRowAllocator> childAllocator = builder.queryAllocator()->createChildRowAllocator(child);
  3042. CHThorHashLookupInfo hashInfo(*static_cast<const RtlRecordTypeInfo *>(child));
  3043. RtlLinkedDictionaryBuilder dictBuilder(childAllocator, &hashInfo);
  3044. RtlFieldStrInfo dummyField("<nested row>", NULL, child);
  3045. while (source.processNextRow(field))
  3046. {
  3047. RtlDynamicRowBuilder childBuilder(childAllocator);
  3048. size32_t childLen = child->build(childBuilder, 0, &dummyField, source);
  3049. dictBuilder.appendOwn((void *) childBuilder.finalizeRowClear(childLen));
  3050. }
  3051. // Go back in and patch the count
  3052. rtlWriteInt4(builder.getSelf()+offset, dictBuilder.getcount());
  3053. * ( const void * * ) (builder.getSelf()+offset+sizeof(size32_t)) = dictBuilder.linkrows();
  3054. offset += sizeInBytes;
  3055. }
  3056. else
  3057. throwUnexpected(); // And may never be...
  3058. source.processEndDataset(field);
  3059. return offset;
  3060. }
  3061. size32_t RtlDictionaryTypeInfo::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  3062. {
  3063. if (isLinkCounted())
  3064. {
  3065. size32_t thisCount = rtlReadSize32t(self);
  3066. if (target.processBeginDataset(field, thisCount))
  3067. {
  3068. const byte * * rows = *reinterpret_cast<const byte * * const *>(self + sizeof(size32_t));
  3069. for (unsigned i= 0; i < thisCount; i++)
  3070. {
  3071. const byte * row = rows[i];
  3072. if (row)
  3073. child->process(row, row, field, target);
  3074. }
  3075. target.processEndDataset(field);
  3076. }
  3077. return sizeof(size32_t) + sizeof(void * *);
  3078. }
  3079. else
  3080. {
  3081. //MORE: We could interpret serialized dictionaries if there was ever a need
  3082. throwUnexpected();
  3083. }
  3084. }
  3085. size32_t RtlDictionaryTypeInfo::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const
  3086. {
  3087. StringAttr outerTag;
  3088. if (hasOuterXPath(field))
  3089. {
  3090. queryNestedOuterXPath(outerTag, field);
  3091. target.outputBeginNested(outerTag, false);
  3092. }
  3093. const char *innerPath = queryXPath(field);
  3094. target.outputBeginArray(innerPath);
  3095. unsigned thisSize;
  3096. if (isLinkCounted())
  3097. {
  3098. size32_t thisCount = rtlReadSize32t(self);
  3099. const byte * * rows = *reinterpret_cast<const byte * * const *>(self + sizeof(size32_t));
  3100. for (unsigned i= 0; i < thisCount; i++)
  3101. {
  3102. const byte * row = rows[i];
  3103. if (row)
  3104. child->toXML(row, row, field, target);
  3105. }
  3106. thisSize = sizeof(size32_t) + sizeof(void * *);
  3107. }
  3108. else
  3109. {
  3110. //MORE: We could interpret serialized dictionaries if there was ever a need
  3111. throwUnexpected();
  3112. }
  3113. target.outputEndArray(innerPath);
  3114. if (outerTag)
  3115. target.outputEndNested(outerTag);
  3116. return thisSize;
  3117. }
  3118. size32_t RtlDictionaryTypeInfo::deserialize(ARowBuilder & builder, IRowDeserializerSource & in, size32_t offset) const
  3119. {
  3120. if (isLinkCounted())
  3121. {
  3122. //Currently inefficient because it is recreating deserializers and resolving child allocators each time it is called.
  3123. ICodeContext * ctx = nullptr; // Slightly dodgy, but not needed if the child deserializers are also calculated
  3124. unsigned activityId = 0;
  3125. // a 32-bit record count, and a pointer to an hash table with record pointers
  3126. size32_t sizeInBytes = sizeof(size32_t) + sizeof(void *);
  3127. byte * dest = builder.ensureCapacity(offset + sizeInBytes, nullptr) + offset;
  3128. Owned<IEngineRowAllocator> childAllocator = builder.queryAllocator()->createChildRowAllocator(child);
  3129. Owned<IOutputRowDeserializer> deserializer = childAllocator->queryOutputMeta()->createDiskDeserializer(ctx, activityId);
  3130. rtlDeserializeChildDictionary(*(size32_t *)dest, *(const byte * * *)(dest + sizeof(size32_t)), childAllocator, deserializer, in);
  3131. return offset + sizeInBytes;
  3132. }
  3133. else
  3134. {
  3135. UNIMPLEMENTED;
  3136. }
  3137. }
  3138. void RtlDictionaryTypeInfo::readAhead(IRowDeserializerSource & in) const
  3139. {
  3140. size32_t size = in.readSize();
  3141. in.skip(size);
  3142. }
  3143. int RtlDictionaryTypeInfo::compare(const byte * left, const byte * right) const
  3144. {
  3145. if (isLinkCounted())
  3146. {
  3147. const size32_t countLeft = rtlReadSize32t(left);
  3148. const size32_t countRight = rtlReadSize32t(right);
  3149. const byte * * rowsLeft = (const byte * *)((const byte *)left + sizeof(size32_t));
  3150. const byte * * rowsRight = (const byte * *)((const byte *)right + sizeof(size32_t));
  3151. size32_t leftRow = 0;
  3152. size32_t rightRow = 0;
  3153. for (;;)
  3154. {
  3155. //Dictionaries are compared as datasets => skip until the first non-null entry
  3156. while ((leftRow != countLeft) && !rowsLeft[leftRow])
  3157. leftRow++;
  3158. while ((rightRow != countRight) && !rowsRight[rightRow])
  3159. rightRow++;
  3160. if ((leftRow == countLeft) || (rightRow == countRight))
  3161. {
  3162. if ((leftRow == countLeft) && (rightRow == countRight))
  3163. return 0;
  3164. if (leftRow == countLeft)
  3165. return -1;
  3166. else
  3167. return +1;
  3168. }
  3169. int rc = child->compare(rowsLeft[leftRow], rowsRight[rightRow]);
  3170. if (rc != 0)
  3171. return rc;
  3172. leftRow++;
  3173. rightRow++;
  3174. }
  3175. }
  3176. else
  3177. {
  3178. //Non LCR dictionaries are not supported.
  3179. throwUnexpected();
  3180. }
  3181. }
  3182. unsigned RtlDictionaryTypeInfo::hash(const byte * self, unsigned inhash) const
  3183. {
  3184. if (isLinkCounted())
  3185. {
  3186. const size32_t count = rtlReadSize32t(self);
  3187. self += sizeof(size32_t);
  3188. const byte * * rows = (const byte * *) self;
  3189. size32_t row = 0;
  3190. for (;;)
  3191. {
  3192. //Dictionaries are compared as datasets => skip until the first non-null entry
  3193. while ((row != count) && !rows[row])
  3194. row++;
  3195. if (row == count)
  3196. break;
  3197. inhash = child->hash(rows[row], inhash);
  3198. row++;
  3199. }
  3200. }
  3201. else
  3202. {
  3203. //Non LCR dictionaries are not supported.
  3204. throwUnexpected();
  3205. }
  3206. return inhash;
  3207. }
  3208. //-------------------------------------------------------------------------------------------------------------------
  3209. size32_t RtlIfBlockTypeInfo::getMinSize() const
  3210. {
  3211. return 0;
  3212. }
  3213. size32_t RtlIfBlockTypeInfo::size(const byte * self, const byte * selfrow) const
  3214. {
  3215. if (getCondition(selfrow))
  3216. return sizeFields(fields, self, selfrow);
  3217. return 0;
  3218. }
  3219. size32_t RtlIfBlockTypeInfo::buildString(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t size, const char *value) const
  3220. {
  3221. throwUnexpected();
  3222. }
  3223. size32_t RtlIfBlockTypeInfo::buildUtf8(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t len, const char *value) const
  3224. {
  3225. throwUnexpected();
  3226. }
  3227. size32_t RtlIfBlockTypeInfo::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  3228. {
  3229. if (getCondition(selfrow))
  3230. return processFields(fields, self, selfrow, target);
  3231. return 0;
  3232. }
  3233. size32_t RtlIfBlockTypeInfo::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const
  3234. {
  3235. if (getCondition(selfrow))
  3236. return toXMLFields(fields, self, selfrow, target);
  3237. return 0;
  3238. }
  3239. size32_t RtlIfBlockTypeInfo::deserialize(ARowBuilder & builder, IRowDeserializerSource & in, size32_t offset) const
  3240. {
  3241. if (getCondition(builder.getSelf()))
  3242. return deserializeFields(fields, builder, in, offset);
  3243. return offset;
  3244. }
  3245. void RtlIfBlockTypeInfo::readAhead(IRowDeserializerSource & in) const
  3246. {
  3247. UNIMPLEMENTED;
  3248. }
  3249. void RtlIfBlockTypeInfo::getString(size32_t & resultLen, char * & result, const void * ptr) const
  3250. {
  3251. //MORE: Should this fail instead?
  3252. resultLen = 0;
  3253. result = nullptr;
  3254. }
  3255. void RtlIfBlockTypeInfo::getUtf8(size32_t & resultLen, char * & result, const void * ptr) const
  3256. {
  3257. //MORE: Should this fail instead?
  3258. resultLen = 0;
  3259. result = nullptr;
  3260. }
  3261. __int64 RtlIfBlockTypeInfo::getInt(const void * ptr) const
  3262. {
  3263. //MORE: Should this fail instead?
  3264. return 0;
  3265. }
  3266. int RtlIfBlockTypeInfo::compare(const byte * left, const byte * right) const
  3267. {
  3268. bool includeLeft = getCondition(left);
  3269. bool includeRight = getCondition(right);
  3270. if (includeLeft && includeRight)
  3271. return compareFields(fields, left, right);
  3272. //If the fields are all blank then this isn't actually correct, but that is unlikely to be a problem
  3273. if (includeLeft)
  3274. return +1;
  3275. else if (includeRight)
  3276. return -1;
  3277. else
  3278. return 0;
  3279. }
  3280. unsigned RtlIfBlockTypeInfo::hash(const byte * self, unsigned inhash) const
  3281. {
  3282. bool included = getCondition(self);
  3283. if (included)
  3284. inhash = hashFields(fields, self, inhash);
  3285. return inhash;
  3286. }
  3287. bool RtlDynamicIfBlockTypeInfo::getCondition(const byte * selfrow) const
  3288. {
  3289. #ifdef _DEBUG
  3290. // Temporary code to help my testing, until proper implementation available
  3291. return selfrow[3] != 2;
  3292. #endif
  3293. UNIMPLEMENTED;
  3294. }
  3295. //-------------------------------------------------------------------------------------------------------------------
  3296. __int64 RtlBitfieldTypeInfo::signedValue(const void * self) const
  3297. {
  3298. __int64 value = rtlReadInt(self, getBitfieldIntSize());
  3299. unsigned shift = getBitfieldShift();
  3300. unsigned numBits = getBitfieldNumBits();
  3301. unsigned bitsInValue = sizeof(value) * 8;
  3302. value <<= (bitsInValue - shift - numBits);
  3303. return value >> (bitsInValue - numBits);
  3304. }
  3305. unsigned __int64 RtlBitfieldTypeInfo::unsignedValue(const void * self) const
  3306. {
  3307. unsigned __int64 value = rtlReadUInt(self, getBitfieldIntSize());
  3308. unsigned shift = getBitfieldShift();
  3309. unsigned numBits = getBitfieldNumBits();
  3310. unsigned bitsInValue = sizeof(value) * 8;
  3311. value <<= (bitsInValue - shift - numBits);
  3312. return value >> (bitsInValue - numBits);
  3313. }
  3314. size32_t RtlBitfieldTypeInfo::buildInt(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, __int64 val) const
  3315. {
  3316. builder.ensureCapacity(length+offset, queryName(field));
  3317. byte * cur = builder.getSelf() + offset;
  3318. unsigned __int64 value = rtlReadUInt(builder.getSelf(), getBitfieldIntSize());
  3319. unsigned shift = getBitfieldShift();
  3320. unsigned numBits = getBitfieldNumBits();
  3321. unsigned __int64 mask = (U64C(1) << numBits) - 1;
  3322. value &= ~(mask << shift);
  3323. value |= ((val << shift) & mask);
  3324. rtlWriteInt(cur, val, getBitfieldIntSize());
  3325. return offset + getSize();
  3326. }
  3327. size32_t RtlBitfieldTypeInfo::buildString(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t size, const char *value) const
  3328. {
  3329. return buildInt(builder, offset, field, rtlStrToInt8(size, value));
  3330. }
  3331. size32_t RtlBitfieldTypeInfo::buildUtf8(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t len, const char *value) const
  3332. {
  3333. size32_t size = rtlUtf8Length(len, value);
  3334. return buildInt(builder, offset, field, rtlStrToInt8(size, value));
  3335. }
  3336. size32_t RtlBitfieldTypeInfo::getMinSize() const
  3337. {
  3338. if (fieldType & RFTMislastbitfield)
  3339. return getBitfieldIntSize();
  3340. return 0;
  3341. }
  3342. size32_t RtlBitfieldTypeInfo::size(const byte * self, const byte * selfrow) const
  3343. {
  3344. if (fieldType & RFTMislastbitfield)
  3345. return getBitfieldIntSize();
  3346. return 0;
  3347. }
  3348. size32_t RtlBitfieldTypeInfo::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  3349. {
  3350. if (isUnsigned())
  3351. target.processUInt(unsignedValue(self), field);
  3352. else
  3353. target.processInt(signedValue(self), field);
  3354. return getSize();
  3355. }
  3356. size32_t RtlBitfieldTypeInfo::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const
  3357. {
  3358. size32_t fieldsize = getBitfieldIntSize();
  3359. if (isUnsigned())
  3360. target.outputUInt(unsignedValue(self), fieldsize, queryScalarXPath(field));
  3361. else
  3362. target.outputInt(signedValue(self), fieldsize, queryScalarXPath(field));
  3363. if (fieldType & RFTMislastbitfield)
  3364. return fieldsize;
  3365. return 0;
  3366. }
  3367. void RtlBitfieldTypeInfo::getString(size32_t & resultLen, char * & result, const void * ptr) const
  3368. {
  3369. if (isUnsigned())
  3370. rtlUInt8ToStrX(resultLen, result, unsignedValue(ptr));
  3371. else
  3372. rtlInt8ToStrX(resultLen, result, signedValue(ptr));
  3373. }
  3374. void RtlBitfieldTypeInfo::getUtf8(size32_t & resultLen, char * & result, const void * ptr) const
  3375. {
  3376. getString(resultLen, result, ptr);
  3377. }
  3378. __int64 RtlBitfieldTypeInfo::getInt(const void * ptr) const
  3379. {
  3380. if (isUnsigned())
  3381. return (__int64)unsignedValue(ptr);
  3382. else
  3383. return signedValue(ptr);
  3384. }
  3385. int RtlBitfieldTypeInfo::compare(const byte * left, const byte * right) const
  3386. {
  3387. if (isUnsigned())
  3388. {
  3389. unsigned __int64 leftValue = unsignedValue(left);
  3390. unsigned __int64 rightValue = unsignedValue(right);
  3391. return (leftValue < rightValue) ? -1 : (leftValue > rightValue) ? +1 : 0;
  3392. }
  3393. else
  3394. {
  3395. __int64 leftValue = signedValue(left);
  3396. __int64 rightValue = signedValue(right);
  3397. return (leftValue < rightValue) ? -1 : (leftValue > rightValue) ? +1 : 0;
  3398. }
  3399. }
  3400. unsigned RtlBitfieldTypeInfo::hash(const byte * self, unsigned inhash) const
  3401. {
  3402. __int64 val = getInt(self);
  3403. return rtlHash32Data8(&val, inhash);
  3404. }
  3405. size32_t RtlBitfieldTypeInfo::getSize() const
  3406. {
  3407. if (fieldType & RFTMislastbitfield)
  3408. return getBitfieldIntSize();
  3409. return 0;
  3410. }
  3411. //-------------------------------------------------------------------------------------------------------------------
  3412. size32_t RtlUnimplementedTypeInfo::getMinSize() const
  3413. {
  3414. rtlFailUnexpected();
  3415. }
  3416. size32_t RtlUnimplementedTypeInfo::size(const byte * self, const byte * selfrow) const
  3417. {
  3418. rtlFailUnexpected();
  3419. }
  3420. size32_t RtlUnimplementedTypeInfo::buildString(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t size, const char *value) const
  3421. {
  3422. rtlFailUnexpected();
  3423. }
  3424. size32_t RtlUnimplementedTypeInfo::buildUtf8(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t len, const char *value) const
  3425. {
  3426. rtlFailUnexpected();
  3427. }
  3428. size32_t RtlUnimplementedTypeInfo::process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const
  3429. {
  3430. rtlFailUnexpected();
  3431. }
  3432. size32_t RtlUnimplementedTypeInfo::toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const
  3433. {
  3434. rtlFailUnexpected();
  3435. }
  3436. size32_t RtlUnimplementedTypeInfo::deserialize(ARowBuilder & builder, IRowDeserializerSource & in, size32_t offset) const
  3437. {
  3438. rtlFailUnexpected();
  3439. return offset;
  3440. }
  3441. void RtlUnimplementedTypeInfo::readAhead(IRowDeserializerSource & in) const
  3442. {
  3443. rtlFailUnexpected();
  3444. }
  3445. void RtlUnimplementedTypeInfo::getString(size32_t & resultLen, char * & result, const void * ptr) const
  3446. {
  3447. resultLen = 0;
  3448. result = nullptr;
  3449. rtlFailUnexpected();
  3450. }
  3451. void RtlUnimplementedTypeInfo::getUtf8(size32_t & resultLen, char * & result, const void * ptr) const
  3452. {
  3453. resultLen = 0;
  3454. result = nullptr;
  3455. rtlFailUnexpected();
  3456. }
  3457. __int64 RtlUnimplementedTypeInfo::getInt(const void * ptr) const
  3458. {
  3459. rtlFailUnexpected();
  3460. return 0;
  3461. }
  3462. int RtlUnimplementedTypeInfo::compare(const byte * left, const byte * right) const
  3463. {
  3464. rtlFailUnexpected();
  3465. }
  3466. unsigned RtlUnimplementedTypeInfo::hash(const byte * self, unsigned inhash) const
  3467. {
  3468. rtlFailUnexpected();
  3469. }
  3470. //-------------------------------------------------------------------------------------------------------------------
  3471. RtlFieldStrInfo::RtlFieldStrInfo(const char * _name, const char * _xpath, const RtlTypeInfo * _type, unsigned _flags, const char *_initializer)
  3472. : RtlFieldInfo(_name, _xpath, _type, _flags, _initializer)
  3473. {
  3474. }
  3475. RtlFieldStrInfo::RtlFieldStrInfo(const char * _name, const char * _xpath, const RtlTypeInfo * _type, unsigned _flags)
  3476. : RtlFieldInfo(_name, _xpath, _type, _flags, NULL)
  3477. {
  3478. }
  3479. RtlFieldStrInfo::RtlFieldStrInfo(const char * _name, const char * _xpath, const RtlTypeInfo * _type)
  3480. : RtlFieldInfo(_name, _xpath, _type, 0, NULL)
  3481. {
  3482. }
  3483. RtlFieldStrInfo::RtlFieldStrInfo(const char * _name, const char * _xpath, const RtlTypeInfo * _type, const char *_initializer)
  3484. : RtlFieldInfo(_name, _xpath, _type, 0, _initializer)
  3485. {
  3486. }
  3487. unsigned ECLRTL_API countFields(const RtlFieldInfo * const * fields)
  3488. {
  3489. unsigned cnt = 0;
  3490. for (;*fields;fields++)
  3491. cnt++;
  3492. return cnt;
  3493. }
  3494. /*
  3495. Stack:
  3496. * Change hqlhtcpp so that the correct derived classes are generated.
  3497. * Test so that toXML calls the default implementaions and check that the same values are generated. (Don't if contains ifblocks/alien)
  3498. * Release
  3499. * Think about bitfields - how do I know it is the last bitfield, how am I going to keep track of the offsets.
  3500. * What code would need to be generated for alien datatypes.
  3501. * Could have alien int and alien string varieties????
  3502. * What would an ecl interpreter look like (a special workunit?) helpers are interpreted? What about the graph?
  3503. * Could I add associations to register user attributes - so a callback could know when they were assigned to?
  3504. * Could I add ctx->noteLocation() into the generated code - so could put breakpoints on variables.
  3505. * Add annotation when a member of the target dataset is updated.
  3506. ctx->noteFieldAssigned(self, <field>); - does this include temporary datasets?
  3507. ctx->noteAttributeX(<name>, Int|String|Unicode|
  3508. ctx->noteLocation(location); - reduce locations, so only one returned per line for a non-dataset? Should it just be the first item on the line that is tagged??
  3509. * Need static information about the breakpoints so debugger knows where to put valid brakpoints....
  3510. * Debugger will want to know about the type of the breakpoints.
  3511. * Should try and compress the location format - possibly have a table of <module.attributes>-># with breakpoint as 12:23
  3512. Also need some information about which datasets, and stored variables etc. are used so they can be displayed.
  3513. - Most datasets can be deduced from the parameters passed into the transform
  3514. - Some are trickier e.g., the extract, could possibly define some mappings
  3515. - options to disable projects/other more complex operations inline (so easier to walk through)
  3516. Bitfields:
  3517. - Two separate questions:
  3518. i) How is the meta information generated.
  3519. ii) How is it stored internally in an IHqlExpression * ?
  3520. * Could store the offset in the type - either in the base type of as a qualifier.
  3521. + much easier code generation.
  3522. - Doesn't provie an easy indication of the last field in a bitfield (because can't really modify after the fact)
  3523. - Problematic when fields are removed to merge them.
  3524. * Could add a bitfield container to the record.
  3525. + Makes it easier to handle the last bitfield
  3526. + Matches the structure used for the cursor.
  3527. - Everything needs to walk the bitfield containers similar to ifblocks.
  3528. - Makes it just as tricky to merge
  3529. - Harder to create the record, unless the code is implicitly handled by appendOperand().
  3530. * The type of no_select could contain a modifier to indicate the offset/islast
  3531. + the type of a no_select would have a 1:1 mapping with type info.
  3532. - A bit complicated to calculate, especially when it isn't used much of the time
  3533. => On Reflection is is probably easiest to keep the structure as it is (some comments should go in hqlexpr to avoid revisiting).
  3534. * interperet bitfield offsets and "is last bitfield" dynamically
  3535. + Greatly simplifies generating the meta - you can always use the field.
  3536. - Requires another parameter and significant extra complexity for the uncommon case. (especially incrementing self)
  3537. * Could generate from the expanded record instead of walking the record structure directly
  3538. + That already knows how the bitfields are allocated, and could easily know which is the last field.
  3539. - A field is no longer sufficient as key fr searching for the information.
  3540. - Best would be a createFieldTypeKey(select-expr) which returns field when approriate, or modified if a bitfield. Then the pain is localised.
  3541. * Output a bitfield container item into the type information
  3542. + Solves the size problem
  3543. - Individual bitfields still need to know their offsets, so doesn't solve the full problem.
  3544. =>
  3545. Change so that either use meta to generate the information, or use no_select when appropriate to fidn out the nesc. information.
  3546. Probably the latter for the moment.
  3547. a) Create a key function and make sure it is always used.
  3548. b) Need to work out how to generate no_ifblock.
  3549. - ifblock is context dependent, so need to generate as part of the parent record, and in the parent record context.
  3550. */