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