kernel.js 137 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122
  1. /**
  2. * @fileoverview Kernel is a class to provide type-checked accessing
  3. * (read/write bool/int32/string/...) on binary data.
  4. *
  5. * When creating the Kernel with the binary data, there is no deep
  6. * decoding done (which requires full type information). The deep decoding is
  7. * deferred until the first time accessing (when accessors can provide
  8. * full type information).
  9. *
  10. * Because accessors can be statically analyzed and stripped, unlike eager
  11. * binary decoding (which requires the full type information of all defined
  12. * fields), Kernel will only need the full type information of used
  13. * fields.
  14. */
  15. goog.module('protobuf.runtime.Kernel');
  16. const BinaryStorage = goog.require('protobuf.runtime.BinaryStorage');
  17. const BufferDecoder = goog.require('protobuf.binary.BufferDecoder');
  18. const ByteString = goog.require('protobuf.ByteString');
  19. const Int64 = goog.require('protobuf.Int64');
  20. const InternalMessage = goog.require('protobuf.binary.InternalMessage');
  21. const Storage = goog.require('protobuf.runtime.Storage');
  22. const WireType = goog.require('protobuf.binary.WireType');
  23. const Writer = goog.require('protobuf.binary.Writer');
  24. const reader = goog.require('protobuf.binary.reader');
  25. const {CHECK_TYPE, checkCriticalElementIndex, checkCriticalState, checkCriticalType, checkCriticalTypeBool, checkCriticalTypeBoolArray, checkCriticalTypeByteString, checkCriticalTypeByteStringArray, checkCriticalTypeDouble, checkCriticalTypeDoubleArray, checkCriticalTypeFloat, checkCriticalTypeFloatIterable, checkCriticalTypeMessageArray, checkCriticalTypeSignedInt32, checkCriticalTypeSignedInt32Array, checkCriticalTypeSignedInt64, checkCriticalTypeSignedInt64Array, checkCriticalTypeString, checkCriticalTypeStringArray, checkCriticalTypeUnsignedInt32, checkCriticalTypeUnsignedInt32Array, checkDefAndNotNull, checkElementIndex, checkFieldNumber, checkFunctionExists, checkState, checkTypeDouble, checkTypeFloat, checkTypeSignedInt32, checkTypeSignedInt64, checkTypeUnsignedInt32} = goog.require('protobuf.internal.checks');
  26. const {Field, IndexEntry} = goog.require('protobuf.binary.field');
  27. const {buildIndex} = goog.require('protobuf.binary.indexer');
  28. const {createTag, get32BitVarintLength, getTagLength} = goog.require('protobuf.binary.tag');
  29. /**
  30. * Validates the index entry has the correct wire type.
  31. * @param {!IndexEntry} indexEntry
  32. * @param {!WireType} expected
  33. */
  34. function validateWireType(indexEntry, expected) {
  35. const wireType = Field.getWireType(indexEntry);
  36. checkCriticalState(
  37. wireType === expected,
  38. `Expected wire type: ${expected} but found: ${wireType}`);
  39. }
  40. /**
  41. * Checks if the object implements InternalMessage interface.
  42. * @param {?} obj
  43. * @return {!InternalMessage}
  44. */
  45. function checkIsInternalMessage(obj) {
  46. const message = /** @type {!InternalMessage} */ (obj);
  47. checkFunctionExists(message.internalGetKernel);
  48. return message;
  49. }
  50. /**
  51. * Checks if the instanceCreator returns an instance that implements the
  52. * InternalMessage interface.
  53. * @param {function(!Kernel):T} instanceCreator
  54. * @template T
  55. */
  56. function checkInstanceCreator(instanceCreator) {
  57. if (CHECK_TYPE) {
  58. const emptyMessage = instanceCreator(Kernel.createEmpty());
  59. checkFunctionExists(emptyMessage.internalGetKernel);
  60. }
  61. }
  62. /**
  63. * Reads the last entry of the index array using the given read function.
  64. * This is used to implement parsing singular primitive fields.
  65. * @param {!Array<!IndexEntry>} indexArray
  66. * @param {!BufferDecoder} bufferDecoder
  67. * @param {function(!BufferDecoder, number):T} readFunc
  68. * @param {!WireType} wireType
  69. * @return {T}
  70. * @template T
  71. */
  72. function readOptional(indexArray, bufferDecoder, readFunc, wireType) {
  73. const index = indexArray.length - 1;
  74. checkElementIndex(index, indexArray.length);
  75. const indexEntry = indexArray[index];
  76. validateWireType(indexEntry, wireType);
  77. return readFunc(bufferDecoder, Field.getStartIndex(indexEntry));
  78. }
  79. /**
  80. * Converts all entries of the index array to the template type using given read
  81. * methods and return an Iterable containing those converted values.
  82. * Primitive repeated fields may be encoded either packed or unpacked. Thus, two
  83. * read methods are needed for those two cases.
  84. * This is used to implement parsing repeated primitive fields.
  85. * @param {!Array<!IndexEntry>} indexArray
  86. * @param {!BufferDecoder} bufferDecoder
  87. * @param {function(!BufferDecoder, number):T} singularReadFunc
  88. * @param {function(!BufferDecoder, number):!Array<T>} packedReadFunc
  89. * @param {!WireType} expectedWireType
  90. * @return {!Array<T>}
  91. * @template T
  92. */
  93. function readRepeatedPrimitive(
  94. indexArray, bufferDecoder, singularReadFunc, packedReadFunc,
  95. expectedWireType) {
  96. // Fast path when there is a single packed entry.
  97. if (indexArray.length === 1 &&
  98. Field.getWireType(indexArray[0]) === WireType.DELIMITED) {
  99. return packedReadFunc(bufferDecoder, Field.getStartIndex(indexArray[0]));
  100. }
  101. let /** !Array<T> */ result = [];
  102. for (const indexEntry of indexArray) {
  103. const wireType = Field.getWireType(indexEntry);
  104. const startIndex = Field.getStartIndex(indexEntry);
  105. if (wireType === WireType.DELIMITED) {
  106. result = result.concat(packedReadFunc(bufferDecoder, startIndex));
  107. } else {
  108. validateWireType(indexEntry, expectedWireType);
  109. result.push(singularReadFunc(bufferDecoder, startIndex));
  110. }
  111. }
  112. return result;
  113. }
  114. /**
  115. * Converts all entries of the index array to the template type using the given
  116. * read function and return an Array containing those converted values. This is
  117. * used to implement parsing repeated non-primitive fields.
  118. * @param {!Array<!IndexEntry>} indexArray
  119. * @param {!BufferDecoder} bufferDecoder
  120. * @param {function(!BufferDecoder, number):T} singularReadFunc
  121. * @return {!Array<T>}
  122. * @template T
  123. */
  124. function readRepeatedNonPrimitive(indexArray, bufferDecoder, singularReadFunc) {
  125. const result = new Array(indexArray.length);
  126. for (let i = 0; i < indexArray.length; i++) {
  127. validateWireType(indexArray[i], WireType.DELIMITED);
  128. result[i] =
  129. singularReadFunc(bufferDecoder, Field.getStartIndex(indexArray[i]));
  130. }
  131. return result;
  132. }
  133. /**
  134. * Converts all entries of the index array to the template type using the given
  135. * read function and return an Array containing those converted values. This is
  136. * used to implement parsing repeated non-primitive fields.
  137. * @param {!Array<!IndexEntry>} indexArray
  138. * @param {!BufferDecoder} bufferDecoder
  139. * @param {number} fieldNumber
  140. * @param {function(!Kernel):T} instanceCreator
  141. * @param {number=} pivot
  142. * @return {!Array<T>}
  143. * @template T
  144. */
  145. function readRepeatedGroup(
  146. indexArray, bufferDecoder, fieldNumber, instanceCreator, pivot) {
  147. const result = new Array(indexArray.length);
  148. for (let i = 0; i < indexArray.length; i++) {
  149. result[i] = doReadGroup(
  150. bufferDecoder, indexArray[i], fieldNumber, instanceCreator, pivot);
  151. }
  152. return result;
  153. }
  154. /**
  155. * Creates a new bytes array to contain all data of a submessage.
  156. * When there are multiple entries, merge them together.
  157. * @param {!Array<!IndexEntry>} indexArray
  158. * @param {!BufferDecoder} bufferDecoder
  159. * @return {!BufferDecoder}
  160. */
  161. function mergeMessageArrays(indexArray, bufferDecoder) {
  162. const dataArrays = indexArray.map(
  163. indexEntry =>
  164. reader.readDelimited(bufferDecoder, Field.getStartIndex(indexEntry)));
  165. return BufferDecoder.merge(dataArrays);
  166. }
  167. /**
  168. * @param {!Array<!IndexEntry>} indexArray
  169. * @param {!BufferDecoder} bufferDecoder
  170. * @param {number=} pivot
  171. * @return {!Kernel}
  172. */
  173. function readAccessor(indexArray, bufferDecoder, pivot = undefined) {
  174. checkState(indexArray.length > 0);
  175. let accessorBuffer;
  176. // Faster access for one member.
  177. if (indexArray.length === 1) {
  178. const indexEntry = indexArray[0];
  179. validateWireType(indexEntry, WireType.DELIMITED);
  180. accessorBuffer =
  181. reader.readDelimited(bufferDecoder, Field.getStartIndex(indexEntry));
  182. } else {
  183. indexArray.forEach(indexEntry => {
  184. validateWireType(indexEntry, WireType.DELIMITED);
  185. });
  186. accessorBuffer = mergeMessageArrays(indexArray, bufferDecoder);
  187. }
  188. return Kernel.fromBufferDecoder_(accessorBuffer, pivot);
  189. }
  190. /**
  191. * Merges all index entries of the index array using the given read function.
  192. * This is used to implement parsing singular message fields.
  193. * @param {!Array<!IndexEntry>} indexArray
  194. * @param {!BufferDecoder} bufferDecoder
  195. * @param {function(!Kernel):T} instanceCreator
  196. * @param {number=} pivot
  197. * @return {T}
  198. * @template T
  199. */
  200. function readMessage(indexArray, bufferDecoder, instanceCreator, pivot) {
  201. checkInstanceCreator(instanceCreator);
  202. const accessor = readAccessor(indexArray, bufferDecoder, pivot);
  203. return instanceCreator(accessor);
  204. }
  205. /**
  206. * Merges all index entries of the index array using the given read function.
  207. * This is used to implement parsing singular group fields.
  208. * @param {!Array<!IndexEntry>} indexArray
  209. * @param {!BufferDecoder} bufferDecoder
  210. * @param {number} fieldNumber
  211. * @param {function(!Kernel):T} instanceCreator
  212. * @param {number=} pivot
  213. * @return {T}
  214. * @template T
  215. */
  216. function readGroup(
  217. indexArray, bufferDecoder, fieldNumber, instanceCreator, pivot) {
  218. checkInstanceCreator(instanceCreator);
  219. checkState(indexArray.length > 0);
  220. return doReadGroup(
  221. bufferDecoder, indexArray[indexArray.length - 1], fieldNumber,
  222. instanceCreator, pivot);
  223. }
  224. /**
  225. * Merges all index entries of the index array using the given read function.
  226. * This is used to implement parsing singular message fields.
  227. * @param {!BufferDecoder} bufferDecoder
  228. * @param {!IndexEntry} indexEntry
  229. * @param {number} fieldNumber
  230. * @param {function(!Kernel):T} instanceCreator
  231. * @param {number=} pivot
  232. * @return {T}
  233. * @template T
  234. */
  235. function doReadGroup(
  236. bufferDecoder, indexEntry, fieldNumber, instanceCreator, pivot) {
  237. validateWireType(indexEntry, WireType.START_GROUP);
  238. const fieldStartIndex = Field.getStartIndex(indexEntry);
  239. const tag = createTag(WireType.START_GROUP, fieldNumber);
  240. const groupTagLength = get32BitVarintLength(tag);
  241. const groupLength = getTagLength(
  242. bufferDecoder, fieldStartIndex, WireType.START_GROUP, fieldNumber);
  243. const accessorBuffer = bufferDecoder.subBufferDecoder(
  244. fieldStartIndex, groupLength - groupTagLength);
  245. const kernel = Kernel.fromBufferDecoder_(accessorBuffer, pivot);
  246. return instanceCreator(kernel);
  247. }
  248. /**
  249. * @param {!Writer} writer
  250. * @param {number} fieldNumber
  251. * @param {?InternalMessage} value
  252. */
  253. function writeMessage(writer, fieldNumber, value) {
  254. writer.writeDelimited(
  255. fieldNumber, checkDefAndNotNull(value).internalGetKernel().serialize());
  256. }
  257. /**
  258. * @param {!Writer} writer
  259. * @param {number} fieldNumber
  260. * @param {?InternalMessage} value
  261. */
  262. function writeGroup(writer, fieldNumber, value) {
  263. const kernel = checkDefAndNotNull(value).internalGetKernel();
  264. writer.writeStartGroup(fieldNumber);
  265. kernel.serializeToWriter(writer);
  266. writer.writeEndGroup(fieldNumber);
  267. }
  268. /**
  269. * Writes the array of Messages into the writer for the given field number.
  270. * @param {!Writer} writer
  271. * @param {number} fieldNumber
  272. * @param {!Iterable<!InternalMessage>} values
  273. */
  274. function writeRepeatedMessage(writer, fieldNumber, values) {
  275. for (const value of values) {
  276. writeMessage(writer, fieldNumber, value);
  277. }
  278. }
  279. /**
  280. * Writes the array of Messages into the writer for the given field number.
  281. * @param {!Writer} writer
  282. * @param {number} fieldNumber
  283. * @param {!Array<!InternalMessage>} values
  284. */
  285. function writeRepeatedGroup(writer, fieldNumber, values) {
  286. for (const value of values) {
  287. writeGroup(writer, fieldNumber, value);
  288. }
  289. }
  290. /**
  291. * Array.from has a weird type definition in google3/javascript/externs/es6.js
  292. * and wants the mapping function accept strings.
  293. * @const {function((string|number)): number}
  294. */
  295. const fround = /** @type {function((string|number)): number} */ (Math.fround);
  296. /**
  297. * Wraps an array and exposes it as an Iterable. This class is used to provide
  298. * immutable access of the array to the caller.
  299. * @implements {Iterable<T>}
  300. * @template T
  301. */
  302. class ArrayIterable {
  303. /**
  304. * @param {!Array<T>} array
  305. */
  306. constructor(array) {
  307. /** @private @const {!Array<T>} */
  308. this.array_ = array;
  309. }
  310. /** @return {!Iterator<T>} */
  311. [Symbol.iterator]() {
  312. return this.array_[Symbol.iterator]();
  313. }
  314. }
  315. /**
  316. * Accesses protobuf fields on binary format data. Binary data is decoded lazily
  317. * at the first access.
  318. * @final
  319. */
  320. class Kernel {
  321. /**
  322. * Create a Kernel for the given binary bytes.
  323. * The bytes array is kept by the Kernel. DON'T MODIFY IT.
  324. * @param {!ArrayBuffer} arrayBuffer Binary bytes.
  325. * @param {number=} pivot Fields with a field number no greater than the pivot
  326. * value will be stored in an array for fast access. Other fields will be
  327. * stored in a map. A higher pivot value can improve runtime performance
  328. * at the expense of requiring more memory. It's recommended to set the
  329. * value to the max field number of the message unless the field numbers
  330. * are too sparse. If the value is not set, a default value specified in
  331. * storage.js will be used.
  332. * @return {!Kernel}
  333. */
  334. static fromArrayBuffer(arrayBuffer, pivot = undefined) {
  335. const bufferDecoder = BufferDecoder.fromArrayBuffer(arrayBuffer);
  336. return Kernel.fromBufferDecoder_(bufferDecoder, pivot);
  337. }
  338. /**
  339. * Creates an empty Kernel.
  340. * @param {number=} pivot Fields with a field number no greater than the pivot
  341. * value will be stored in an array for fast access. Other fields will be
  342. * stored in a map. A higher pivot value can improve runtime performance
  343. * at the expense of requiring more memory. It's recommended to set the
  344. * value to the max field number of the message unless the field numbers
  345. * are too sparse. If the value is not set, a default value specified in
  346. * storage.js will be used.
  347. * @return {!Kernel}
  348. */
  349. static createEmpty(pivot = undefined) {
  350. return new Kernel(/* bufferDecoder= */ null, new BinaryStorage(pivot));
  351. }
  352. /**
  353. * Create a Kernel for the given binary bytes.
  354. * The bytes array is kept by the Kernel. DON'T MODIFY IT.
  355. * @param {!BufferDecoder} bufferDecoder Binary bytes.
  356. * @param {number|undefined} pivot
  357. * @return {!Kernel}
  358. * @private
  359. */
  360. static fromBufferDecoder_(bufferDecoder, pivot) {
  361. return new Kernel(bufferDecoder, buildIndex(bufferDecoder, pivot));
  362. }
  363. /**
  364. * @param {?BufferDecoder} bufferDecoder Binary bytes. Accessor treats the
  365. * bytes as immutable and will never attempt to write to it.
  366. * @param {!Storage<!Field>} fields A map of field number to Field. The
  367. * IndexEntry in each Field needs to be populated with the location of the
  368. * field in the binary data.
  369. * @private
  370. */
  371. constructor(bufferDecoder, fields) {
  372. /** @private @const {?BufferDecoder} */
  373. this.bufferDecoder_ = bufferDecoder;
  374. /** @private @const {!Storage<!Field>} */
  375. this.fields_ = fields;
  376. }
  377. /**
  378. * Creates a shallow copy of the accessor.
  379. * @return {!Kernel}
  380. */
  381. shallowCopy() {
  382. return new Kernel(this.bufferDecoder_, this.fields_.shallowCopy());
  383. }
  384. /**
  385. * See definition of the pivot parameter on the fromArrayBuffer() method.
  386. * @return {number}
  387. */
  388. getPivot() {
  389. return this.fields_.getPivot();
  390. }
  391. /**
  392. * Clears the field for the given field number.
  393. * @param {number} fieldNumber
  394. */
  395. clearField(fieldNumber) {
  396. this.fields_.delete(fieldNumber);
  397. }
  398. /**
  399. * Returns data for a field specified by the given field number. Also cache
  400. * the data if it doesn't already exist in the cache. When no data is
  401. * available, return the given default value.
  402. * @param {number} fieldNumber
  403. * @param {?T} defaultValue
  404. * @param {function(!Array<!IndexEntry>, !BufferDecoder):T} readFunc
  405. * @param {function(!Writer, number, T)=} encoder
  406. * @return {T}
  407. * @template T
  408. * @private
  409. */
  410. getFieldWithDefault_(
  411. fieldNumber, defaultValue, readFunc, encoder = undefined) {
  412. checkFieldNumber(fieldNumber);
  413. const field = this.fields_.get(fieldNumber);
  414. if (field === undefined) {
  415. return defaultValue;
  416. }
  417. if (field.hasDecodedValue()) {
  418. checkState(!encoder || !!field.getEncoder());
  419. return field.getDecodedValue();
  420. }
  421. const parsed = readFunc(
  422. checkDefAndNotNull(field.getIndexArray()),
  423. checkDefAndNotNull(this.bufferDecoder_));
  424. field.setCache(parsed, encoder);
  425. return parsed;
  426. }
  427. /**
  428. * Sets data for a singular field specified by the given field number.
  429. * @param {number} fieldNumber
  430. * @param {T} value
  431. * @param {function(!Writer, number, T)} encoder
  432. * @return {T}
  433. * @template T
  434. * @private
  435. */
  436. setField_(fieldNumber, value, encoder) {
  437. checkFieldNumber(fieldNumber);
  438. this.fields_.set(fieldNumber, Field.fromDecodedValue(value, encoder));
  439. }
  440. /**
  441. * Serializes internal contents to binary format bytes array to the
  442. * given writer.
  443. * @param {!Writer} writer
  444. * @package
  445. */
  446. serializeToWriter(writer) {
  447. // If we use for...of here, jscompiler returns an array of both types for
  448. // fieldNumber and field without specifying which type is for
  449. // field, which prevents us to use fieldNumber. Thus, we use
  450. // forEach here.
  451. this.fields_.forEach((field, fieldNumber) => {
  452. // If encoder doesn't exist, there is no need to encode the value
  453. // because the data in the index is still valid.
  454. if (field.getEncoder() !== undefined) {
  455. const encoder = checkDefAndNotNull(field.getEncoder());
  456. encoder(writer, fieldNumber, field.getDecodedValue());
  457. return;
  458. }
  459. const indexArr = field.getIndexArray();
  460. if (indexArr) {
  461. for (const indexEntry of indexArr) {
  462. writer.writeTag(fieldNumber, Field.getWireType(indexEntry));
  463. writer.writeBufferDecoder(
  464. checkDefAndNotNull(this.bufferDecoder_),
  465. Field.getStartIndex(indexEntry), Field.getWireType(indexEntry),
  466. fieldNumber);
  467. }
  468. }
  469. });
  470. }
  471. /**
  472. * Serializes internal contents to binary format bytes array.
  473. * @return {!ArrayBuffer}
  474. */
  475. serialize() {
  476. const writer = new Writer();
  477. this.serializeToWriter(writer);
  478. return writer.getAndResetResultBuffer();
  479. }
  480. /**
  481. * Returns whether data exists at the given field number.
  482. * @param {number} fieldNumber
  483. * @return {boolean}
  484. */
  485. hasFieldNumber(fieldNumber) {
  486. checkFieldNumber(fieldNumber);
  487. const field = this.fields_.get(fieldNumber);
  488. if (field === undefined) {
  489. return false;
  490. }
  491. if (field.getIndexArray() !== null) {
  492. return true;
  493. }
  494. if (Array.isArray(field.getDecodedValue())) {
  495. // For repeated fields, existence is decided by number of elements.
  496. return (/** !Array<?> */ (field.getDecodedValue())).length > 0;
  497. }
  498. return true;
  499. }
  500. /***************************************************************************
  501. * OPTIONAL GETTER METHODS
  502. ***************************************************************************/
  503. /**
  504. * Returns data as boolean for the given field number.
  505. * If no default is given, use false as the default.
  506. * @param {number} fieldNumber
  507. * @param {boolean=} defaultValue
  508. * @return {boolean}
  509. */
  510. getBoolWithDefault(fieldNumber, defaultValue = false) {
  511. return this.getFieldWithDefault_(
  512. fieldNumber, defaultValue,
  513. (indexArray, bytes) =>
  514. readOptional(indexArray, bytes, reader.readBool, WireType.VARINT));
  515. }
  516. /**
  517. * Returns data as a ByteString for the given field number.
  518. * If no default is given, use false as the default.
  519. * @param {number} fieldNumber
  520. * @param {!ByteString=} defaultValue
  521. * @return {!ByteString}
  522. */
  523. getBytesWithDefault(fieldNumber, defaultValue = ByteString.EMPTY) {
  524. return this.getFieldWithDefault_(
  525. fieldNumber, defaultValue,
  526. (indexArray, bytes) => readOptional(
  527. indexArray, bytes, reader.readBytes, WireType.DELIMITED));
  528. }
  529. /**
  530. * Returns a double for the given field number.
  531. * If no default is given uses zero as the default.
  532. * @param {number} fieldNumber
  533. * @param {number=} defaultValue
  534. * @return {number}
  535. */
  536. getDoubleWithDefault(fieldNumber, defaultValue = 0) {
  537. checkTypeDouble(defaultValue);
  538. return this.getFieldWithDefault_(
  539. fieldNumber, defaultValue,
  540. (indexArray, bytes) => readOptional(
  541. indexArray, bytes, reader.readDouble, WireType.FIXED64));
  542. }
  543. /**
  544. * Returns a fixed32 for the given field number.
  545. * If no default is given zero as the default.
  546. * @param {number} fieldNumber
  547. * @param {number=} defaultValue
  548. * @return {number}
  549. */
  550. getFixed32WithDefault(fieldNumber, defaultValue = 0) {
  551. checkTypeUnsignedInt32(defaultValue);
  552. return this.getFieldWithDefault_(
  553. fieldNumber, defaultValue,
  554. (indexArray, bytes) => readOptional(
  555. indexArray, bytes, reader.readFixed32, WireType.FIXED32));
  556. }
  557. /**
  558. * Returns a fixed64 for the given field number.
  559. * Note: Since g.m.Long does not support unsigned int64 values we are going
  560. * the Java route here for now and simply output the number as a signed int64.
  561. * Users can get to individual bits by themselves.
  562. * @param {number} fieldNumber
  563. * @param {!Int64=} defaultValue
  564. * @return {!Int64}
  565. */
  566. getFixed64WithDefault(fieldNumber, defaultValue = Int64.getZero()) {
  567. return this.getSfixed64WithDefault(fieldNumber, defaultValue);
  568. }
  569. /**
  570. * Returns a float for the given field number.
  571. * If no default is given zero as the default.
  572. * @param {number} fieldNumber
  573. * @param {number=} defaultValue
  574. * @return {number}
  575. */
  576. getFloatWithDefault(fieldNumber, defaultValue = 0) {
  577. checkTypeFloat(defaultValue);
  578. return this.getFieldWithDefault_(
  579. fieldNumber, defaultValue,
  580. (indexArray, bytes) => readOptional(
  581. indexArray, bytes, reader.readFloat, WireType.FIXED32));
  582. }
  583. /**
  584. * Returns a int32 for the given field number.
  585. * If no default is given zero as the default.
  586. * @param {number} fieldNumber
  587. * @param {number=} defaultValue
  588. * @return {number}
  589. */
  590. getInt32WithDefault(fieldNumber, defaultValue = 0) {
  591. checkTypeSignedInt32(defaultValue);
  592. return this.getFieldWithDefault_(
  593. fieldNumber, defaultValue,
  594. (indexArray, bytes) =>
  595. readOptional(indexArray, bytes, reader.readInt32, WireType.VARINT));
  596. }
  597. /**
  598. * Returns a int64 for the given field number.
  599. * If no default is given zero as the default.
  600. * @param {number} fieldNumber
  601. * @param {!Int64=} defaultValue
  602. * @return {!Int64}
  603. */
  604. getInt64WithDefault(fieldNumber, defaultValue = Int64.getZero()) {
  605. checkTypeSignedInt64(defaultValue);
  606. return this.getFieldWithDefault_(
  607. fieldNumber, defaultValue,
  608. (indexArray, bytes) =>
  609. readOptional(indexArray, bytes, reader.readInt64, WireType.VARINT));
  610. }
  611. /**
  612. * Returns a sfixed32 for the given field number.
  613. * If no default is given zero as the default.
  614. * @param {number} fieldNumber
  615. * @param {number=} defaultValue
  616. * @return {number}
  617. */
  618. getSfixed32WithDefault(fieldNumber, defaultValue = 0) {
  619. checkTypeSignedInt32(defaultValue);
  620. return this.getFieldWithDefault_(
  621. fieldNumber, defaultValue,
  622. (indexArray, bytes) => readOptional(
  623. indexArray, bytes, reader.readSfixed32, WireType.FIXED32));
  624. }
  625. /**
  626. * Returns a sfixed64 for the given field number.
  627. * If no default is given zero as the default.
  628. * @param {number} fieldNumber
  629. * @param {!Int64=} defaultValue
  630. * @return {!Int64}
  631. */
  632. getSfixed64WithDefault(fieldNumber, defaultValue = Int64.getZero()) {
  633. checkTypeSignedInt64(defaultValue);
  634. return this.getFieldWithDefault_(
  635. fieldNumber, defaultValue,
  636. (indexArray, bytes) => readOptional(
  637. indexArray, bytes, reader.readSfixed64, WireType.FIXED64));
  638. }
  639. /**
  640. * Returns a sint32 for the given field number.
  641. * If no default is given zero as the default.
  642. * @param {number} fieldNumber
  643. * @param {number=} defaultValue
  644. * @return {number}
  645. */
  646. getSint32WithDefault(fieldNumber, defaultValue = 0) {
  647. checkTypeSignedInt32(defaultValue);
  648. return this.getFieldWithDefault_(
  649. fieldNumber, defaultValue,
  650. (indexArray, bytes) => readOptional(
  651. indexArray, bytes, reader.readSint32, WireType.VARINT));
  652. }
  653. /**
  654. * Returns a sint64 for the given field number.
  655. * If no default is given zero as the default.
  656. * @param {number} fieldNumber
  657. * @param {!Int64=} defaultValue
  658. * @return {!Int64}
  659. */
  660. getSint64WithDefault(fieldNumber, defaultValue = Int64.getZero()) {
  661. checkTypeSignedInt64(defaultValue);
  662. return this.getFieldWithDefault_(
  663. fieldNumber, defaultValue,
  664. (indexArray, bytes) => readOptional(
  665. indexArray, bytes, reader.readSint64, WireType.VARINT));
  666. }
  667. /**
  668. * Returns a string for the given field number.
  669. * If no default is given uses empty string as the default.
  670. * @param {number} fieldNumber
  671. * @param {string=} defaultValue
  672. * @return {string}
  673. */
  674. getStringWithDefault(fieldNumber, defaultValue = '') {
  675. return this.getFieldWithDefault_(
  676. fieldNumber, defaultValue,
  677. (indexArray, bytes) => readOptional(
  678. indexArray, bytes, reader.readString, WireType.DELIMITED));
  679. }
  680. /**
  681. * Returns a uint32 for the given field number.
  682. * If no default is given zero as the default.
  683. * @param {number} fieldNumber
  684. * @param {number=} defaultValue
  685. * @return {number}
  686. */
  687. getUint32WithDefault(fieldNumber, defaultValue = 0) {
  688. checkTypeUnsignedInt32(defaultValue);
  689. return this.getFieldWithDefault_(
  690. fieldNumber, defaultValue,
  691. (indexArray, bytes) => readOptional(
  692. indexArray, bytes, reader.readUint32, WireType.VARINT));
  693. }
  694. /**
  695. * Returns a uint64 for the given field number.
  696. * Note: Since g.m.Long does not support unsigned int64 values we are going
  697. * the Java route here for now and simply output the number as a signed int64.
  698. * Users can get to individual bits by themselves.
  699. * @param {number} fieldNumber
  700. * @param {!Int64=} defaultValue
  701. * @return {!Int64}
  702. */
  703. getUint64WithDefault(fieldNumber, defaultValue = Int64.getZero()) {
  704. return this.getInt64WithDefault(fieldNumber, defaultValue);
  705. }
  706. /**
  707. * Returns data as a mutable proto Message for the given field number.
  708. * If no value has been set, return null.
  709. * If hasFieldNumber(fieldNumber) == false before calling, it remains false.
  710. *
  711. * This method should not be used along with getMessage, since calling
  712. * getMessageOrNull after getMessage will not register the encoder.
  713. *
  714. * @param {number} fieldNumber
  715. * @param {function(!Kernel):T} instanceCreator
  716. * @param {number=} pivot
  717. * @return {?T}
  718. * @template T
  719. */
  720. getMessageOrNull(fieldNumber, instanceCreator, pivot = undefined) {
  721. return this.getFieldWithDefault_(
  722. fieldNumber, null,
  723. (indexArray, bytes) =>
  724. readMessage(indexArray, bytes, instanceCreator, pivot),
  725. writeMessage);
  726. }
  727. /**
  728. * Returns data as a mutable proto Message for the given field number.
  729. * If no value has been set, return null.
  730. * If hasFieldNumber(fieldNumber) == false before calling, it remains false.
  731. *
  732. * This method should not be used along with getMessage, since calling
  733. * getMessageOrNull after getMessage will not register the encoder.
  734. *
  735. * @param {number} fieldNumber
  736. * @param {function(!Kernel):T} instanceCreator
  737. * @param {number=} pivot
  738. * @return {?T}
  739. * @template T
  740. */
  741. getGroupOrNull(fieldNumber, instanceCreator, pivot = undefined) {
  742. return this.getFieldWithDefault_(
  743. fieldNumber, null,
  744. (indexArray, bytes) =>
  745. readGroup(indexArray, bytes, fieldNumber, instanceCreator, pivot),
  746. writeGroup);
  747. }
  748. /**
  749. * Returns data as a mutable proto Message for the given field number.
  750. * If no value has been set previously, creates and attaches an instance.
  751. * Postcondition: hasFieldNumber(fieldNumber) == true.
  752. *
  753. * This method should not be used along with getMessage, since calling
  754. * getMessageAttach after getMessage will not register the encoder.
  755. *
  756. * @param {number} fieldNumber
  757. * @param {function(!Kernel):T} instanceCreator
  758. * @param {number=} pivot
  759. * @return {T}
  760. * @template T
  761. */
  762. getMessageAttach(fieldNumber, instanceCreator, pivot = undefined) {
  763. checkInstanceCreator(instanceCreator);
  764. let instance = this.getMessageOrNull(fieldNumber, instanceCreator, pivot);
  765. if (!instance) {
  766. instance = instanceCreator(Kernel.createEmpty());
  767. this.setField_(fieldNumber, instance, writeMessage);
  768. }
  769. return instance;
  770. }
  771. /**
  772. * Returns data as a mutable proto Message for the given field number.
  773. * If no value has been set previously, creates and attaches an instance.
  774. * Postcondition: hasFieldNumber(fieldNumber) == true.
  775. *
  776. * This method should not be used along with getMessage, since calling
  777. * getMessageAttach after getMessage will not register the encoder.
  778. *
  779. * @param {number} fieldNumber
  780. * @param {function(!Kernel):T} instanceCreator
  781. * @param {number=} pivot
  782. * @return {T}
  783. * @template T
  784. */
  785. getGroupAttach(fieldNumber, instanceCreator, pivot = undefined) {
  786. checkInstanceCreator(instanceCreator);
  787. let instance = this.getGroupOrNull(fieldNumber, instanceCreator, pivot);
  788. if (!instance) {
  789. instance = instanceCreator(Kernel.createEmpty());
  790. this.setField_(fieldNumber, instance, writeGroup);
  791. }
  792. return instance;
  793. }
  794. /**
  795. * Returns data as a proto Message for the given field number.
  796. * If no value has been set, return a default instance.
  797. * This default instance is guaranteed to be the same instance, unless this
  798. * field is cleared.
  799. * Does not register the encoder, so changes made to the returned
  800. * sub-message will not be included when serializing the parent message.
  801. * Use getMessageAttach() if the resulting sub-message should be mutable.
  802. *
  803. * This method should not be used along with getMessageOrNull or
  804. * getMessageAttach, since these methods register the encoder.
  805. *
  806. * @param {number} fieldNumber
  807. * @param {function(!Kernel):T} instanceCreator
  808. * @param {number=} pivot
  809. * @return {T}
  810. * @template T
  811. */
  812. getMessage(fieldNumber, instanceCreator, pivot = undefined) {
  813. checkInstanceCreator(instanceCreator);
  814. const message = this.getFieldWithDefault_(
  815. fieldNumber, null,
  816. (indexArray, bytes) =>
  817. readMessage(indexArray, bytes, instanceCreator, pivot));
  818. // Returns an empty message as the default value if the field doesn't exist.
  819. // We don't pass the default value to getFieldWithDefault_ to reduce object
  820. // allocation.
  821. return message === null ? instanceCreator(Kernel.createEmpty()) : message;
  822. }
  823. /**
  824. * Returns data as a proto Message for the given field number.
  825. * If no value has been set, return a default instance.
  826. * This default instance is guaranteed to be the same instance, unless this
  827. * field is cleared.
  828. * Does not register the encoder, so changes made to the returned
  829. * sub-message will not be included when serializing the parent message.
  830. * Use getMessageAttach() if the resulting sub-message should be mutable.
  831. *
  832. * This method should not be used along with getMessageOrNull or
  833. * getMessageAttach, since these methods register the encoder.
  834. *
  835. * @param {number} fieldNumber
  836. * @param {function(!Kernel):T} instanceCreator
  837. * @param {number=} pivot
  838. * @return {T}
  839. * @template T
  840. */
  841. getGroup(fieldNumber, instanceCreator, pivot = undefined) {
  842. checkInstanceCreator(instanceCreator);
  843. const message = this.getFieldWithDefault_(
  844. fieldNumber, null,
  845. (indexArray, bytes) =>
  846. readGroup(indexArray, bytes, fieldNumber, instanceCreator, pivot));
  847. // Returns an empty message as the default value if the field doesn't exist.
  848. // We don't pass the default value to getFieldWithDefault_ to reduce object
  849. // allocation.
  850. return message === null ? instanceCreator(Kernel.createEmpty()) : message;
  851. }
  852. /**
  853. * Returns the accessor for the given singular message, or returns null if
  854. * it hasn't been set.
  855. * @param {number} fieldNumber
  856. * @param {number=} pivot
  857. * @return {?Kernel}
  858. */
  859. getMessageAccessorOrNull(fieldNumber, pivot = undefined) {
  860. checkFieldNumber(fieldNumber);
  861. const field = this.fields_.get(fieldNumber);
  862. if (field === undefined) {
  863. return null;
  864. }
  865. if (field.hasDecodedValue()) {
  866. return checkIsInternalMessage(field.getDecodedValue())
  867. .internalGetKernel();
  868. } else {
  869. return readAccessor(
  870. checkDefAndNotNull(field.getIndexArray()),
  871. checkDefAndNotNull(this.bufferDecoder_), pivot);
  872. }
  873. }
  874. /***************************************************************************
  875. * REPEATED GETTER METHODS
  876. ***************************************************************************/
  877. /* Bool */
  878. /**
  879. * Returns an Array instance containing boolean values for the given field
  880. * number.
  881. * @param {number} fieldNumber
  882. * @return {!Array<boolean>}
  883. * @private
  884. */
  885. getRepeatedBoolArray_(fieldNumber) {
  886. return this.getFieldWithDefault_(
  887. fieldNumber, /* defaultValue= */[],
  888. (indexArray, bytes) => readRepeatedPrimitive(
  889. indexArray, bytes, reader.readBool, reader.readPackedBool,
  890. WireType.VARINT));
  891. }
  892. /**
  893. * Returns the element at index for the given field number.
  894. * @param {number} fieldNumber
  895. * @param {number} index
  896. * @return {boolean}
  897. */
  898. getRepeatedBoolElement(fieldNumber, index) {
  899. const array = this.getRepeatedBoolArray_(fieldNumber);
  900. checkCriticalElementIndex(index, array.length);
  901. return array[index];
  902. }
  903. /**
  904. * Returns an Iterable instance containing boolean values for the given field
  905. * number.
  906. * @param {number} fieldNumber
  907. * @return {!Iterable<boolean>}
  908. */
  909. getRepeatedBoolIterable(fieldNumber) {
  910. // Don't split this statement unless needed. JS compiler thinks
  911. // getRepeatedBoolArray_ might have side effects and doesn't inline the
  912. // call in the compiled code. See cl/293894484 for details.
  913. return new ArrayIterable(this.getRepeatedBoolArray_(fieldNumber));
  914. }
  915. /**
  916. * Returns the size of the repeated field.
  917. * @param {number} fieldNumber
  918. * @return {number}
  919. */
  920. getRepeatedBoolSize(fieldNumber) {
  921. return this.getRepeatedBoolArray_(fieldNumber).length;
  922. }
  923. /* Double */
  924. /**
  925. * Returns an Array instance containing double values for the given field
  926. * number.
  927. * @param {number} fieldNumber
  928. * @return {!Array<number>}
  929. * @private
  930. */
  931. getRepeatedDoubleArray_(fieldNumber) {
  932. return this.getFieldWithDefault_(
  933. fieldNumber, /* defaultValue= */[],
  934. (indexArray, bytes) => readRepeatedPrimitive(
  935. indexArray, bytes, reader.readDouble, reader.readPackedDouble,
  936. WireType.FIXED64));
  937. }
  938. /**
  939. * Returns the element at index for the given field number.
  940. * @param {number} fieldNumber
  941. * @param {number} index
  942. * @return {number}
  943. */
  944. getRepeatedDoubleElement(fieldNumber, index) {
  945. const array = this.getRepeatedDoubleArray_(fieldNumber);
  946. checkCriticalElementIndex(index, array.length);
  947. return array[index];
  948. }
  949. /**
  950. * Returns an Iterable instance containing double values for the given field
  951. * number.
  952. * @param {number} fieldNumber
  953. * @return {!Iterable<number>}
  954. */
  955. getRepeatedDoubleIterable(fieldNumber) {
  956. // Don't split this statement unless needed. JS compiler thinks
  957. // getRepeatedDoubleArray_ might have side effects and doesn't inline the
  958. // call in the compiled code. See cl/293894484 for details.
  959. return new ArrayIterable(this.getRepeatedDoubleArray_(fieldNumber));
  960. }
  961. /**
  962. * Returns the size of the repeated field.
  963. * @param {number} fieldNumber
  964. * @return {number}
  965. */
  966. getRepeatedDoubleSize(fieldNumber) {
  967. return this.getRepeatedDoubleArray_(fieldNumber).length;
  968. }
  969. /* Fixed32 */
  970. /**
  971. * Returns an Array instance containing fixed32 values for the given field
  972. * number.
  973. * @param {number} fieldNumber
  974. * @return {!Array<number>}
  975. * @private
  976. */
  977. getRepeatedFixed32Array_(fieldNumber) {
  978. return this.getFieldWithDefault_(
  979. fieldNumber, /* defaultValue= */[],
  980. (indexArray, bytes) => readRepeatedPrimitive(
  981. indexArray, bytes, reader.readFixed32, reader.readPackedFixed32,
  982. WireType.FIXED32));
  983. }
  984. /**
  985. * Returns the element at index for the given field number.
  986. * @param {number} fieldNumber
  987. * @param {number} index
  988. * @return {number}
  989. */
  990. getRepeatedFixed32Element(fieldNumber, index) {
  991. const array = this.getRepeatedFixed32Array_(fieldNumber);
  992. checkCriticalElementIndex(index, array.length);
  993. return array[index];
  994. }
  995. /**
  996. * Returns an Iterable instance containing fixed32 values for the given field
  997. * number.
  998. * @param {number} fieldNumber
  999. * @return {!Iterable<number>}
  1000. */
  1001. getRepeatedFixed32Iterable(fieldNumber) {
  1002. // Don't split this statement unless needed. JS compiler thinks
  1003. // getRepeatedFixed32Array_ might have side effects and doesn't inline the
  1004. // call in the compiled code. See cl/293894484 for details.
  1005. return new ArrayIterable(this.getRepeatedFixed32Array_(fieldNumber));
  1006. }
  1007. /**
  1008. * Returns the size of the repeated field.
  1009. * @param {number} fieldNumber
  1010. * @return {number}
  1011. */
  1012. getRepeatedFixed32Size(fieldNumber) {
  1013. return this.getRepeatedFixed32Array_(fieldNumber).length;
  1014. }
  1015. /* Fixed64 */
  1016. /**
  1017. * Returns the element at index for the given field number.
  1018. * @param {number} fieldNumber
  1019. * @param {number} index
  1020. * @return {!Int64}
  1021. */
  1022. getRepeatedFixed64Element(fieldNumber, index) {
  1023. return this.getRepeatedSfixed64Element(fieldNumber, index);
  1024. }
  1025. /**
  1026. * Returns an Iterable instance containing fixed64 values for the given field
  1027. * number.
  1028. * @param {number} fieldNumber
  1029. * @return {!Iterable<!Int64>}
  1030. */
  1031. getRepeatedFixed64Iterable(fieldNumber) {
  1032. return this.getRepeatedSfixed64Iterable(fieldNumber);
  1033. }
  1034. /**
  1035. * Returns the size of the repeated field.
  1036. * @param {number} fieldNumber
  1037. * @return {number}
  1038. */
  1039. getRepeatedFixed64Size(fieldNumber) {
  1040. return this.getRepeatedSfixed64Size(fieldNumber);
  1041. }
  1042. /* Float */
  1043. /**
  1044. * Returns an Array instance containing float values for the given field
  1045. * number.
  1046. * @param {number} fieldNumber
  1047. * @return {!Array<number>}
  1048. * @private
  1049. */
  1050. getRepeatedFloatArray_(fieldNumber) {
  1051. return this.getFieldWithDefault_(
  1052. fieldNumber, /* defaultValue= */[],
  1053. (indexArray, bytes) => readRepeatedPrimitive(
  1054. indexArray, bytes, reader.readFloat, reader.readPackedFloat,
  1055. WireType.FIXED32));
  1056. }
  1057. /**
  1058. * Returns the element at index for the given field number.
  1059. * @param {number} fieldNumber
  1060. * @param {number} index
  1061. * @return {number}
  1062. */
  1063. getRepeatedFloatElement(fieldNumber, index) {
  1064. const array = this.getRepeatedFloatArray_(fieldNumber);
  1065. checkCriticalElementIndex(index, array.length);
  1066. return array[index];
  1067. }
  1068. /**
  1069. * Returns an Iterable instance containing float values for the given field
  1070. * number.
  1071. * @param {number} fieldNumber
  1072. * @return {!Iterable<number>}
  1073. */
  1074. getRepeatedFloatIterable(fieldNumber) {
  1075. // Don't split this statement unless needed. JS compiler thinks
  1076. // getRepeatedFloatArray_ might have side effects and doesn't inline the
  1077. // call in the compiled code. See cl/293894484 for details.
  1078. return new ArrayIterable(this.getRepeatedFloatArray_(fieldNumber));
  1079. }
  1080. /**
  1081. * Returns the size of the repeated field.
  1082. * @param {number} fieldNumber
  1083. * @return {number}
  1084. */
  1085. getRepeatedFloatSize(fieldNumber) {
  1086. return this.getRepeatedFloatArray_(fieldNumber).length;
  1087. }
  1088. /* Int32 */
  1089. /**
  1090. * Returns an Array instance containing int32 values for the given field
  1091. * number.
  1092. * @param {number} fieldNumber
  1093. * @return {!Array<number>}
  1094. * @private
  1095. */
  1096. getRepeatedInt32Array_(fieldNumber) {
  1097. return this.getFieldWithDefault_(
  1098. fieldNumber, /* defaultValue= */[],
  1099. (indexArray, bytes) => readRepeatedPrimitive(
  1100. indexArray, bytes, reader.readInt32, reader.readPackedInt32,
  1101. WireType.VARINT));
  1102. }
  1103. /**
  1104. * Returns the element at index for the given field number.
  1105. * @param {number} fieldNumber
  1106. * @param {number} index
  1107. * @return {number}
  1108. */
  1109. getRepeatedInt32Element(fieldNumber, index) {
  1110. const array = this.getRepeatedInt32Array_(fieldNumber);
  1111. checkCriticalElementIndex(index, array.length);
  1112. return array[index];
  1113. }
  1114. /**
  1115. * Returns an Iterable instance containing int32 values for the given field
  1116. * number.
  1117. * @param {number} fieldNumber
  1118. * @return {!Iterable<number>}
  1119. */
  1120. getRepeatedInt32Iterable(fieldNumber) {
  1121. // Don't split this statement unless needed. JS compiler thinks
  1122. // getRepeatedInt32Array_ might have side effects and doesn't inline the
  1123. // call in the compiled code. See cl/293894484 for details.
  1124. return new ArrayIterable(this.getRepeatedInt32Array_(fieldNumber));
  1125. }
  1126. /**
  1127. * Returns the size of the repeated field.
  1128. * @param {number} fieldNumber
  1129. * @return {number}
  1130. */
  1131. getRepeatedInt32Size(fieldNumber) {
  1132. return this.getRepeatedInt32Array_(fieldNumber).length;
  1133. }
  1134. /* Int64 */
  1135. /**
  1136. * Returns an Array instance containing int64 values for the given field
  1137. * number.
  1138. * @param {number} fieldNumber
  1139. * @return {!Array<!Int64>}
  1140. * @private
  1141. */
  1142. getRepeatedInt64Array_(fieldNumber) {
  1143. return this.getFieldWithDefault_(
  1144. fieldNumber, /* defaultValue= */[],
  1145. (indexArray, bytes) => readRepeatedPrimitive(
  1146. indexArray, bytes, reader.readInt64, reader.readPackedInt64,
  1147. WireType.VARINT));
  1148. }
  1149. /**
  1150. * Returns the element at index for the given field number.
  1151. * @param {number} fieldNumber
  1152. * @param {number} index
  1153. * @return {!Int64}
  1154. */
  1155. getRepeatedInt64Element(fieldNumber, index) {
  1156. const array = this.getRepeatedInt64Array_(fieldNumber);
  1157. checkCriticalElementIndex(index, array.length);
  1158. return array[index];
  1159. }
  1160. /**
  1161. * Returns an Iterable instance containing int64 values for the given field
  1162. * number.
  1163. * @param {number} fieldNumber
  1164. * @return {!Iterable<!Int64>}
  1165. */
  1166. getRepeatedInt64Iterable(fieldNumber) {
  1167. // Don't split this statement unless needed. JS compiler thinks
  1168. // getRepeatedInt64Array_ might have side effects and doesn't inline the
  1169. // call in the compiled code. See cl/293894484 for details.
  1170. return new ArrayIterable(this.getRepeatedInt64Array_(fieldNumber));
  1171. }
  1172. /**
  1173. * Returns the size of the repeated field.
  1174. * @param {number} fieldNumber
  1175. * @return {number}
  1176. */
  1177. getRepeatedInt64Size(fieldNumber) {
  1178. return this.getRepeatedInt64Array_(fieldNumber).length;
  1179. }
  1180. /* Sfixed32 */
  1181. /**
  1182. * Returns an Array instance containing sfixed32 values for the given field
  1183. * number.
  1184. * @param {number} fieldNumber
  1185. * @return {!Array<number>}
  1186. * @private
  1187. */
  1188. getRepeatedSfixed32Array_(fieldNumber) {
  1189. return this.getFieldWithDefault_(
  1190. fieldNumber, /* defaultValue= */[],
  1191. (indexArray, bytes) => readRepeatedPrimitive(
  1192. indexArray, bytes, reader.readSfixed32, reader.readPackedSfixed32,
  1193. WireType.FIXED32));
  1194. }
  1195. /**
  1196. * Returns the element at index for the given field number.
  1197. * @param {number} fieldNumber
  1198. * @param {number} index
  1199. * @return {number}
  1200. */
  1201. getRepeatedSfixed32Element(fieldNumber, index) {
  1202. const array = this.getRepeatedSfixed32Array_(fieldNumber);
  1203. checkCriticalElementIndex(index, array.length);
  1204. return array[index];
  1205. }
  1206. /**
  1207. * Returns an Iterable instance containing sfixed32 values for the given field
  1208. * number.
  1209. * @param {number} fieldNumber
  1210. * @return {!Iterable<number>}
  1211. */
  1212. getRepeatedSfixed32Iterable(fieldNumber) {
  1213. // Don't split this statement unless needed. JS compiler thinks
  1214. // getRepeatedSfixed32Array_ might have side effects and doesn't inline the
  1215. // call in the compiled code. See cl/293894484 for details.
  1216. return new ArrayIterable(this.getRepeatedSfixed32Array_(fieldNumber));
  1217. }
  1218. /**
  1219. * Returns the size of the repeated field.
  1220. * @param {number} fieldNumber
  1221. * @return {number}
  1222. */
  1223. getRepeatedSfixed32Size(fieldNumber) {
  1224. return this.getRepeatedSfixed32Array_(fieldNumber).length;
  1225. }
  1226. /* Sfixed64 */
  1227. /**
  1228. * Returns an Array instance containing sfixed64 values for the given field
  1229. * number.
  1230. * @param {number} fieldNumber
  1231. * @return {!Array<!Int64>}
  1232. * @private
  1233. */
  1234. getRepeatedSfixed64Array_(fieldNumber) {
  1235. return this.getFieldWithDefault_(
  1236. fieldNumber, /* defaultValue= */[],
  1237. (indexArray, bytes) => readRepeatedPrimitive(
  1238. indexArray, bytes, reader.readSfixed64, reader.readPackedSfixed64,
  1239. WireType.FIXED64));
  1240. }
  1241. /**
  1242. * Returns the element at index for the given field number.
  1243. * @param {number} fieldNumber
  1244. * @param {number} index
  1245. * @return {!Int64}
  1246. */
  1247. getRepeatedSfixed64Element(fieldNumber, index) {
  1248. const array = this.getRepeatedSfixed64Array_(fieldNumber);
  1249. checkCriticalElementIndex(index, array.length);
  1250. return array[index];
  1251. }
  1252. /**
  1253. * Returns an Iterable instance containing sfixed64 values for the given field
  1254. * number.
  1255. * @param {number} fieldNumber
  1256. * @return {!Iterable<!Int64>}
  1257. */
  1258. getRepeatedSfixed64Iterable(fieldNumber) {
  1259. // Don't split this statement unless needed. JS compiler thinks
  1260. // getRepeatedSfixed64Array_ might have side effects and doesn't inline the
  1261. // call in the compiled code. See cl/293894484 for details.
  1262. return new ArrayIterable(this.getRepeatedSfixed64Array_(fieldNumber));
  1263. }
  1264. /**
  1265. * Returns the size of the repeated field.
  1266. * @param {number} fieldNumber
  1267. * @return {number}
  1268. */
  1269. getRepeatedSfixed64Size(fieldNumber) {
  1270. return this.getRepeatedSfixed64Array_(fieldNumber).length;
  1271. }
  1272. /* Sint32 */
  1273. /**
  1274. * Returns an Array instance containing sint32 values for the given field
  1275. * number.
  1276. * @param {number} fieldNumber
  1277. * @return {!Array<number>}
  1278. * @private
  1279. */
  1280. getRepeatedSint32Array_(fieldNumber) {
  1281. return this.getFieldWithDefault_(
  1282. fieldNumber, /* defaultValue= */[],
  1283. (indexArray, bytes) => readRepeatedPrimitive(
  1284. indexArray, bytes, reader.readSint32, reader.readPackedSint32,
  1285. WireType.VARINT));
  1286. }
  1287. /**
  1288. * Returns the element at index for the given field number.
  1289. * @param {number} fieldNumber
  1290. * @param {number} index
  1291. * @return {number}
  1292. */
  1293. getRepeatedSint32Element(fieldNumber, index) {
  1294. const array = this.getRepeatedSint32Array_(fieldNumber);
  1295. checkCriticalElementIndex(index, array.length);
  1296. return array[index];
  1297. }
  1298. /**
  1299. * Returns an Iterable instance containing sint32 values for the given field
  1300. * number.
  1301. * @param {number} fieldNumber
  1302. * @return {!Iterable<number>}
  1303. */
  1304. getRepeatedSint32Iterable(fieldNumber) {
  1305. // Don't split this statement unless needed. JS compiler thinks
  1306. // getRepeatedSint32Array_ might have side effects and doesn't inline the
  1307. // call in the compiled code. See cl/293894484 for details.
  1308. return new ArrayIterable(this.getRepeatedSint32Array_(fieldNumber));
  1309. }
  1310. /**
  1311. * Returns the size of the repeated field.
  1312. * @param {number} fieldNumber
  1313. * @return {number}
  1314. */
  1315. getRepeatedSint32Size(fieldNumber) {
  1316. return this.getRepeatedSint32Array_(fieldNumber).length;
  1317. }
  1318. /* Sint64 */
  1319. /**
  1320. * Returns an Array instance containing sint64 values for the given field
  1321. * number.
  1322. * @param {number} fieldNumber
  1323. * @return {!Array<!Int64>}
  1324. * @private
  1325. */
  1326. getRepeatedSint64Array_(fieldNumber) {
  1327. return this.getFieldWithDefault_(
  1328. fieldNumber, /* defaultValue= */[],
  1329. (indexArray, bytes) => readRepeatedPrimitive(
  1330. indexArray, bytes, reader.readSint64, reader.readPackedSint64,
  1331. WireType.VARINT));
  1332. }
  1333. /**
  1334. * Returns the element at index for the given field number.
  1335. * @param {number} fieldNumber
  1336. * @param {number} index
  1337. * @return {!Int64}
  1338. */
  1339. getRepeatedSint64Element(fieldNumber, index) {
  1340. const array = this.getRepeatedSint64Array_(fieldNumber);
  1341. checkCriticalElementIndex(index, array.length);
  1342. return array[index];
  1343. }
  1344. /**
  1345. * Returns an Iterable instance containing sint64 values for the given field
  1346. * number.
  1347. * @param {number} fieldNumber
  1348. * @return {!Iterable<!Int64>}
  1349. */
  1350. getRepeatedSint64Iterable(fieldNumber) {
  1351. // Don't split this statement unless needed. JS compiler thinks
  1352. // getRepeatedSint64Array_ might have side effects and doesn't inline the
  1353. // call in the compiled code. See cl/293894484 for details.
  1354. return new ArrayIterable(this.getRepeatedSint64Array_(fieldNumber));
  1355. }
  1356. /**
  1357. * Returns the size of the repeated field.
  1358. * @param {number} fieldNumber
  1359. * @return {number}
  1360. */
  1361. getRepeatedSint64Size(fieldNumber) {
  1362. return this.getRepeatedSint64Array_(fieldNumber).length;
  1363. }
  1364. /* Uint32 */
  1365. /**
  1366. * Returns an Array instance containing uint32 values for the given field
  1367. * number.
  1368. * @param {number} fieldNumber
  1369. * @return {!Array<number>}
  1370. * @private
  1371. */
  1372. getRepeatedUint32Array_(fieldNumber) {
  1373. return this.getFieldWithDefault_(
  1374. fieldNumber, /* defaultValue= */[],
  1375. (indexArray, bytes) => readRepeatedPrimitive(
  1376. indexArray, bytes, reader.readUint32, reader.readPackedUint32,
  1377. WireType.VARINT));
  1378. }
  1379. /**
  1380. * Returns the element at index for the given field number.
  1381. * @param {number} fieldNumber
  1382. * @param {number} index
  1383. * @return {number}
  1384. */
  1385. getRepeatedUint32Element(fieldNumber, index) {
  1386. const array = this.getRepeatedUint32Array_(fieldNumber);
  1387. checkCriticalElementIndex(index, array.length);
  1388. return array[index];
  1389. }
  1390. /**
  1391. * Returns an Iterable instance containing uint32 values for the given field
  1392. * number.
  1393. * @param {number} fieldNumber
  1394. * @return {!Iterable<number>}
  1395. */
  1396. getRepeatedUint32Iterable(fieldNumber) {
  1397. // Don't split this statement unless needed. JS compiler thinks
  1398. // getRepeatedUint32Array_ might have side effects and doesn't inline the
  1399. // call in the compiled code. See cl/293894484 for details.
  1400. return new ArrayIterable(this.getRepeatedUint32Array_(fieldNumber));
  1401. }
  1402. /**
  1403. * Returns the size of the repeated field.
  1404. * @param {number} fieldNumber
  1405. * @return {number}
  1406. */
  1407. getRepeatedUint32Size(fieldNumber) {
  1408. return this.getRepeatedUint32Array_(fieldNumber).length;
  1409. }
  1410. /* Uint64 */
  1411. /**
  1412. * Returns the element at index for the given field number.
  1413. * @param {number} fieldNumber
  1414. * @param {number} index
  1415. * @return {!Int64}
  1416. */
  1417. getRepeatedUint64Element(fieldNumber, index) {
  1418. return this.getRepeatedInt64Element(fieldNumber, index);
  1419. }
  1420. /**
  1421. * Returns an Iterable instance containing uint64 values for the given field
  1422. * number.
  1423. * @param {number} fieldNumber
  1424. * @return {!Iterable<!Int64>}
  1425. */
  1426. getRepeatedUint64Iterable(fieldNumber) {
  1427. return this.getRepeatedInt64Iterable(fieldNumber);
  1428. }
  1429. /**
  1430. * Returns the size of the repeated field.
  1431. * @param {number} fieldNumber
  1432. * @return {number}
  1433. */
  1434. getRepeatedUint64Size(fieldNumber) {
  1435. return this.getRepeatedInt64Size(fieldNumber);
  1436. }
  1437. /* Bytes */
  1438. /**
  1439. * Returns an array instance containing bytes values for the given field
  1440. * number.
  1441. * @param {number} fieldNumber
  1442. * @return {!Array<!ByteString>}
  1443. * @private
  1444. */
  1445. getRepeatedBytesArray_(fieldNumber) {
  1446. return this.getFieldWithDefault_(
  1447. fieldNumber, /* defaultValue= */[],
  1448. (indexArray, bytes) =>
  1449. readRepeatedNonPrimitive(indexArray, bytes, reader.readBytes));
  1450. }
  1451. /**
  1452. * Returns the element at index for the given field number as a bytes.
  1453. * @param {number} fieldNumber
  1454. * @param {number} index
  1455. * @return {!ByteString}
  1456. */
  1457. getRepeatedBytesElement(fieldNumber, index) {
  1458. const array = this.getRepeatedBytesArray_(fieldNumber);
  1459. checkCriticalElementIndex(index, array.length);
  1460. return array[index];
  1461. }
  1462. /**
  1463. * Returns an Iterable instance containing bytes values for the given field
  1464. * number.
  1465. * @param {number} fieldNumber
  1466. * @return {!Iterable<!ByteString>}
  1467. */
  1468. getRepeatedBytesIterable(fieldNumber) {
  1469. // Don't split this statement unless needed. JS compiler thinks
  1470. // getRepeatedBytesArray_ might have side effects and doesn't inline the
  1471. // call in the compiled code. See cl/293894484 for details.
  1472. return new ArrayIterable(this.getRepeatedBytesArray_(fieldNumber));
  1473. }
  1474. /**
  1475. * Returns the size of the repeated field.
  1476. * @param {number} fieldNumber
  1477. * @return {number}
  1478. */
  1479. getRepeatedBytesSize(fieldNumber) {
  1480. return this.getRepeatedBytesArray_(fieldNumber).length;
  1481. }
  1482. /* String */
  1483. /**
  1484. * Returns an array instance containing string values for the given field
  1485. * number.
  1486. * @param {number} fieldNumber
  1487. * @return {!Array<string>}
  1488. * @private
  1489. */
  1490. getRepeatedStringArray_(fieldNumber) {
  1491. return this.getFieldWithDefault_(
  1492. fieldNumber, /* defaultValue= */[],
  1493. (indexArray, bufferDecoder) => readRepeatedNonPrimitive(
  1494. indexArray, bufferDecoder, reader.readString));
  1495. }
  1496. /**
  1497. * Returns the element at index for the given field number as a string.
  1498. * @param {number} fieldNumber
  1499. * @param {number} index
  1500. * @return {string}
  1501. */
  1502. getRepeatedStringElement(fieldNumber, index) {
  1503. const array = this.getRepeatedStringArray_(fieldNumber);
  1504. checkCriticalElementIndex(index, array.length);
  1505. return array[index];
  1506. }
  1507. /**
  1508. * Returns an Iterable instance containing string values for the given field
  1509. * number.
  1510. * @param {number} fieldNumber
  1511. * @return {!Iterable<string>}
  1512. */
  1513. getRepeatedStringIterable(fieldNumber) {
  1514. // Don't split this statement unless needed. JS compiler thinks
  1515. // getRepeatedStringArray_ might have side effects and doesn't inline the
  1516. // call in the compiled code. See cl/293894484 for details.
  1517. return new ArrayIterable(this.getRepeatedStringArray_(fieldNumber));
  1518. }
  1519. /**
  1520. * Returns the size of the repeated field.
  1521. * @param {number} fieldNumber
  1522. * @return {number}
  1523. */
  1524. getRepeatedStringSize(fieldNumber) {
  1525. return this.getRepeatedStringArray_(fieldNumber).length;
  1526. }
  1527. /* Message */
  1528. /**
  1529. * Returns an Array instance containing boolean values for the given field
  1530. * number.
  1531. * @param {number} fieldNumber
  1532. * @param {function(!Kernel):T} instanceCreator
  1533. * @param {number|undefined} pivot
  1534. * @return {!Array<T>}
  1535. * @template T
  1536. * @private
  1537. */
  1538. getRepeatedMessageArray_(fieldNumber, instanceCreator, pivot) {
  1539. // This method can be shortened using getFieldWithDefault and
  1540. // getRepeatedNonPrimitive methods. But that will require creating and
  1541. // passing a reader closure every time getRepeatedMessageArray_ is called,
  1542. // which is expensive.
  1543. checkInstanceCreator(instanceCreator);
  1544. checkFieldNumber(fieldNumber);
  1545. const field = this.fields_.get(fieldNumber);
  1546. if (field === undefined) {
  1547. return [];
  1548. }
  1549. if (field.hasDecodedValue()) {
  1550. return field.getDecodedValue();
  1551. }
  1552. const indexArray = checkDefAndNotNull(field.getIndexArray());
  1553. const result = new Array(indexArray.length);
  1554. for (let i = 0; i < indexArray.length; i++) {
  1555. validateWireType(indexArray[i], WireType.DELIMITED);
  1556. const subMessageBuffer = reader.readDelimited(
  1557. checkDefAndNotNull(this.bufferDecoder_),
  1558. Field.getStartIndex(indexArray[i]));
  1559. result[i] =
  1560. instanceCreator(Kernel.fromBufferDecoder_(subMessageBuffer, pivot));
  1561. }
  1562. field.setCache(result, writeRepeatedMessage);
  1563. return result;
  1564. }
  1565. /**
  1566. * Returns the element at index for the given field number as a message.
  1567. * @param {number} fieldNumber
  1568. * @param {function(!Kernel):T} instanceCreator
  1569. * @param {number} index
  1570. * @param {number=} pivot
  1571. * @return {T}
  1572. * @template T
  1573. */
  1574. getRepeatedMessageElement(
  1575. fieldNumber, instanceCreator, index, pivot = undefined) {
  1576. const array =
  1577. this.getRepeatedMessageArray_(fieldNumber, instanceCreator, pivot);
  1578. checkCriticalElementIndex(index, array.length);
  1579. return array[index];
  1580. }
  1581. /**
  1582. * Returns an Iterable instance containing message values for the given field
  1583. * number.
  1584. * @param {number} fieldNumber
  1585. * @param {function(!Kernel):T} instanceCreator
  1586. * @param {number=} pivot
  1587. * @return {!Iterable<T>}
  1588. * @template T
  1589. */
  1590. getRepeatedMessageIterable(fieldNumber, instanceCreator, pivot = undefined) {
  1591. // Don't split this statement unless needed. JS compiler thinks
  1592. // getRepeatedMessageArray_ might have side effects and doesn't inline the
  1593. // call in the compiled code. See cl/293894484 for details.
  1594. return new ArrayIterable(
  1595. this.getRepeatedMessageArray_(fieldNumber, instanceCreator, pivot));
  1596. }
  1597. /**
  1598. * Returns an Iterable instance containing message accessors for the given
  1599. * field number.
  1600. * @param {number} fieldNumber
  1601. * @param {number=} pivot
  1602. * @return {!Iterable<!Kernel>}
  1603. */
  1604. getRepeatedMessageAccessorIterable(fieldNumber, pivot = undefined) {
  1605. checkFieldNumber(fieldNumber);
  1606. const field = this.fields_.get(fieldNumber);
  1607. if (!field) {
  1608. return [];
  1609. }
  1610. if (field.hasDecodedValue()) {
  1611. return new ArrayIterable(field.getDecodedValue().map(
  1612. value => checkIsInternalMessage(value).internalGetKernel()));
  1613. }
  1614. const readMessageFunc = (bufferDecoder, start) => Kernel.fromBufferDecoder_(
  1615. reader.readDelimited(bufferDecoder, start), pivot);
  1616. const array = readRepeatedNonPrimitive(
  1617. checkDefAndNotNull(field.getIndexArray()),
  1618. checkDefAndNotNull(this.bufferDecoder_), readMessageFunc);
  1619. return new ArrayIterable(array);
  1620. }
  1621. /**
  1622. * Returns the size of the repeated field.
  1623. * @param {number} fieldNumber
  1624. * @param {function(!Kernel):T} instanceCreator
  1625. * @return {number}
  1626. * @param {number=} pivot
  1627. * @template T
  1628. */
  1629. getRepeatedMessageSize(fieldNumber, instanceCreator, pivot = undefined) {
  1630. return this.getRepeatedMessageArray_(fieldNumber, instanceCreator, pivot)
  1631. .length;
  1632. }
  1633. /**
  1634. * Returns an Array instance containing boolean values for the given field
  1635. * number.
  1636. * @param {number} fieldNumber
  1637. * @param {function(!Kernel):T} instanceCreator
  1638. * @param {number|undefined} pivot
  1639. * @return {!Array<T>}
  1640. * @template T
  1641. * @private
  1642. */
  1643. getRepeatedGroupArray_(fieldNumber, instanceCreator, pivot) {
  1644. return this.getFieldWithDefault_(
  1645. fieldNumber, [],
  1646. (indexArray, bufferDecoder) => readRepeatedGroup(
  1647. indexArray, bufferDecoder, fieldNumber, instanceCreator, pivot),
  1648. writeRepeatedGroup);
  1649. }
  1650. /**
  1651. * Returns the element at index for the given field number as a group.
  1652. * @param {number} fieldNumber
  1653. * @param {function(!Kernel):T} instanceCreator
  1654. * @param {number} index
  1655. * @param {number=} pivot
  1656. * @return {T}
  1657. * @template T
  1658. */
  1659. getRepeatedGroupElement(
  1660. fieldNumber, instanceCreator, index, pivot = undefined) {
  1661. const array =
  1662. this.getRepeatedGroupArray_(fieldNumber, instanceCreator, pivot);
  1663. checkCriticalElementIndex(index, array.length);
  1664. return array[index];
  1665. }
  1666. /**
  1667. * Returns an Iterable instance containing group values for the given field
  1668. * number.
  1669. * @param {number} fieldNumber
  1670. * @param {function(!Kernel):T} instanceCreator
  1671. * @param {number=} pivot
  1672. * @return {!Iterable<T>}
  1673. * @template T
  1674. */
  1675. getRepeatedGroupIterable(fieldNumber, instanceCreator, pivot = undefined) {
  1676. // Don't split this statement unless needed. JS compiler thinks
  1677. // getRepeatedMessageArray_ might have side effects and doesn't inline the
  1678. // call in the compiled code. See cl/293894484 for details.
  1679. return new ArrayIterable(
  1680. this.getRepeatedGroupArray_(fieldNumber, instanceCreator, pivot));
  1681. }
  1682. /**
  1683. * Returns the size of the repeated field.
  1684. * @param {number} fieldNumber
  1685. * @param {function(!Kernel):T} instanceCreator
  1686. * @return {number}
  1687. * @param {number=} pivot
  1688. * @template T
  1689. */
  1690. getRepeatedGroupSize(fieldNumber, instanceCreator, pivot = undefined) {
  1691. return this.getRepeatedGroupArray_(fieldNumber, instanceCreator, pivot)
  1692. .length;
  1693. }
  1694. /***************************************************************************
  1695. * OPTIONAL SETTER METHODS
  1696. ***************************************************************************/
  1697. /**
  1698. * Sets a boolean value to the field with the given field number.
  1699. * @param {number} fieldNumber
  1700. * @param {boolean} value
  1701. */
  1702. setBool(fieldNumber, value) {
  1703. checkCriticalTypeBool(value);
  1704. this.setField_(fieldNumber, value, (writer, fieldNumber, value) => {
  1705. writer.writeBool(fieldNumber, value);
  1706. });
  1707. }
  1708. /**
  1709. * Sets a boolean value to the field with the given field number.
  1710. * @param {number} fieldNumber
  1711. * @param {!ByteString} value
  1712. */
  1713. setBytes(fieldNumber, value) {
  1714. checkCriticalTypeByteString(value);
  1715. this.setField_(fieldNumber, value, (writer, fieldNumber, value) => {
  1716. writer.writeBytes(fieldNumber, value);
  1717. });
  1718. }
  1719. /**
  1720. * Sets a double value to the field with the given field number.
  1721. * @param {number} fieldNumber
  1722. * @param {number} value
  1723. */
  1724. setDouble(fieldNumber, value) {
  1725. checkCriticalTypeDouble(value);
  1726. this.setField_(fieldNumber, value, (writer, fieldNumber, value) => {
  1727. writer.writeDouble(fieldNumber, value);
  1728. });
  1729. }
  1730. /**
  1731. * Sets a fixed32 value to the field with the given field number.
  1732. * @param {number} fieldNumber
  1733. * @param {number} value
  1734. */
  1735. setFixed32(fieldNumber, value) {
  1736. checkCriticalTypeUnsignedInt32(value);
  1737. this.setField_(fieldNumber, value, (writer, fieldNumber, value) => {
  1738. writer.writeFixed32(fieldNumber, value);
  1739. });
  1740. }
  1741. /**
  1742. * Sets a uint64 value to the field with the given field number.\
  1743. * Note: Since g.m.Long does not support unsigned int64 values we are going
  1744. * the Java route here for now and simply output the number as a signed int64.
  1745. * Users can get to individual bits by themselves.
  1746. * @param {number} fieldNumber
  1747. * @param {!Int64} value
  1748. */
  1749. setFixed64(fieldNumber, value) {
  1750. this.setSfixed64(fieldNumber, value);
  1751. }
  1752. /**
  1753. * Sets a float value to the field with the given field number.
  1754. * @param {number} fieldNumber
  1755. * @param {number} value
  1756. */
  1757. setFloat(fieldNumber, value) {
  1758. checkCriticalTypeFloat(value);
  1759. // Eagerly round to 32-bit precision so that reading back after set will
  1760. // yield the same value a reader will receive after serialization.
  1761. const floatValue = Math.fround(value);
  1762. this.setField_(fieldNumber, floatValue, (writer, fieldNumber, value) => {
  1763. writer.writeFloat(fieldNumber, value);
  1764. });
  1765. }
  1766. /**
  1767. * Sets a int32 value to the field with the given field number.
  1768. * @param {number} fieldNumber
  1769. * @param {number} value
  1770. */
  1771. setInt32(fieldNumber, value) {
  1772. checkCriticalTypeSignedInt32(value);
  1773. this.setField_(fieldNumber, value, (writer, fieldNumber, value) => {
  1774. writer.writeInt32(fieldNumber, value);
  1775. });
  1776. }
  1777. /**
  1778. * Sets a int64 value to the field with the given field number.
  1779. * @param {number} fieldNumber
  1780. * @param {!Int64} value
  1781. */
  1782. setInt64(fieldNumber, value) {
  1783. checkCriticalTypeSignedInt64(value);
  1784. this.setField_(fieldNumber, value, (writer, fieldNumber, value) => {
  1785. writer.writeInt64(fieldNumber, value);
  1786. });
  1787. }
  1788. /**
  1789. * Sets a sfixed32 value to the field with the given field number.
  1790. * @param {number} fieldNumber
  1791. * @param {number} value
  1792. */
  1793. setSfixed32(fieldNumber, value) {
  1794. checkCriticalTypeSignedInt32(value);
  1795. this.setField_(fieldNumber, value, (writer, fieldNumber, value) => {
  1796. writer.writeSfixed32(fieldNumber, value);
  1797. });
  1798. }
  1799. /**
  1800. * Sets a sfixed64 value to the field with the given field number.
  1801. * @param {number} fieldNumber
  1802. * @param {!Int64} value
  1803. */
  1804. setSfixed64(fieldNumber, value) {
  1805. checkCriticalTypeSignedInt64(value);
  1806. this.setField_(fieldNumber, value, (writer, fieldNumber, value) => {
  1807. writer.writeSfixed64(fieldNumber, value);
  1808. });
  1809. }
  1810. /**
  1811. * Sets a sint32 value to the field with the given field number.
  1812. * @param {number} fieldNumber
  1813. * @param {number} value
  1814. */
  1815. setSint32(fieldNumber, value) {
  1816. checkCriticalTypeSignedInt32(value);
  1817. this.setField_(fieldNumber, value, (writer, fieldNumber, value) => {
  1818. writer.writeSint32(fieldNumber, value);
  1819. });
  1820. }
  1821. /**
  1822. * Sets a sint64 value to the field with the given field number.
  1823. * @param {number} fieldNumber
  1824. * @param {!Int64} value
  1825. */
  1826. setSint64(fieldNumber, value) {
  1827. checkCriticalTypeSignedInt64(value);
  1828. this.setField_(fieldNumber, value, (writer, fieldNumber, value) => {
  1829. writer.writeSint64(fieldNumber, value);
  1830. });
  1831. }
  1832. /**
  1833. * Sets a boolean value to the field with the given field number.
  1834. * @param {number} fieldNumber
  1835. * @param {string} value
  1836. */
  1837. setString(fieldNumber, value) {
  1838. checkCriticalTypeString(value);
  1839. this.setField_(fieldNumber, value, (writer, fieldNumber, value) => {
  1840. writer.writeString(fieldNumber, value);
  1841. });
  1842. }
  1843. /**
  1844. * Sets a uint32 value to the field with the given field number.
  1845. * @param {number} fieldNumber
  1846. * @param {number} value
  1847. */
  1848. setUint32(fieldNumber, value) {
  1849. checkCriticalTypeUnsignedInt32(value);
  1850. this.setField_(fieldNumber, value, (writer, fieldNumber, value) => {
  1851. writer.writeUint32(fieldNumber, value);
  1852. });
  1853. }
  1854. /**
  1855. * Sets a uint64 value to the field with the given field number.\
  1856. * Note: Since g.m.Long does not support unsigned int64 values we are going
  1857. * the Java route here for now and simply output the number as a signed int64.
  1858. * Users can get to individual bits by themselves.
  1859. * @param {number} fieldNumber
  1860. * @param {!Int64} value
  1861. */
  1862. setUint64(fieldNumber, value) {
  1863. this.setInt64(fieldNumber, value);
  1864. }
  1865. /**
  1866. * Sets a proto Group to the field with the given field number.
  1867. * Instead of working with the Kernel inside of the message directly, we
  1868. * need the message instance to keep its reference equality for subsequent
  1869. * gettings.
  1870. * @param {number} fieldNumber
  1871. * @param {!InternalMessage} value
  1872. */
  1873. setGroup(fieldNumber, value) {
  1874. checkCriticalType(
  1875. value !== null, 'Given value is not a message instance: null');
  1876. this.setField_(fieldNumber, value, writeGroup);
  1877. }
  1878. /**
  1879. * Sets a proto Message to the field with the given field number.
  1880. * Instead of working with the Kernel inside of the message directly, we
  1881. * need the message instance to keep its reference equality for subsequent
  1882. * gettings.
  1883. * @param {number} fieldNumber
  1884. * @param {!InternalMessage} value
  1885. */
  1886. setMessage(fieldNumber, value) {
  1887. checkCriticalType(
  1888. value !== null, 'Given value is not a message instance: null');
  1889. this.setField_(fieldNumber, value, writeMessage);
  1890. }
  1891. /***************************************************************************
  1892. * REPEATED SETTER METHODS
  1893. ***************************************************************************/
  1894. /* Bool */
  1895. /**
  1896. * Adds all boolean values into the field for the given field number.
  1897. * How these values are encoded depends on the given write function.
  1898. * @param {number} fieldNumber
  1899. * @param {!Iterable<boolean>} values
  1900. * @param {function(!Writer, number, !Array<boolean>): undefined} encoder
  1901. * @private
  1902. */
  1903. addRepeatedBoolIterable_(fieldNumber, values, encoder) {
  1904. const array = [...this.getRepeatedBoolArray_(fieldNumber), ...values];
  1905. checkCriticalTypeBoolArray(array);
  1906. // Needs to set it back because the default empty array was not cached.
  1907. this.setField_(fieldNumber, array, encoder);
  1908. }
  1909. /**
  1910. * Adds a single boolean value into the field for the given field number.
  1911. * All values will be encoded as packed values.
  1912. * @param {number} fieldNumber
  1913. * @param {boolean} value
  1914. */
  1915. addPackedBoolElement(fieldNumber, value) {
  1916. this.addRepeatedBoolIterable_(
  1917. fieldNumber, [value], (writer, fieldNumber, values) => {
  1918. writer.writePackedBool(fieldNumber, values);
  1919. });
  1920. }
  1921. /**
  1922. * Adds all boolean values into the field for the given field number.
  1923. * All these values will be encoded as packed values.
  1924. * @param {number} fieldNumber
  1925. * @param {!Iterable<boolean>} values
  1926. */
  1927. addPackedBoolIterable(fieldNumber, values) {
  1928. this.addRepeatedBoolIterable_(
  1929. fieldNumber, values, (writer, fieldNumber, values) => {
  1930. writer.writePackedBool(fieldNumber, values);
  1931. });
  1932. }
  1933. /**
  1934. * Adds a single boolean value into the field for the given field number.
  1935. * All values will be encoded as unpacked values.
  1936. * @param {number} fieldNumber
  1937. * @param {boolean} value
  1938. */
  1939. addUnpackedBoolElement(fieldNumber, value) {
  1940. this.addRepeatedBoolIterable_(
  1941. fieldNumber, [value], (writer, fieldNumber, values) => {
  1942. writer.writeRepeatedBool(fieldNumber, values);
  1943. });
  1944. }
  1945. /**
  1946. * Adds all boolean values into the field for the given field number.
  1947. * All these values will be encoded as unpacked values.
  1948. * @param {number} fieldNumber
  1949. * @param {!Iterable<boolean>} values
  1950. */
  1951. addUnpackedBoolIterable(fieldNumber, values) {
  1952. this.addRepeatedBoolIterable_(
  1953. fieldNumber, values, (writer, fieldNumber, values) => {
  1954. writer.writeRepeatedBool(fieldNumber, values);
  1955. });
  1956. }
  1957. /**
  1958. * Sets a single boolean value into the field for the given field number at
  1959. * the given index. How these values are encoded depends on the given write
  1960. * function.
  1961. * @param {number} fieldNumber
  1962. * @param {number} index
  1963. * @param {boolean} value
  1964. * @param {function(!Writer, number, !Array<boolean>): undefined} encoder
  1965. * @throws {!Error} if index is out of range when check mode is critical
  1966. * @private
  1967. */
  1968. setRepeatedBoolElement_(fieldNumber, index, value, encoder) {
  1969. checkCriticalTypeBool(value);
  1970. const array = this.getRepeatedBoolArray_(fieldNumber);
  1971. checkCriticalElementIndex(index, array.length);
  1972. array[index] = value;
  1973. // Needs to set it back to set encoder.
  1974. this.setField_(fieldNumber, array, encoder);
  1975. }
  1976. /**
  1977. * Sets a single boolean value into the field for the given field number at
  1978. * the given index. All values will be encoded as packed values.
  1979. * @param {number} fieldNumber
  1980. * @param {number} index
  1981. * @param {boolean} value
  1982. * @throws {!Error} if index is out of range when check mode is critical
  1983. */
  1984. setPackedBoolElement(fieldNumber, index, value) {
  1985. this.setRepeatedBoolElement_(
  1986. fieldNumber, index, value, (writer, fieldNumber, values) => {
  1987. writer.writePackedBool(fieldNumber, values);
  1988. });
  1989. }
  1990. /**
  1991. * Sets all boolean values into the field for the given field number.
  1992. * All these values will be encoded as packed values.
  1993. * @param {number} fieldNumber
  1994. * @param {!Iterable<boolean>} values
  1995. */
  1996. setPackedBoolIterable(fieldNumber, values) {
  1997. const /** !Array<boolean> */ array = Array.from(values);
  1998. checkCriticalTypeBoolArray(array);
  1999. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  2000. writer.writePackedBool(fieldNumber, values);
  2001. });
  2002. }
  2003. /**
  2004. * Sets a single boolean value into the field for the given field number at
  2005. * the given index. All values will be encoded as unpacked values.
  2006. * @param {number} fieldNumber
  2007. * @param {number} index
  2008. * @param {boolean} value
  2009. * @throws {!Error} if index is out of range when check mode is critical
  2010. */
  2011. setUnpackedBoolElement(fieldNumber, index, value) {
  2012. this.setRepeatedBoolElement_(
  2013. fieldNumber, index, value, (writer, fieldNumber, values) => {
  2014. writer.writeRepeatedBool(fieldNumber, values);
  2015. });
  2016. }
  2017. /**
  2018. * Sets all boolean values into the field for the given field number.
  2019. * All these values will be encoded as unpacked values.
  2020. * @param {number} fieldNumber
  2021. * @param {!Iterable<boolean>} values
  2022. */
  2023. setUnpackedBoolIterable(fieldNumber, values) {
  2024. const /** !Array<boolean> */ array = Array.from(values);
  2025. checkCriticalTypeBoolArray(array);
  2026. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  2027. writer.writeRepeatedBool(fieldNumber, values);
  2028. });
  2029. }
  2030. /* Double */
  2031. /**
  2032. * Adds all double values into the field for the given field number.
  2033. * How these values are encoded depends on the given write function.
  2034. * @param {number} fieldNumber
  2035. * @param {!Iterable<number>} values
  2036. * @param {function(!Writer, number, !Array<number>): undefined} encoder
  2037. * @private
  2038. */
  2039. addRepeatedDoubleIterable_(fieldNumber, values, encoder) {
  2040. const array = [...this.getRepeatedDoubleArray_(fieldNumber), ...values];
  2041. checkCriticalTypeDoubleArray(array);
  2042. // Needs to set it back because the default empty array was not cached.
  2043. this.setField_(fieldNumber, array, encoder);
  2044. }
  2045. /**
  2046. * Adds a single double value into the field for the given field number.
  2047. * All values will be encoded as packed values.
  2048. * @param {number} fieldNumber
  2049. * @param {number} value
  2050. */
  2051. addPackedDoubleElement(fieldNumber, value) {
  2052. this.addRepeatedDoubleIterable_(
  2053. fieldNumber, [value], (writer, fieldNumber, values) => {
  2054. writer.writePackedDouble(fieldNumber, values);
  2055. });
  2056. }
  2057. /**
  2058. * Adds all double values into the field for the given field number.
  2059. * All these values will be encoded as packed values.
  2060. * @param {number} fieldNumber
  2061. * @param {!Iterable<number>} values
  2062. */
  2063. addPackedDoubleIterable(fieldNumber, values) {
  2064. this.addRepeatedDoubleIterable_(
  2065. fieldNumber, values, (writer, fieldNumber, values) => {
  2066. writer.writePackedDouble(fieldNumber, values);
  2067. });
  2068. }
  2069. /**
  2070. * Adds a single double value into the field for the given field number.
  2071. * All values will be encoded as unpacked values.
  2072. * @param {number} fieldNumber
  2073. * @param {number} value
  2074. */
  2075. addUnpackedDoubleElement(fieldNumber, value) {
  2076. this.addRepeatedDoubleIterable_(
  2077. fieldNumber, [value], (writer, fieldNumber, values) => {
  2078. writer.writeRepeatedDouble(fieldNumber, values);
  2079. });
  2080. }
  2081. /**
  2082. * Adds all double values into the field for the given field number.
  2083. * All these values will be encoded as unpacked values.
  2084. * @param {number} fieldNumber
  2085. * @param {!Iterable<number>} values
  2086. */
  2087. addUnpackedDoubleIterable(fieldNumber, values) {
  2088. this.addRepeatedDoubleIterable_(
  2089. fieldNumber, values, (writer, fieldNumber, values) => {
  2090. writer.writeRepeatedDouble(fieldNumber, values);
  2091. });
  2092. }
  2093. /**
  2094. * Sets a single double value into the field for the given field number at the
  2095. * given index.
  2096. * How these values are encoded depends on the given write function.
  2097. * @param {number} fieldNumber
  2098. * @param {number} index
  2099. * @param {number} value
  2100. * @param {function(!Writer, number, !Array<number>): undefined} encoder
  2101. * @throws {!Error} if index is out of range when check mode is critical
  2102. * @private
  2103. */
  2104. setRepeatedDoubleElement_(fieldNumber, index, value, encoder) {
  2105. checkCriticalTypeDouble(value);
  2106. const array = this.getRepeatedDoubleArray_(fieldNumber);
  2107. checkCriticalElementIndex(index, array.length);
  2108. array[index] = value;
  2109. // Needs to set it back to set encoder.
  2110. this.setField_(fieldNumber, array, encoder);
  2111. }
  2112. /**
  2113. * Sets a single double value into the field for the given field number at the
  2114. * given index.
  2115. * All values will be encoded as packed values.
  2116. * @param {number} fieldNumber
  2117. * @param {number} index
  2118. * @param {number} value
  2119. * @throws {!Error} if index is out of range when check mode is critical
  2120. */
  2121. setPackedDoubleElement(fieldNumber, index, value) {
  2122. this.setRepeatedDoubleElement_(
  2123. fieldNumber, index, value, (writer, fieldNumber, values) => {
  2124. writer.writePackedDouble(fieldNumber, values);
  2125. });
  2126. }
  2127. /**
  2128. * Sets all double values into the field for the given field number.
  2129. * All these values will be encoded as packed values.
  2130. * @param {number} fieldNumber
  2131. * @param {!Iterable<number>} values
  2132. */
  2133. setPackedDoubleIterable(fieldNumber, values) {
  2134. const array = Array.from(values);
  2135. checkCriticalTypeDoubleArray(array);
  2136. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  2137. writer.writePackedDouble(fieldNumber, values);
  2138. });
  2139. }
  2140. /**
  2141. * Sets a single double value into the field for the given field number at the
  2142. * given index.
  2143. * All values will be encoded as unpacked values.
  2144. * @param {number} fieldNumber
  2145. * @param {number} index
  2146. * @param {number} value
  2147. * @throws {!Error} if index is out of range when check mode is critical
  2148. */
  2149. setUnpackedDoubleElement(fieldNumber, index, value) {
  2150. this.setRepeatedDoubleElement_(
  2151. fieldNumber, index, value, (writer, fieldNumber, values) => {
  2152. writer.writeRepeatedDouble(fieldNumber, values);
  2153. });
  2154. }
  2155. /**
  2156. * Sets all double values into the field for the given field number.
  2157. * All these values will be encoded as unpacked values.
  2158. * @param {number} fieldNumber
  2159. * @param {!Iterable<number>} values
  2160. */
  2161. setUnpackedDoubleIterable(fieldNumber, values) {
  2162. const array = Array.from(values);
  2163. checkCriticalTypeDoubleArray(array);
  2164. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  2165. writer.writeRepeatedDouble(fieldNumber, values);
  2166. });
  2167. }
  2168. /* Fixed32 */
  2169. /**
  2170. * Adds all fixed32 values into the field for the given field number.
  2171. * How these values are encoded depends on the given write function.
  2172. * @param {number} fieldNumber
  2173. * @param {!Iterable<number>} values
  2174. * @param {function(!Writer, number, !Array<number>): undefined} encoder
  2175. * @private
  2176. */
  2177. addRepeatedFixed32Iterable_(fieldNumber, values, encoder) {
  2178. const array = [...this.getRepeatedFixed32Array_(fieldNumber), ...values];
  2179. checkCriticalTypeUnsignedInt32Array(array);
  2180. // Needs to set it back because the default empty array was not cached.
  2181. this.setField_(fieldNumber, array, encoder);
  2182. }
  2183. /**
  2184. * Adds a single fixed32 value into the field for the given field number.
  2185. * All values will be encoded as packed values.
  2186. * @param {number} fieldNumber
  2187. * @param {number} value
  2188. */
  2189. addPackedFixed32Element(fieldNumber, value) {
  2190. this.addRepeatedFixed32Iterable_(
  2191. fieldNumber, [value], (writer, fieldNumber, values) => {
  2192. writer.writePackedFixed32(fieldNumber, values);
  2193. });
  2194. }
  2195. /**
  2196. * Adds all fixed32 values into the field for the given field number.
  2197. * All these values will be encoded as packed values.
  2198. * @param {number} fieldNumber
  2199. * @param {!Iterable<number>} values
  2200. */
  2201. addPackedFixed32Iterable(fieldNumber, values) {
  2202. this.addRepeatedFixed32Iterable_(
  2203. fieldNumber, values, (writer, fieldNumber, values) => {
  2204. writer.writePackedFixed32(fieldNumber, values);
  2205. });
  2206. }
  2207. /**
  2208. * Adds a single fixed32 value into the field for the given field number.
  2209. * All values will be encoded as unpacked values.
  2210. * @param {number} fieldNumber
  2211. * @param {number} value
  2212. */
  2213. addUnpackedFixed32Element(fieldNumber, value) {
  2214. this.addRepeatedFixed32Iterable_(
  2215. fieldNumber, [value], (writer, fieldNumber, values) => {
  2216. writer.writeRepeatedFixed32(fieldNumber, values);
  2217. });
  2218. }
  2219. /**
  2220. * Adds all fixed32 values into the field for the given field number.
  2221. * All these values will be encoded as unpacked values.
  2222. * @param {number} fieldNumber
  2223. * @param {!Iterable<number>} values
  2224. */
  2225. addUnpackedFixed32Iterable(fieldNumber, values) {
  2226. this.addRepeatedFixed32Iterable_(
  2227. fieldNumber, values, (writer, fieldNumber, values) => {
  2228. writer.writeRepeatedFixed32(fieldNumber, values);
  2229. });
  2230. }
  2231. /**
  2232. * Sets a single fixed32 value into the field for the given field number at
  2233. * the given index. How these values are encoded depends on the given write
  2234. * function.
  2235. * @param {number} fieldNumber
  2236. * @param {number} index
  2237. * @param {number} value
  2238. * @param {function(!Writer, number, !Array<number>): undefined} encoder
  2239. * @throws {!Error} if index is out of range when check mode is critical
  2240. * @private
  2241. */
  2242. setRepeatedFixed32Element_(fieldNumber, index, value, encoder) {
  2243. checkCriticalTypeUnsignedInt32(value);
  2244. const array = this.getRepeatedFixed32Array_(fieldNumber);
  2245. checkCriticalElementIndex(index, array.length);
  2246. array[index] = value;
  2247. // Needs to set it back to set encoder.
  2248. this.setField_(fieldNumber, array, encoder);
  2249. }
  2250. /**
  2251. * Sets a single fixed32 value into the field for the given field number at
  2252. * the given index. All values will be encoded as packed values.
  2253. * @param {number} fieldNumber
  2254. * @param {number} index
  2255. * @param {number} value
  2256. * @throws {!Error} if index is out of range when check mode is critical
  2257. */
  2258. setPackedFixed32Element(fieldNumber, index, value) {
  2259. this.setRepeatedFixed32Element_(
  2260. fieldNumber, index, value, (writer, fieldNumber, values) => {
  2261. writer.writePackedFixed32(fieldNumber, values);
  2262. });
  2263. }
  2264. /**
  2265. * Sets all fixed32 values into the field for the given field number.
  2266. * All these values will be encoded as packed values.
  2267. * @param {number} fieldNumber
  2268. * @param {!Iterable<number>} values
  2269. */
  2270. setPackedFixed32Iterable(fieldNumber, values) {
  2271. const array = Array.from(values);
  2272. checkCriticalTypeUnsignedInt32Array(array);
  2273. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  2274. writer.writePackedFixed32(fieldNumber, values);
  2275. });
  2276. }
  2277. /**
  2278. * Sets a single fixed32 value into the field for the given field number at
  2279. * the given index. All values will be encoded as unpacked values.
  2280. * @param {number} fieldNumber
  2281. * @param {number} index
  2282. * @param {number} value
  2283. * @throws {!Error} if index is out of range when check mode is critical
  2284. */
  2285. setUnpackedFixed32Element(fieldNumber, index, value) {
  2286. this.setRepeatedFixed32Element_(
  2287. fieldNumber, index, value, (writer, fieldNumber, values) => {
  2288. writer.writeRepeatedFixed32(fieldNumber, values);
  2289. });
  2290. }
  2291. /**
  2292. * Sets all fixed32 values into the field for the given field number.
  2293. * All these values will be encoded as unpacked values.
  2294. * @param {number} fieldNumber
  2295. * @param {!Iterable<number>} values
  2296. */
  2297. setUnpackedFixed32Iterable(fieldNumber, values) {
  2298. const array = Array.from(values);
  2299. checkCriticalTypeUnsignedInt32Array(array);
  2300. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  2301. writer.writeRepeatedFixed32(fieldNumber, values);
  2302. });
  2303. }
  2304. /* Fixed64 */
  2305. /**
  2306. * Adds a single fixed64 value into the field for the given field number.
  2307. * All values will be encoded as packed values.
  2308. * @param {number} fieldNumber
  2309. * @param {!Int64} value
  2310. */
  2311. addPackedFixed64Element(fieldNumber, value) {
  2312. this.addPackedSfixed64Element(fieldNumber, value);
  2313. }
  2314. /**
  2315. * Adds all fixed64 values into the field for the given field number.
  2316. * All these values will be encoded as packed values.
  2317. * @param {number} fieldNumber
  2318. * @param {!Iterable<!Int64>} values
  2319. */
  2320. addPackedFixed64Iterable(fieldNumber, values) {
  2321. this.addPackedSfixed64Iterable(fieldNumber, values);
  2322. }
  2323. /**
  2324. * Adds a single fixed64 value into the field for the given field number.
  2325. * All values will be encoded as unpacked values.
  2326. * @param {number} fieldNumber
  2327. * @param {!Int64} value
  2328. */
  2329. addUnpackedFixed64Element(fieldNumber, value) {
  2330. this.addUnpackedSfixed64Element(fieldNumber, value);
  2331. }
  2332. /**
  2333. * Adds all fixed64 values into the field for the given field number.
  2334. * All these values will be encoded as unpacked values.
  2335. * @param {number} fieldNumber
  2336. * @param {!Iterable<!Int64>} values
  2337. */
  2338. addUnpackedFixed64Iterable(fieldNumber, values) {
  2339. this.addUnpackedSfixed64Iterable(fieldNumber, values);
  2340. }
  2341. /**
  2342. * Sets a single fixed64 value into the field for the given field number at
  2343. * the given index. All values will be encoded as packed values.
  2344. * @param {number} fieldNumber
  2345. * @param {number} index
  2346. * @param {!Int64} value
  2347. * @throws {!Error} if index is out of range when check mode is critical
  2348. */
  2349. setPackedFixed64Element(fieldNumber, index, value) {
  2350. this.setPackedSfixed64Element(fieldNumber, index, value);
  2351. }
  2352. /**
  2353. * Sets all fixed64 values into the field for the given field number.
  2354. * All these values will be encoded as packed values.
  2355. * @param {number} fieldNumber
  2356. * @param {!Iterable<!Int64>} values
  2357. */
  2358. setPackedFixed64Iterable(fieldNumber, values) {
  2359. this.setPackedSfixed64Iterable(fieldNumber, values);
  2360. }
  2361. /**
  2362. * Sets a single fixed64 value into the field for the given field number at
  2363. * the given index. All values will be encoded as unpacked values.
  2364. * @param {number} fieldNumber
  2365. * @param {number} index
  2366. * @param {!Int64} value
  2367. * @throws {!Error} if index is out of range when check mode is critical
  2368. */
  2369. setUnpackedFixed64Element(fieldNumber, index, value) {
  2370. this.setUnpackedSfixed64Element(fieldNumber, index, value);
  2371. }
  2372. /**
  2373. * Sets all fixed64 values into the field for the given field number.
  2374. * All these values will be encoded as unpacked values.
  2375. * @param {number} fieldNumber
  2376. * @param {!Iterable<!Int64>} values
  2377. */
  2378. setUnpackedFixed64Iterable(fieldNumber, values) {
  2379. this.setUnpackedSfixed64Iterable(fieldNumber, values);
  2380. }
  2381. /* Float */
  2382. /**
  2383. * Adds all float values into the field for the given field number.
  2384. * How these values are encoded depends on the given write function.
  2385. * @param {number} fieldNumber
  2386. * @param {!Iterable<number>} values
  2387. * @param {function(!Writer, number, !Array<number>): undefined} encoder
  2388. * @private
  2389. */
  2390. addRepeatedFloatIterable_(fieldNumber, values, encoder) {
  2391. checkCriticalTypeFloatIterable(values);
  2392. // Eagerly round to 32-bit precision so that reading back after set will
  2393. // yield the same value a reader will receive after serialization.
  2394. const floatValues = Array.from(values, fround);
  2395. const array = [...this.getRepeatedFloatArray_(fieldNumber), ...floatValues];
  2396. checkCriticalTypeFloatIterable(array);
  2397. // Needs to set it back because the default empty array was not cached.
  2398. this.setField_(fieldNumber, array, encoder);
  2399. }
  2400. /**
  2401. * Adds a single float value into the field for the given field number.
  2402. * All values will be encoded as packed values.
  2403. * @param {number} fieldNumber
  2404. * @param {number} value
  2405. */
  2406. addPackedFloatElement(fieldNumber, value) {
  2407. this.addRepeatedFloatIterable_(
  2408. fieldNumber, [value], (writer, fieldNumber, values) => {
  2409. writer.writePackedFloat(fieldNumber, values);
  2410. });
  2411. }
  2412. /**
  2413. * Adds all float values into the field for the given field number.
  2414. * All these values will be encoded as packed values.
  2415. * @param {number} fieldNumber
  2416. * @param {!Iterable<number>} values
  2417. */
  2418. addPackedFloatIterable(fieldNumber, values) {
  2419. this.addRepeatedFloatIterable_(
  2420. fieldNumber, values, (writer, fieldNumber, values) => {
  2421. writer.writePackedFloat(fieldNumber, values);
  2422. });
  2423. }
  2424. /**
  2425. * Adds a single float value into the field for the given field number.
  2426. * All values will be encoded as unpacked values.
  2427. * @param {number} fieldNumber
  2428. * @param {number} value
  2429. */
  2430. addUnpackedFloatElement(fieldNumber, value) {
  2431. this.addRepeatedFloatIterable_(
  2432. fieldNumber, [value], (writer, fieldNumber, values) => {
  2433. writer.writeRepeatedFloat(fieldNumber, values);
  2434. });
  2435. }
  2436. /**
  2437. * Adds all float values into the field for the given field number.
  2438. * All these values will be encoded as unpacked values.
  2439. * @param {number} fieldNumber
  2440. * @param {!Iterable<number>} values
  2441. */
  2442. addUnpackedFloatIterable(fieldNumber, values) {
  2443. this.addRepeatedFloatIterable_(
  2444. fieldNumber, values, (writer, fieldNumber, values) => {
  2445. writer.writeRepeatedFloat(fieldNumber, values);
  2446. });
  2447. }
  2448. /**
  2449. * Sets a single float value into the field for the given field number at the
  2450. * given index.
  2451. * How these values are encoded depends on the given write function.
  2452. * @param {number} fieldNumber
  2453. * @param {number} index
  2454. * @param {number} value
  2455. * @param {function(!Writer, number, !Array<number>): undefined} encoder
  2456. * @throws {!Error} if index is out of range when check mode is critical
  2457. * @private
  2458. */
  2459. setRepeatedFloatElement_(fieldNumber, index, value, encoder) {
  2460. checkCriticalTypeFloat(value);
  2461. // Eagerly round to 32-bit precision so that reading back after set will
  2462. // yield the same value a reader will receive after serialization.
  2463. const floatValue = Math.fround(value);
  2464. const array = this.getRepeatedFloatArray_(fieldNumber);
  2465. checkCriticalElementIndex(index, array.length);
  2466. array[index] = floatValue;
  2467. // Needs to set it back to set encoder.
  2468. this.setField_(fieldNumber, array, encoder);
  2469. }
  2470. /**
  2471. * Sets a single float value into the field for the given field number at the
  2472. * given index.
  2473. * All values will be encoded as packed values.
  2474. * @param {number} fieldNumber
  2475. * @param {number} index
  2476. * @param {number} value
  2477. * @throws {!Error} if index is out of range when check mode is critical
  2478. */
  2479. setPackedFloatElement(fieldNumber, index, value) {
  2480. this.setRepeatedFloatElement_(
  2481. fieldNumber, index, value, (writer, fieldNumber, values) => {
  2482. writer.writePackedFloat(fieldNumber, values);
  2483. });
  2484. }
  2485. /**
  2486. * Sets all float values into the field for the given field number.
  2487. * All these values will be encoded as packed values.
  2488. * @param {number} fieldNumber
  2489. * @param {!Iterable<number>} values
  2490. */
  2491. setPackedFloatIterable(fieldNumber, values) {
  2492. checkCriticalTypeFloatIterable(values);
  2493. // Eagerly round to 32-bit precision so that reading back after set will
  2494. // yield the same value a reader will receive after serialization.
  2495. const array = Array.from(values, fround);
  2496. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  2497. writer.writePackedFloat(fieldNumber, values);
  2498. });
  2499. }
  2500. /**
  2501. * Sets a single float value into the field for the given field number at the
  2502. * given index.
  2503. * All values will be encoded as unpacked values.
  2504. * @param {number} fieldNumber
  2505. * @param {number} index
  2506. * @param {number} value
  2507. * @throws {!Error} if index is out of range when check mode is critical
  2508. */
  2509. setUnpackedFloatElement(fieldNumber, index, value) {
  2510. this.setRepeatedFloatElement_(
  2511. fieldNumber, index, value, (writer, fieldNumber, values) => {
  2512. writer.writeRepeatedFloat(fieldNumber, values);
  2513. });
  2514. }
  2515. /**
  2516. * Sets all float values into the field for the given field number.
  2517. * All these values will be encoded as unpacked values.
  2518. * @param {number} fieldNumber
  2519. * @param {!Iterable<number>} values
  2520. */
  2521. setUnpackedFloatIterable(fieldNumber, values) {
  2522. checkCriticalTypeFloatIterable(values);
  2523. // Eagerly round to 32-bit precision so that reading back after set will
  2524. // yield the same value a reader will receive after serialization.
  2525. const array = Array.from(values, fround);
  2526. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  2527. writer.writeRepeatedFloat(fieldNumber, values);
  2528. });
  2529. }
  2530. /* Int32 */
  2531. /**
  2532. * Adds all int32 values into the field for the given field number.
  2533. * How these values are encoded depends on the given write function.
  2534. * @param {number} fieldNumber
  2535. * @param {!Iterable<number>} values
  2536. * @param {function(!Writer, number, !Array<number>): undefined} encoder
  2537. * @private
  2538. */
  2539. addRepeatedInt32Iterable_(fieldNumber, values, encoder) {
  2540. const array = [...this.getRepeatedInt32Array_(fieldNumber), ...values];
  2541. checkCriticalTypeSignedInt32Array(array);
  2542. // Needs to set it back because the default empty array was not cached.
  2543. this.setField_(fieldNumber, array, encoder);
  2544. }
  2545. /**
  2546. * Adds a single int32 value into the field for the given field number.
  2547. * All values will be encoded as packed values.
  2548. * @param {number} fieldNumber
  2549. * @param {number} value
  2550. */
  2551. addPackedInt32Element(fieldNumber, value) {
  2552. this.addRepeatedInt32Iterable_(
  2553. fieldNumber, [value], (writer, fieldNumber, values) => {
  2554. writer.writePackedInt32(fieldNumber, values);
  2555. });
  2556. }
  2557. /**
  2558. * Adds all int32 values into the field for the given field number.
  2559. * All these values will be encoded as packed values.
  2560. * @param {number} fieldNumber
  2561. * @param {!Iterable<number>} values
  2562. */
  2563. addPackedInt32Iterable(fieldNumber, values) {
  2564. this.addRepeatedInt32Iterable_(
  2565. fieldNumber, values, (writer, fieldNumber, values) => {
  2566. writer.writePackedInt32(fieldNumber, values);
  2567. });
  2568. }
  2569. /**
  2570. * Adds a single int32 value into the field for the given field number.
  2571. * All values will be encoded as unpacked values.
  2572. * @param {number} fieldNumber
  2573. * @param {number} value
  2574. */
  2575. addUnpackedInt32Element(fieldNumber, value) {
  2576. this.addRepeatedInt32Iterable_(
  2577. fieldNumber, [value], (writer, fieldNumber, values) => {
  2578. writer.writeRepeatedInt32(fieldNumber, values);
  2579. });
  2580. }
  2581. /**
  2582. * Adds all int32 values into the field for the given field number.
  2583. * All these values will be encoded as unpacked values.
  2584. * @param {number} fieldNumber
  2585. * @param {!Iterable<number>} values
  2586. */
  2587. addUnpackedInt32Iterable(fieldNumber, values) {
  2588. this.addRepeatedInt32Iterable_(
  2589. fieldNumber, values, (writer, fieldNumber, values) => {
  2590. writer.writeRepeatedInt32(fieldNumber, values);
  2591. });
  2592. }
  2593. /**
  2594. * Sets a single int32 value into the field for the given field number at
  2595. * the given index. How these values are encoded depends on the given write
  2596. * function.
  2597. * @param {number} fieldNumber
  2598. * @param {number} index
  2599. * @param {number} value
  2600. * @param {function(!Writer, number, !Array<number>): undefined} encoder
  2601. * @throws {!Error} if index is out of range when check mode is critical
  2602. * @private
  2603. */
  2604. setRepeatedInt32Element_(fieldNumber, index, value, encoder) {
  2605. checkCriticalTypeSignedInt32(value);
  2606. const array = this.getRepeatedInt32Array_(fieldNumber);
  2607. checkCriticalElementIndex(index, array.length);
  2608. array[index] = value;
  2609. // Needs to set it back to set encoder.
  2610. this.setField_(fieldNumber, array, encoder);
  2611. }
  2612. /**
  2613. * Sets a single int32 value into the field for the given field number at
  2614. * the given index. All values will be encoded as packed values.
  2615. * @param {number} fieldNumber
  2616. * @param {number} index
  2617. * @param {number} value
  2618. * @throws {!Error} if index is out of range when check mode is critical
  2619. */
  2620. setPackedInt32Element(fieldNumber, index, value) {
  2621. this.setRepeatedInt32Element_(
  2622. fieldNumber, index, value, (writer, fieldNumber, values) => {
  2623. writer.writePackedInt32(fieldNumber, values);
  2624. });
  2625. }
  2626. /**
  2627. * Sets all int32 values into the field for the given field number.
  2628. * All these values will be encoded as packed values.
  2629. * @param {number} fieldNumber
  2630. * @param {!Iterable<number>} values
  2631. */
  2632. setPackedInt32Iterable(fieldNumber, values) {
  2633. const array = Array.from(values);
  2634. checkCriticalTypeSignedInt32Array(array);
  2635. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  2636. writer.writePackedInt32(fieldNumber, values);
  2637. });
  2638. }
  2639. /**
  2640. * Sets a single int32 value into the field for the given field number at
  2641. * the given index. All values will be encoded as unpacked values.
  2642. * @param {number} fieldNumber
  2643. * @param {number} index
  2644. * @param {number} value
  2645. * @throws {!Error} if index is out of range when check mode is critical
  2646. */
  2647. setUnpackedInt32Element(fieldNumber, index, value) {
  2648. this.setRepeatedInt32Element_(
  2649. fieldNumber, index, value, (writer, fieldNumber, values) => {
  2650. writer.writeRepeatedInt32(fieldNumber, values);
  2651. });
  2652. }
  2653. /**
  2654. * Sets all int32 values into the field for the given field number.
  2655. * All these values will be encoded as unpacked values.
  2656. * @param {number} fieldNumber
  2657. * @param {!Iterable<number>} values
  2658. */
  2659. setUnpackedInt32Iterable(fieldNumber, values) {
  2660. const array = Array.from(values);
  2661. checkCriticalTypeSignedInt32Array(array);
  2662. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  2663. writer.writeRepeatedInt32(fieldNumber, values);
  2664. });
  2665. }
  2666. /* Int64 */
  2667. /**
  2668. * Adds all int64 values into the field for the given field number.
  2669. * How these values are encoded depends on the given write function.
  2670. * @param {number} fieldNumber
  2671. * @param {!Iterable<!Int64>} values
  2672. * @param {function(!Writer, number, !Array<!Int64>): undefined} encoder
  2673. * @private
  2674. */
  2675. addRepeatedInt64Iterable_(fieldNumber, values, encoder) {
  2676. const array = [...this.getRepeatedInt64Array_(fieldNumber), ...values];
  2677. checkCriticalTypeSignedInt64Array(array);
  2678. // Needs to set it back because the default empty array was not cached.
  2679. this.setField_(fieldNumber, array, encoder);
  2680. }
  2681. /**
  2682. * Adds a single int64 value into the field for the given field number.
  2683. * All values will be encoded as packed values.
  2684. * @param {number} fieldNumber
  2685. * @param {!Int64} value
  2686. */
  2687. addPackedInt64Element(fieldNumber, value) {
  2688. this.addRepeatedInt64Iterable_(
  2689. fieldNumber, [value], (writer, fieldNumber, values) => {
  2690. writer.writePackedInt64(fieldNumber, values);
  2691. });
  2692. }
  2693. /**
  2694. * Adds all int64 values into the field for the given field number.
  2695. * All these values will be encoded as packed values.
  2696. * @param {number} fieldNumber
  2697. * @param {!Iterable<!Int64>} values
  2698. */
  2699. addPackedInt64Iterable(fieldNumber, values) {
  2700. this.addRepeatedInt64Iterable_(
  2701. fieldNumber, values, (writer, fieldNumber, values) => {
  2702. writer.writePackedInt64(fieldNumber, values);
  2703. });
  2704. }
  2705. /**
  2706. * Adds a single int64 value into the field for the given field number.
  2707. * All values will be encoded as unpacked values.
  2708. * @param {number} fieldNumber
  2709. * @param {!Int64} value
  2710. */
  2711. addUnpackedInt64Element(fieldNumber, value) {
  2712. this.addRepeatedInt64Iterable_(
  2713. fieldNumber, [value], (writer, fieldNumber, values) => {
  2714. writer.writeRepeatedInt64(fieldNumber, values);
  2715. });
  2716. }
  2717. /**
  2718. * Adds all int64 values into the field for the given field number.
  2719. * All these values will be encoded as unpacked values.
  2720. * @param {number} fieldNumber
  2721. * @param {!Iterable<!Int64>} values
  2722. */
  2723. addUnpackedInt64Iterable(fieldNumber, values) {
  2724. this.addRepeatedInt64Iterable_(
  2725. fieldNumber, values, (writer, fieldNumber, values) => {
  2726. writer.writeRepeatedInt64(fieldNumber, values);
  2727. });
  2728. }
  2729. /**
  2730. * Sets a single int64 value into the field for the given field number at
  2731. * the given index. How these values are encoded depends on the given write
  2732. * function.
  2733. * @param {number} fieldNumber
  2734. * @param {number} index
  2735. * @param {!Int64} value
  2736. * @param {function(!Writer, number, !Array<!Int64>): undefined} encoder
  2737. * @throws {!Error} if index is out of range when check mode is critical
  2738. * @private
  2739. */
  2740. setRepeatedInt64Element_(fieldNumber, index, value, encoder) {
  2741. checkCriticalTypeSignedInt64(value);
  2742. const array = this.getRepeatedInt64Array_(fieldNumber);
  2743. checkCriticalElementIndex(index, array.length);
  2744. array[index] = value;
  2745. // Needs to set it back to set encoder.
  2746. this.setField_(fieldNumber, array, encoder);
  2747. }
  2748. /**
  2749. * Sets a single int64 value into the field for the given field number at
  2750. * the given index. All values will be encoded as packed values.
  2751. * @param {number} fieldNumber
  2752. * @param {number} index
  2753. * @param {!Int64} value
  2754. * @throws {!Error} if index is out of range when check mode is critical
  2755. */
  2756. setPackedInt64Element(fieldNumber, index, value) {
  2757. this.setRepeatedInt64Element_(
  2758. fieldNumber, index, value, (writer, fieldNumber, values) => {
  2759. writer.writePackedInt64(fieldNumber, values);
  2760. });
  2761. }
  2762. /**
  2763. * Sets all int64 values into the field for the given field number.
  2764. * All these values will be encoded as packed values.
  2765. * @param {number} fieldNumber
  2766. * @param {!Iterable<!Int64>} values
  2767. */
  2768. setPackedInt64Iterable(fieldNumber, values) {
  2769. const array = Array.from(values);
  2770. checkCriticalTypeSignedInt64Array(array);
  2771. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  2772. writer.writePackedInt64(fieldNumber, values);
  2773. });
  2774. }
  2775. /**
  2776. * Sets a single int64 value into the field for the given field number at
  2777. * the given index. All values will be encoded as unpacked values.
  2778. * @param {number} fieldNumber
  2779. * @param {number} index
  2780. * @param {!Int64} value
  2781. * @throws {!Error} if index is out of range when check mode is critical
  2782. */
  2783. setUnpackedInt64Element(fieldNumber, index, value) {
  2784. this.setRepeatedInt64Element_(
  2785. fieldNumber, index, value, (writer, fieldNumber, values) => {
  2786. writer.writeRepeatedInt64(fieldNumber, values);
  2787. });
  2788. }
  2789. /**
  2790. * Sets all int64 values into the field for the given field number.
  2791. * All these values will be encoded as unpacked values.
  2792. * @param {number} fieldNumber
  2793. * @param {!Iterable<!Int64>} values
  2794. */
  2795. setUnpackedInt64Iterable(fieldNumber, values) {
  2796. const array = Array.from(values);
  2797. checkCriticalTypeSignedInt64Array(array);
  2798. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  2799. writer.writeRepeatedInt64(fieldNumber, values);
  2800. });
  2801. }
  2802. /* Sfixed32 */
  2803. /**
  2804. * Adds all sfixed32 values into the field for the given field number.
  2805. * How these values are encoded depends on the given write function.
  2806. * @param {number} fieldNumber
  2807. * @param {!Iterable<number>} values
  2808. * @param {function(!Writer, number, !Array<number>): undefined} encoder
  2809. * @private
  2810. */
  2811. addRepeatedSfixed32Iterable_(fieldNumber, values, encoder) {
  2812. const array = [...this.getRepeatedSfixed32Array_(fieldNumber), ...values];
  2813. checkCriticalTypeSignedInt32Array(array);
  2814. // Needs to set it back because the default empty array was not cached.
  2815. this.setField_(fieldNumber, array, encoder);
  2816. }
  2817. /**
  2818. * Adds a single sfixed32 value into the field for the given field number.
  2819. * All values will be encoded as packed values.
  2820. * @param {number} fieldNumber
  2821. * @param {number} value
  2822. */
  2823. addPackedSfixed32Element(fieldNumber, value) {
  2824. this.addRepeatedSfixed32Iterable_(
  2825. fieldNumber, [value], (writer, fieldNumber, values) => {
  2826. writer.writePackedSfixed32(fieldNumber, values);
  2827. });
  2828. }
  2829. /**
  2830. * Adds all sfixed32 values into the field for the given field number.
  2831. * All these values will be encoded as packed values.
  2832. * @param {number} fieldNumber
  2833. * @param {!Iterable<number>} values
  2834. */
  2835. addPackedSfixed32Iterable(fieldNumber, values) {
  2836. this.addRepeatedSfixed32Iterable_(
  2837. fieldNumber, values, (writer, fieldNumber, values) => {
  2838. writer.writePackedSfixed32(fieldNumber, values);
  2839. });
  2840. }
  2841. /**
  2842. * Adds a single sfixed32 value into the field for the given field number.
  2843. * All values will be encoded as unpacked values.
  2844. * @param {number} fieldNumber
  2845. * @param {number} value
  2846. */
  2847. addUnpackedSfixed32Element(fieldNumber, value) {
  2848. this.addRepeatedSfixed32Iterable_(
  2849. fieldNumber, [value], (writer, fieldNumber, values) => {
  2850. writer.writeRepeatedSfixed32(fieldNumber, values);
  2851. });
  2852. }
  2853. /**
  2854. * Adds all sfixed32 values into the field for the given field number.
  2855. * All these values will be encoded as unpacked values.
  2856. * @param {number} fieldNumber
  2857. * @param {!Iterable<number>} values
  2858. */
  2859. addUnpackedSfixed32Iterable(fieldNumber, values) {
  2860. this.addRepeatedSfixed32Iterable_(
  2861. fieldNumber, values, (writer, fieldNumber, values) => {
  2862. writer.writeRepeatedSfixed32(fieldNumber, values);
  2863. });
  2864. }
  2865. /**
  2866. * Sets a single sfixed32 value into the field for the given field number at
  2867. * the given index. How these values are encoded depends on the given write
  2868. * function.
  2869. * @param {number} fieldNumber
  2870. * @param {number} index
  2871. * @param {number} value
  2872. * @param {function(!Writer, number, !Array<number>): undefined} encoder
  2873. * @throws {!Error} if index is out of range when check mode is critical
  2874. * @private
  2875. */
  2876. setRepeatedSfixed32Element_(fieldNumber, index, value, encoder) {
  2877. checkCriticalTypeSignedInt32(value);
  2878. const array = this.getRepeatedSfixed32Array_(fieldNumber);
  2879. checkCriticalElementIndex(index, array.length);
  2880. array[index] = value;
  2881. // Needs to set it back to set encoder.
  2882. this.setField_(fieldNumber, array, encoder);
  2883. }
  2884. /**
  2885. * Sets a single sfixed32 value into the field for the given field number at
  2886. * the given index. All values will be encoded as packed values.
  2887. * @param {number} fieldNumber
  2888. * @param {number} index
  2889. * @param {number} value
  2890. * @throws {!Error} if index is out of range when check mode is critical
  2891. */
  2892. setPackedSfixed32Element(fieldNumber, index, value) {
  2893. this.setRepeatedSfixed32Element_(
  2894. fieldNumber, index, value, (writer, fieldNumber, values) => {
  2895. writer.writePackedSfixed32(fieldNumber, values);
  2896. });
  2897. }
  2898. /**
  2899. * Sets all sfixed32 values into the field for the given field number.
  2900. * All these values will be encoded as packed values.
  2901. * @param {number} fieldNumber
  2902. * @param {!Iterable<number>} values
  2903. */
  2904. setPackedSfixed32Iterable(fieldNumber, values) {
  2905. const array = Array.from(values);
  2906. checkCriticalTypeSignedInt32Array(array);
  2907. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  2908. writer.writePackedSfixed32(fieldNumber, values);
  2909. });
  2910. }
  2911. /**
  2912. * Sets a single sfixed32 value into the field for the given field number at
  2913. * the given index. All values will be encoded as unpacked values.
  2914. * @param {number} fieldNumber
  2915. * @param {number} index
  2916. * @param {number} value
  2917. * @throws {!Error} if index is out of range when check mode is critical
  2918. */
  2919. setUnpackedSfixed32Element(fieldNumber, index, value) {
  2920. this.setRepeatedSfixed32Element_(
  2921. fieldNumber, index, value, (writer, fieldNumber, values) => {
  2922. writer.writeRepeatedSfixed32(fieldNumber, values);
  2923. });
  2924. }
  2925. /**
  2926. * Sets all sfixed32 values into the field for the given field number.
  2927. * All these values will be encoded as unpacked values.
  2928. * @param {number} fieldNumber
  2929. * @param {!Iterable<number>} values
  2930. */
  2931. setUnpackedSfixed32Iterable(fieldNumber, values) {
  2932. const array = Array.from(values);
  2933. checkCriticalTypeSignedInt32Array(array);
  2934. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  2935. writer.writeRepeatedSfixed32(fieldNumber, values);
  2936. });
  2937. }
  2938. /* Sfixed64 */
  2939. /**
  2940. * Adds all sfixed64 values into the field for the given field number.
  2941. * How these values are encoded depends on the given write function.
  2942. * @param {number} fieldNumber
  2943. * @param {!Iterable<!Int64>} values
  2944. * @param {function(!Writer, number, !Array<!Int64>): undefined} encoder
  2945. * @private
  2946. */
  2947. addRepeatedSfixed64Iterable_(fieldNumber, values, encoder) {
  2948. const array = [...this.getRepeatedSfixed64Array_(fieldNumber), ...values];
  2949. checkCriticalTypeSignedInt64Array(array);
  2950. // Needs to set it back because the default empty array was not cached.
  2951. this.setField_(fieldNumber, array, encoder);
  2952. }
  2953. /**
  2954. * Adds a single sfixed64 value into the field for the given field number.
  2955. * All values will be encoded as packed values.
  2956. * @param {number} fieldNumber
  2957. * @param {!Int64} value
  2958. */
  2959. addPackedSfixed64Element(fieldNumber, value) {
  2960. this.addRepeatedSfixed64Iterable_(
  2961. fieldNumber, [value], (writer, fieldNumber, values) => {
  2962. writer.writePackedSfixed64(fieldNumber, values);
  2963. });
  2964. }
  2965. /**
  2966. * Adds all sfixed64 values into the field for the given field number.
  2967. * All these values will be encoded as packed values.
  2968. * @param {number} fieldNumber
  2969. * @param {!Iterable<!Int64>} values
  2970. */
  2971. addPackedSfixed64Iterable(fieldNumber, values) {
  2972. this.addRepeatedSfixed64Iterable_(
  2973. fieldNumber, values, (writer, fieldNumber, values) => {
  2974. writer.writePackedSfixed64(fieldNumber, values);
  2975. });
  2976. }
  2977. /**
  2978. * Adds a single sfixed64 value into the field for the given field number.
  2979. * All values will be encoded as unpacked values.
  2980. * @param {number} fieldNumber
  2981. * @param {!Int64} value
  2982. */
  2983. addUnpackedSfixed64Element(fieldNumber, value) {
  2984. this.addRepeatedSfixed64Iterable_(
  2985. fieldNumber, [value], (writer, fieldNumber, values) => {
  2986. writer.writeRepeatedSfixed64(fieldNumber, values);
  2987. });
  2988. }
  2989. /**
  2990. * Adds all sfixed64 values into the field for the given field number.
  2991. * All these values will be encoded as unpacked values.
  2992. * @param {number} fieldNumber
  2993. * @param {!Iterable<!Int64>} values
  2994. */
  2995. addUnpackedSfixed64Iterable(fieldNumber, values) {
  2996. this.addRepeatedSfixed64Iterable_(
  2997. fieldNumber, values, (writer, fieldNumber, values) => {
  2998. writer.writeRepeatedSfixed64(fieldNumber, values);
  2999. });
  3000. }
  3001. /**
  3002. * Sets a single sfixed64 value into the field for the given field number at
  3003. * the given index. How these values are encoded depends on the given write
  3004. * function.
  3005. * @param {number} fieldNumber
  3006. * @param {number} index
  3007. * @param {!Int64} value
  3008. * @param {function(!Writer, number, !Array<!Int64>): undefined} encoder
  3009. * @throws {!Error} if index is out of range when check mode is critical
  3010. * @private
  3011. */
  3012. setRepeatedSfixed64Element_(fieldNumber, index, value, encoder) {
  3013. checkCriticalTypeSignedInt64(value);
  3014. const array = this.getRepeatedSfixed64Array_(fieldNumber);
  3015. checkCriticalElementIndex(index, array.length);
  3016. array[index] = value;
  3017. // Needs to set it back to set encoder.
  3018. this.setField_(fieldNumber, array, encoder);
  3019. }
  3020. /**
  3021. * Sets a single sfixed64 value into the field for the given field number at
  3022. * the given index. All values will be encoded as packed values.
  3023. * @param {number} fieldNumber
  3024. * @param {number} index
  3025. * @param {!Int64} value
  3026. * @throws {!Error} if index is out of range when check mode is critical
  3027. */
  3028. setPackedSfixed64Element(fieldNumber, index, value) {
  3029. this.setRepeatedSfixed64Element_(
  3030. fieldNumber, index, value, (writer, fieldNumber, values) => {
  3031. writer.writePackedSfixed64(fieldNumber, values);
  3032. });
  3033. }
  3034. /**
  3035. * Sets all sfixed64 values into the field for the given field number.
  3036. * All these values will be encoded as packed values.
  3037. * @param {number} fieldNumber
  3038. * @param {!Iterable<!Int64>} values
  3039. */
  3040. setPackedSfixed64Iterable(fieldNumber, values) {
  3041. const array = Array.from(values);
  3042. checkCriticalTypeSignedInt64Array(array);
  3043. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  3044. writer.writePackedSfixed64(fieldNumber, values);
  3045. });
  3046. }
  3047. /**
  3048. * Sets a single sfixed64 value into the field for the given field number at
  3049. * the given index. All values will be encoded as unpacked values.
  3050. * @param {number} fieldNumber
  3051. * @param {number} index
  3052. * @param {!Int64} value
  3053. * @throws {!Error} if index is out of range when check mode is critical
  3054. */
  3055. setUnpackedSfixed64Element(fieldNumber, index, value) {
  3056. this.setRepeatedSfixed64Element_(
  3057. fieldNumber, index, value, (writer, fieldNumber, values) => {
  3058. writer.writeRepeatedSfixed64(fieldNumber, values);
  3059. });
  3060. }
  3061. /**
  3062. * Sets all sfixed64 values into the field for the given field number.
  3063. * All these values will be encoded as unpacked values.
  3064. * @param {number} fieldNumber
  3065. * @param {!Iterable<!Int64>} values
  3066. */
  3067. setUnpackedSfixed64Iterable(fieldNumber, values) {
  3068. const array = Array.from(values);
  3069. checkCriticalTypeSignedInt64Array(array);
  3070. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  3071. writer.writeRepeatedSfixed64(fieldNumber, values);
  3072. });
  3073. }
  3074. /* Sint32 */
  3075. /**
  3076. * Adds all sint32 values into the field for the given field number.
  3077. * How these values are encoded depends on the given write function.
  3078. * @param {number} fieldNumber
  3079. * @param {!Iterable<number>} values
  3080. * @param {function(!Writer, number, !Array<number>): undefined} encoder
  3081. * @private
  3082. */
  3083. addRepeatedSint32Iterable_(fieldNumber, values, encoder) {
  3084. const array = [...this.getRepeatedSint32Array_(fieldNumber), ...values];
  3085. checkCriticalTypeSignedInt32Array(array);
  3086. // Needs to set it back because the default empty array was not cached.
  3087. this.setField_(fieldNumber, array, encoder);
  3088. }
  3089. /**
  3090. * Adds a single sint32 value into the field for the given field number.
  3091. * All values will be encoded as packed values.
  3092. * @param {number} fieldNumber
  3093. * @param {number} value
  3094. */
  3095. addPackedSint32Element(fieldNumber, value) {
  3096. this.addRepeatedSint32Iterable_(
  3097. fieldNumber, [value], (writer, fieldNumber, values) => {
  3098. writer.writePackedSint32(fieldNumber, values);
  3099. });
  3100. }
  3101. /**
  3102. * Adds all sint32 values into the field for the given field number.
  3103. * All these values will be encoded as packed values.
  3104. * @param {number} fieldNumber
  3105. * @param {!Iterable<number>} values
  3106. */
  3107. addPackedSint32Iterable(fieldNumber, values) {
  3108. this.addRepeatedSint32Iterable_(
  3109. fieldNumber, values, (writer, fieldNumber, values) => {
  3110. writer.writePackedSint32(fieldNumber, values);
  3111. });
  3112. }
  3113. /**
  3114. * Adds a single sint32 value into the field for the given field number.
  3115. * All values will be encoded as unpacked values.
  3116. * @param {number} fieldNumber
  3117. * @param {number} value
  3118. */
  3119. addUnpackedSint32Element(fieldNumber, value) {
  3120. this.addRepeatedSint32Iterable_(
  3121. fieldNumber, [value], (writer, fieldNumber, values) => {
  3122. writer.writeRepeatedSint32(fieldNumber, values);
  3123. });
  3124. }
  3125. /**
  3126. * Adds all sint32 values into the field for the given field number.
  3127. * All these values will be encoded as unpacked values.
  3128. * @param {number} fieldNumber
  3129. * @param {!Iterable<number>} values
  3130. */
  3131. addUnpackedSint32Iterable(fieldNumber, values) {
  3132. this.addRepeatedSint32Iterable_(
  3133. fieldNumber, values, (writer, fieldNumber, values) => {
  3134. writer.writeRepeatedSint32(fieldNumber, values);
  3135. });
  3136. }
  3137. /**
  3138. * Sets a single sint32 value into the field for the given field number at
  3139. * the given index. How these values are encoded depends on the given write
  3140. * function.
  3141. * @param {number} fieldNumber
  3142. * @param {number} index
  3143. * @param {number} value
  3144. * @param {function(!Writer, number, !Array<number>): undefined} encoder
  3145. * @throws {!Error} if index is out of range when check mode is critical
  3146. * @private
  3147. */
  3148. setRepeatedSint32Element_(fieldNumber, index, value, encoder) {
  3149. checkCriticalTypeSignedInt32(value);
  3150. const array = this.getRepeatedSint32Array_(fieldNumber);
  3151. checkCriticalElementIndex(index, array.length);
  3152. array[index] = value;
  3153. // Needs to set it back to set encoder.
  3154. this.setField_(fieldNumber, array, encoder);
  3155. }
  3156. /**
  3157. * Sets a single sint32 value into the field for the given field number at
  3158. * the given index. All values will be encoded as packed values.
  3159. * @param {number} fieldNumber
  3160. * @param {number} index
  3161. * @param {number} value
  3162. * @throws {!Error} if index is out of range when check mode is critical
  3163. */
  3164. setPackedSint32Element(fieldNumber, index, value) {
  3165. this.setRepeatedSint32Element_(
  3166. fieldNumber, index, value, (writer, fieldNumber, values) => {
  3167. writer.writePackedSint32(fieldNumber, values);
  3168. });
  3169. }
  3170. /**
  3171. * Sets all sint32 values into the field for the given field number.
  3172. * All these values will be encoded as packed values.
  3173. * @param {number} fieldNumber
  3174. * @param {!Iterable<number>} values
  3175. */
  3176. setPackedSint32Iterable(fieldNumber, values) {
  3177. const array = Array.from(values);
  3178. checkCriticalTypeSignedInt32Array(array);
  3179. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  3180. writer.writePackedSint32(fieldNumber, values);
  3181. });
  3182. }
  3183. /**
  3184. * Sets a single sint32 value into the field for the given field number at
  3185. * the given index. All values will be encoded as unpacked values.
  3186. * @param {number} fieldNumber
  3187. * @param {number} index
  3188. * @param {number} value
  3189. * @throws {!Error} if index is out of range when check mode is critical
  3190. */
  3191. setUnpackedSint32Element(fieldNumber, index, value) {
  3192. this.setRepeatedSint32Element_(
  3193. fieldNumber, index, value, (writer, fieldNumber, values) => {
  3194. writer.writeRepeatedSint32(fieldNumber, values);
  3195. });
  3196. }
  3197. /**
  3198. * Sets all sint32 values into the field for the given field number.
  3199. * All these values will be encoded as unpacked values.
  3200. * @param {number} fieldNumber
  3201. * @param {!Iterable<number>} values
  3202. */
  3203. setUnpackedSint32Iterable(fieldNumber, values) {
  3204. const array = Array.from(values);
  3205. checkCriticalTypeSignedInt32Array(array);
  3206. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  3207. writer.writeRepeatedSint32(fieldNumber, values);
  3208. });
  3209. }
  3210. /* Sint64 */
  3211. /**
  3212. * Adds all sint64 values into the field for the given field number.
  3213. * How these values are encoded depends on the given write function.
  3214. * @param {number} fieldNumber
  3215. * @param {!Iterable<!Int64>} values
  3216. * @param {function(!Writer, number, !Array<!Int64>): undefined} encoder
  3217. * @private
  3218. */
  3219. addRepeatedSint64Iterable_(fieldNumber, values, encoder) {
  3220. const array = [...this.getRepeatedSint64Array_(fieldNumber), ...values];
  3221. checkCriticalTypeSignedInt64Array(array);
  3222. // Needs to set it back because the default empty array was not cached.
  3223. this.setField_(fieldNumber, array, encoder);
  3224. }
  3225. /**
  3226. * Adds a single sint64 value into the field for the given field number.
  3227. * All values will be encoded as packed values.
  3228. * @param {number} fieldNumber
  3229. * @param {!Int64} value
  3230. */
  3231. addPackedSint64Element(fieldNumber, value) {
  3232. this.addRepeatedSint64Iterable_(
  3233. fieldNumber, [value], (writer, fieldNumber, values) => {
  3234. writer.writePackedSint64(fieldNumber, values);
  3235. });
  3236. }
  3237. /**
  3238. * Adds all sint64 values into the field for the given field number.
  3239. * All these values will be encoded as packed values.
  3240. * @param {number} fieldNumber
  3241. * @param {!Iterable<!Int64>} values
  3242. */
  3243. addPackedSint64Iterable(fieldNumber, values) {
  3244. this.addRepeatedSint64Iterable_(
  3245. fieldNumber, values, (writer, fieldNumber, values) => {
  3246. writer.writePackedSint64(fieldNumber, values);
  3247. });
  3248. }
  3249. /**
  3250. * Adds a single sint64 value into the field for the given field number.
  3251. * All values will be encoded as unpacked values.
  3252. * @param {number} fieldNumber
  3253. * @param {!Int64} value
  3254. */
  3255. addUnpackedSint64Element(fieldNumber, value) {
  3256. this.addRepeatedSint64Iterable_(
  3257. fieldNumber, [value], (writer, fieldNumber, values) => {
  3258. writer.writeRepeatedSint64(fieldNumber, values);
  3259. });
  3260. }
  3261. /**
  3262. * Adds all sint64 values into the field for the given field number.
  3263. * All these values will be encoded as unpacked values.
  3264. * @param {number} fieldNumber
  3265. * @param {!Iterable<!Int64>} values
  3266. */
  3267. addUnpackedSint64Iterable(fieldNumber, values) {
  3268. this.addRepeatedSint64Iterable_(
  3269. fieldNumber, values, (writer, fieldNumber, values) => {
  3270. writer.writeRepeatedSint64(fieldNumber, values);
  3271. });
  3272. }
  3273. /**
  3274. * Sets a single sint64 value into the field for the given field number at
  3275. * the given index. How these values are encoded depends on the given write
  3276. * function.
  3277. * @param {number} fieldNumber
  3278. * @param {number} index
  3279. * @param {!Int64} value
  3280. * @param {function(!Writer, number, !Array<!Int64>): undefined} encoder
  3281. * @throws {!Error} if index is out of range when check mode is critical
  3282. * @private
  3283. */
  3284. setRepeatedSint64Element_(fieldNumber, index, value, encoder) {
  3285. checkCriticalTypeSignedInt64(value);
  3286. const array = this.getRepeatedSint64Array_(fieldNumber);
  3287. checkCriticalElementIndex(index, array.length);
  3288. array[index] = value;
  3289. // Needs to set it back to set encoder.
  3290. this.setField_(fieldNumber, array, encoder);
  3291. }
  3292. /**
  3293. * Sets a single sint64 value into the field for the given field number at
  3294. * the given index. All values will be encoded as packed values.
  3295. * @param {number} fieldNumber
  3296. * @param {number} index
  3297. * @param {!Int64} value
  3298. * @throws {!Error} if index is out of range when check mode is critical
  3299. */
  3300. setPackedSint64Element(fieldNumber, index, value) {
  3301. this.setRepeatedSint64Element_(
  3302. fieldNumber, index, value, (writer, fieldNumber, values) => {
  3303. writer.writePackedSint64(fieldNumber, values);
  3304. });
  3305. }
  3306. /**
  3307. * Sets all sint64 values into the field for the given field number.
  3308. * All these values will be encoded as packed values.
  3309. * @param {number} fieldNumber
  3310. * @param {!Iterable<!Int64>} values
  3311. */
  3312. setPackedSint64Iterable(fieldNumber, values) {
  3313. const array = Array.from(values);
  3314. checkCriticalTypeSignedInt64Array(array);
  3315. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  3316. writer.writePackedSint64(fieldNumber, values);
  3317. });
  3318. }
  3319. /**
  3320. * Sets a single sint64 value into the field for the given field number at
  3321. * the given index. All values will be encoded as unpacked values.
  3322. * @param {number} fieldNumber
  3323. * @param {number} index
  3324. * @param {!Int64} value
  3325. * @throws {!Error} if index is out of range when check mode is critical
  3326. */
  3327. setUnpackedSint64Element(fieldNumber, index, value) {
  3328. this.setRepeatedSint64Element_(
  3329. fieldNumber, index, value, (writer, fieldNumber, values) => {
  3330. writer.writeRepeatedSint64(fieldNumber, values);
  3331. });
  3332. }
  3333. /**
  3334. * Sets all sint64 values into the field for the given field number.
  3335. * All these values will be encoded as unpacked values.
  3336. * @param {number} fieldNumber
  3337. * @param {!Iterable<!Int64>} values
  3338. */
  3339. setUnpackedSint64Iterable(fieldNumber, values) {
  3340. const array = Array.from(values);
  3341. checkCriticalTypeSignedInt64Array(array);
  3342. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  3343. writer.writeRepeatedSint64(fieldNumber, values);
  3344. });
  3345. }
  3346. /* Uint32 */
  3347. /**
  3348. * Adds all uint32 values into the field for the given field number.
  3349. * How these values are encoded depends on the given write function.
  3350. * @param {number} fieldNumber
  3351. * @param {!Iterable<number>} values
  3352. * @param {function(!Writer, number, !Array<number>): undefined} encoder
  3353. * @private
  3354. */
  3355. addRepeatedUint32Iterable_(fieldNumber, values, encoder) {
  3356. const array = [...this.getRepeatedUint32Array_(fieldNumber), ...values];
  3357. checkCriticalTypeUnsignedInt32Array(array);
  3358. // Needs to set it back because the default empty array was not cached.
  3359. this.setField_(fieldNumber, array, encoder);
  3360. }
  3361. /**
  3362. * Adds a single uint32 value into the field for the given field number.
  3363. * All values will be encoded as packed values.
  3364. * @param {number} fieldNumber
  3365. * @param {number} value
  3366. */
  3367. addPackedUint32Element(fieldNumber, value) {
  3368. this.addRepeatedUint32Iterable_(
  3369. fieldNumber, [value], (writer, fieldNumber, values) => {
  3370. writer.writePackedUint32(fieldNumber, values);
  3371. });
  3372. }
  3373. /**
  3374. * Adds all uint32 values into the field for the given field number.
  3375. * All these values will be encoded as packed values.
  3376. * @param {number} fieldNumber
  3377. * @param {!Iterable<number>} values
  3378. */
  3379. addPackedUint32Iterable(fieldNumber, values) {
  3380. this.addRepeatedUint32Iterable_(
  3381. fieldNumber, values, (writer, fieldNumber, values) => {
  3382. writer.writePackedUint32(fieldNumber, values);
  3383. });
  3384. }
  3385. /**
  3386. * Adds a single uint32 value into the field for the given field number.
  3387. * All values will be encoded as unpacked values.
  3388. * @param {number} fieldNumber
  3389. * @param {number} value
  3390. */
  3391. addUnpackedUint32Element(fieldNumber, value) {
  3392. this.addRepeatedUint32Iterable_(
  3393. fieldNumber, [value], (writer, fieldNumber, values) => {
  3394. writer.writeRepeatedUint32(fieldNumber, values);
  3395. });
  3396. }
  3397. /**
  3398. * Adds all uint32 values into the field for the given field number.
  3399. * All these values will be encoded as unpacked values.
  3400. * @param {number} fieldNumber
  3401. * @param {!Iterable<number>} values
  3402. */
  3403. addUnpackedUint32Iterable(fieldNumber, values) {
  3404. this.addRepeatedUint32Iterable_(
  3405. fieldNumber, values, (writer, fieldNumber, values) => {
  3406. writer.writeRepeatedUint32(fieldNumber, values);
  3407. });
  3408. }
  3409. /**
  3410. * Sets a single uint32 value into the field for the given field number at
  3411. * the given index. How these values are encoded depends on the given write
  3412. * function.
  3413. * @param {number} fieldNumber
  3414. * @param {number} index
  3415. * @param {number} value
  3416. * @param {function(!Writer, number, !Array<number>): undefined} encoder
  3417. * @throws {!Error} if index is out of range when check mode is critical
  3418. * @private
  3419. */
  3420. setRepeatedUint32Element_(fieldNumber, index, value, encoder) {
  3421. checkCriticalTypeUnsignedInt32(value);
  3422. const array = this.getRepeatedUint32Array_(fieldNumber);
  3423. checkCriticalElementIndex(index, array.length);
  3424. array[index] = value;
  3425. // Needs to set it back to set encoder.
  3426. this.setField_(fieldNumber, array, encoder);
  3427. }
  3428. /**
  3429. * Sets a single uint32 value into the field for the given field number at
  3430. * the given index. All values will be encoded as packed values.
  3431. * @param {number} fieldNumber
  3432. * @param {number} index
  3433. * @param {number} value
  3434. * @throws {!Error} if index is out of range when check mode is critical
  3435. */
  3436. setPackedUint32Element(fieldNumber, index, value) {
  3437. this.setRepeatedUint32Element_(
  3438. fieldNumber, index, value, (writer, fieldNumber, values) => {
  3439. writer.writePackedUint32(fieldNumber, values);
  3440. });
  3441. }
  3442. /**
  3443. * Sets all uint32 values into the field for the given field number.
  3444. * All these values will be encoded as packed values.
  3445. * @param {number} fieldNumber
  3446. * @param {!Iterable<number>} values
  3447. */
  3448. setPackedUint32Iterable(fieldNumber, values) {
  3449. const array = Array.from(values);
  3450. checkCriticalTypeUnsignedInt32Array(array);
  3451. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  3452. writer.writePackedUint32(fieldNumber, values);
  3453. });
  3454. }
  3455. /**
  3456. * Sets a single uint32 value into the field for the given field number at
  3457. * the given index. All values will be encoded as unpacked values.
  3458. * @param {number} fieldNumber
  3459. * @param {number} index
  3460. * @param {number} value
  3461. * @throws {!Error} if index is out of range when check mode is critical
  3462. */
  3463. setUnpackedUint32Element(fieldNumber, index, value) {
  3464. this.setRepeatedUint32Element_(
  3465. fieldNumber, index, value, (writer, fieldNumber, values) => {
  3466. writer.writeRepeatedUint32(fieldNumber, values);
  3467. });
  3468. }
  3469. /**
  3470. * Sets all uint32 values into the field for the given field number.
  3471. * All these values will be encoded as unpacked values.
  3472. * @param {number} fieldNumber
  3473. * @param {!Iterable<number>} values
  3474. */
  3475. setUnpackedUint32Iterable(fieldNumber, values) {
  3476. const array = Array.from(values);
  3477. checkCriticalTypeUnsignedInt32Array(array);
  3478. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  3479. writer.writeRepeatedUint32(fieldNumber, values);
  3480. });
  3481. }
  3482. /* Uint64 */
  3483. /**
  3484. * Adds a single uint64 value into the field for the given field number.
  3485. * All values will be encoded as packed values.
  3486. * @param {number} fieldNumber
  3487. * @param {!Int64} value
  3488. */
  3489. addPackedUint64Element(fieldNumber, value) {
  3490. this.addPackedInt64Element(fieldNumber, value);
  3491. }
  3492. /**
  3493. * Adds all uint64 values into the field for the given field number.
  3494. * All these values will be encoded as packed values.
  3495. * @param {number} fieldNumber
  3496. * @param {!Iterable<!Int64>} values
  3497. */
  3498. addPackedUint64Iterable(fieldNumber, values) {
  3499. this.addPackedInt64Iterable(fieldNumber, values);
  3500. }
  3501. /**
  3502. * Adds a single uint64 value into the field for the given field number.
  3503. * All values will be encoded as unpacked values.
  3504. * @param {number} fieldNumber
  3505. * @param {!Int64} value
  3506. */
  3507. addUnpackedUint64Element(fieldNumber, value) {
  3508. this.addUnpackedInt64Element(fieldNumber, value);
  3509. }
  3510. /**
  3511. * Adds all uint64 values into the field for the given field number.
  3512. * All these values will be encoded as unpacked values.
  3513. * @param {number} fieldNumber
  3514. * @param {!Iterable<!Int64>} values
  3515. */
  3516. addUnpackedUint64Iterable(fieldNumber, values) {
  3517. this.addUnpackedInt64Iterable(fieldNumber, values);
  3518. }
  3519. /**
  3520. * Sets a single uint64 value into the field for the given field number at
  3521. * the given index. All values will be encoded as packed values.
  3522. * @param {number} fieldNumber
  3523. * @param {number} index
  3524. * @param {!Int64} value
  3525. * @throws {!Error} if index is out of range when check mode is critical
  3526. */
  3527. setPackedUint64Element(fieldNumber, index, value) {
  3528. this.setPackedInt64Element(fieldNumber, index, value);
  3529. }
  3530. /**
  3531. * Sets all uint64 values into the field for the given field number.
  3532. * All these values will be encoded as packed values.
  3533. * @param {number} fieldNumber
  3534. * @param {!Iterable<!Int64>} values
  3535. */
  3536. setPackedUint64Iterable(fieldNumber, values) {
  3537. this.setPackedInt64Iterable(fieldNumber, values);
  3538. }
  3539. /**
  3540. * Sets a single uint64 value into the field for the given field number at
  3541. * the given index. All values will be encoded as unpacked values.
  3542. * @param {number} fieldNumber
  3543. * @param {number} index
  3544. * @param {!Int64} value
  3545. * @throws {!Error} if index is out of range when check mode is critical
  3546. */
  3547. setUnpackedUint64Element(fieldNumber, index, value) {
  3548. this.setUnpackedInt64Element(fieldNumber, index, value);
  3549. }
  3550. /**
  3551. * Sets all uint64 values into the field for the given field number.
  3552. * All these values will be encoded as unpacked values.
  3553. * @param {number} fieldNumber
  3554. * @param {!Iterable<!Int64>} values
  3555. */
  3556. setUnpackedUint64Iterable(fieldNumber, values) {
  3557. this.setUnpackedInt64Iterable(fieldNumber, values);
  3558. }
  3559. /* Bytes */
  3560. /**
  3561. * Sets all bytes values into the field for the given field number.
  3562. * @param {number} fieldNumber
  3563. * @param {!Iterable<!ByteString>} values
  3564. */
  3565. setRepeatedBytesIterable(fieldNumber, values) {
  3566. const /** !Array<!ByteString> */ array = Array.from(values);
  3567. checkCriticalTypeByteStringArray(array);
  3568. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  3569. writer.writeRepeatedBytes(fieldNumber, values);
  3570. });
  3571. }
  3572. /**
  3573. * Adds all bytes values into the field for the given field number.
  3574. * @param {number} fieldNumber
  3575. * @param {!Iterable<!ByteString>} values
  3576. */
  3577. addRepeatedBytesIterable(fieldNumber, values) {
  3578. const array = [...this.getRepeatedBytesArray_(fieldNumber), ...values];
  3579. checkCriticalTypeByteStringArray(array);
  3580. // Needs to set it back because the default empty array was not cached.
  3581. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  3582. writer.writeRepeatedBytes(fieldNumber, values);
  3583. });
  3584. }
  3585. /**
  3586. * Sets a single bytes value into the field for the given field number at
  3587. * the given index.
  3588. * @param {number} fieldNumber
  3589. * @param {number} index
  3590. * @param {!ByteString} value
  3591. * @throws {!Error} if index is out of range when check mode is critical
  3592. */
  3593. setRepeatedBytesElement(fieldNumber, index, value) {
  3594. checkCriticalTypeByteString(value);
  3595. const array = this.getRepeatedBytesArray_(fieldNumber);
  3596. checkCriticalElementIndex(index, array.length);
  3597. array[index] = value;
  3598. // Needs to set it back to set encoder.
  3599. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  3600. writer.writeRepeatedBytes(fieldNumber, values);
  3601. });
  3602. }
  3603. /**
  3604. * Adds a single bytes value into the field for the given field number.
  3605. * @param {number} fieldNumber
  3606. * @param {!ByteString} value
  3607. */
  3608. addRepeatedBytesElement(fieldNumber, value) {
  3609. this.addRepeatedBytesIterable(fieldNumber, [value]);
  3610. }
  3611. /* String */
  3612. /**
  3613. * Sets all string values into the field for the given field number.
  3614. * @param {number} fieldNumber
  3615. * @param {!Iterable<string>} values
  3616. */
  3617. setRepeatedStringIterable(fieldNumber, values) {
  3618. const /** !Array<string> */ array = Array.from(values);
  3619. checkCriticalTypeStringArray(array);
  3620. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  3621. writer.writeRepeatedString(fieldNumber, values);
  3622. });
  3623. }
  3624. /**
  3625. * Adds all string values into the field for the given field number.
  3626. * @param {number} fieldNumber
  3627. * @param {!Iterable<string>} values
  3628. */
  3629. addRepeatedStringIterable(fieldNumber, values) {
  3630. const array = [...this.getRepeatedStringArray_(fieldNumber), ...values];
  3631. checkCriticalTypeStringArray(array);
  3632. // Needs to set it back because the default empty array was not cached.
  3633. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  3634. writer.writeRepeatedString(fieldNumber, values);
  3635. });
  3636. }
  3637. /**
  3638. * Sets a single string value into the field for the given field number at
  3639. * the given index.
  3640. * @param {number} fieldNumber
  3641. * @param {number} index
  3642. * @param {string} value
  3643. * @throws {!Error} if index is out of range when check mode is critical
  3644. */
  3645. setRepeatedStringElement(fieldNumber, index, value) {
  3646. checkCriticalTypeString(value);
  3647. const array = this.getRepeatedStringArray_(fieldNumber);
  3648. checkCriticalElementIndex(index, array.length);
  3649. array[index] = value;
  3650. // Needs to set it back to set encoder.
  3651. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  3652. writer.writeRepeatedString(fieldNumber, values);
  3653. });
  3654. }
  3655. /**
  3656. * Adds a single string value into the field for the given field number.
  3657. * @param {number} fieldNumber
  3658. * @param {string} value
  3659. */
  3660. addRepeatedStringElement(fieldNumber, value) {
  3661. this.addRepeatedStringIterable(fieldNumber, [value]);
  3662. }
  3663. /* Message */
  3664. /**
  3665. * Sets all message values into the field for the given field number.
  3666. * @param {number} fieldNumber
  3667. * @param {!Iterable<!InternalMessage>} values
  3668. */
  3669. setRepeatedMessageIterable(fieldNumber, values) {
  3670. const /** !Array<!InternalMessage> */ array = Array.from(values);
  3671. checkCriticalTypeMessageArray(array);
  3672. this.setField_(fieldNumber, array, (writer, fieldNumber, values) => {
  3673. writeRepeatedMessage(writer, fieldNumber, values);
  3674. });
  3675. }
  3676. /**
  3677. * Adds all message values into the field for the given field number.
  3678. * @param {number} fieldNumber
  3679. * @param {!Iterable<!InternalMessage>} values
  3680. * @param {function(!Kernel):!InternalMessage} instanceCreator
  3681. * @param {number=} pivot
  3682. */
  3683. addRepeatedMessageIterable(
  3684. fieldNumber, values, instanceCreator, pivot = undefined) {
  3685. const array = [
  3686. ...this.getRepeatedMessageArray_(fieldNumber, instanceCreator, pivot),
  3687. ...values,
  3688. ];
  3689. checkCriticalTypeMessageArray(array);
  3690. // Needs to set it back with the new array.
  3691. this.setField_(
  3692. fieldNumber, array,
  3693. (writer, fieldNumber, values) =>
  3694. writeRepeatedMessage(writer, fieldNumber, values));
  3695. }
  3696. /**
  3697. * Sets a single message value into the field for the given field number at
  3698. * the given index.
  3699. * @param {number} fieldNumber
  3700. * @param {!InternalMessage} value
  3701. * @param {function(!Kernel):!InternalMessage} instanceCreator
  3702. * @param {number} index
  3703. * @param {number=} pivot
  3704. * @throws {!Error} if index is out of range when check mode is critical
  3705. */
  3706. setRepeatedMessageElement(
  3707. fieldNumber, value, instanceCreator, index, pivot = undefined) {
  3708. checkInstanceCreator(instanceCreator);
  3709. checkCriticalType(
  3710. value !== null, 'Given value is not a message instance: null');
  3711. const array =
  3712. this.getRepeatedMessageArray_(fieldNumber, instanceCreator, pivot);
  3713. checkCriticalElementIndex(index, array.length);
  3714. array[index] = value;
  3715. }
  3716. /**
  3717. * Adds a single message value into the field for the given field number.
  3718. * @param {number} fieldNumber
  3719. * @param {!InternalMessage} value
  3720. * @param {function(!Kernel):!InternalMessage} instanceCreator
  3721. * @param {number=} pivot
  3722. */
  3723. addRepeatedMessageElement(
  3724. fieldNumber, value, instanceCreator, pivot = undefined) {
  3725. this.addRepeatedMessageIterable(
  3726. fieldNumber, [value], instanceCreator, pivot);
  3727. }
  3728. // Groups
  3729. /**
  3730. * Sets all message values into the field for the given field number.
  3731. * @param {number} fieldNumber
  3732. * @param {!Iterable<!InternalMessage>} values
  3733. */
  3734. setRepeatedGroupIterable(fieldNumber, values) {
  3735. const /** !Array<!InternalMessage> */ array = Array.from(values);
  3736. checkCriticalTypeMessageArray(array);
  3737. this.setField_(fieldNumber, array, writeRepeatedGroup);
  3738. }
  3739. /**
  3740. * Adds all message values into the field for the given field number.
  3741. * @param {number} fieldNumber
  3742. * @param {!Iterable<!InternalMessage>} values
  3743. * @param {function(!Kernel):!InternalMessage} instanceCreator
  3744. * @param {number=} pivot
  3745. */
  3746. addRepeatedGroupIterable(
  3747. fieldNumber, values, instanceCreator, pivot = undefined) {
  3748. const array = [
  3749. ...this.getRepeatedGroupArray_(fieldNumber, instanceCreator, pivot),
  3750. ...values,
  3751. ];
  3752. checkCriticalTypeMessageArray(array);
  3753. // Needs to set it back with the new array.
  3754. this.setField_(fieldNumber, array, writeRepeatedGroup);
  3755. }
  3756. /**
  3757. * Sets a single message value into the field for the given field number at
  3758. * the given index.
  3759. * @param {number} fieldNumber
  3760. * @param {!InternalMessage} value
  3761. * @param {function(!Kernel):!InternalMessage} instanceCreator
  3762. * @param {number} index
  3763. * @param {number=} pivot
  3764. * @throws {!Error} if index is out of range when check mode is critical
  3765. */
  3766. setRepeatedGroupElement(
  3767. fieldNumber, value, instanceCreator, index, pivot = undefined) {
  3768. checkInstanceCreator(instanceCreator);
  3769. checkCriticalType(
  3770. value !== null, 'Given value is not a message instance: null');
  3771. const array =
  3772. this.getRepeatedGroupArray_(fieldNumber, instanceCreator, pivot);
  3773. checkCriticalElementIndex(index, array.length);
  3774. array[index] = value;
  3775. }
  3776. /**
  3777. * Adds a single message value into the field for the given field number.
  3778. * @param {number} fieldNumber
  3779. * @param {!InternalMessage} value
  3780. * @param {function(!Kernel):!InternalMessage} instanceCreator
  3781. * @param {number=} pivot
  3782. */
  3783. addRepeatedGroupElement(
  3784. fieldNumber, value, instanceCreator, pivot = undefined) {
  3785. this.addRepeatedGroupIterable(fieldNumber, [value], instanceCreator, pivot);
  3786. }
  3787. }
  3788. exports = Kernel;