| // Function which converts a protobuf array into an array which can be accessed |
| // as if it was a protobuf object (with the same keys). If the input is not an |
| // array it returns itself (since it is called recursively). |
| export function correctArrayKeys(input) { |
| if (!Array.isArray(input)) return input; |
| for (let i = 0; i < input.length; ++i) { |
| if (input[i] === null) continue; |
| object[i + 1] = correctArrayKeys(input[i]); |
| export function inverseCorrectArrayKeys(input) { |
| if (Array.isArray(input)) { |
| if (input[0] === null || input[0] === undefined) { |
| // Make a copy of the input array so we don't modify the original one. |
| input = Array.from(input); |
| for (let i = 0; i < input.length; ++i) { |
| object[i] = inverseCorrectArrayKeys(input[i]); |
| if (typeof input !== 'object' || input === null) return input; |
| const keys = Object.keys(input); |
| if (keys.length === 0) return []; |
| const maxItem = Math.max(...keys); |
| let array = Array(maxItem).fill(undefined); |
| Object.entries(input).forEach(entry => { |
| array[entry[0] - 1] = inverseCorrectArrayKeys(entry[1]); |