1/** 2 * @fileoverview Helper methods for Uint8Arrays. 3 */ 4goog.module('protobuf.binary.uint8arrays'); 5 6/** 7 * Combines multiple bytes arrays (either Uint8Array or number array whose 8 * values are bytes) into a single Uint8Array. 9 * @param {!Array<!Uint8Array>|!Array<!Array<number>>} arrays 10 * @return {!Uint8Array} 11 */ 12function concatenateByteArrays(arrays) { 13 let totalLength = 0; 14 for (const array of arrays) { 15 totalLength += array.length; 16 } 17 const result = new Uint8Array(totalLength); 18 let offset = 0; 19 for (const array of arrays) { 20 result.set(array, offset); 21 offset += array.length; 22 } 23 return result; 24} 25 26exports = { 27 concatenateByteArrays, 28}; 29