Total Complexity | 4 |
Complexity/F | 2 |
Lines of Code | 31 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | /*! |
||
15 | function endianness(bytes, offset) { |
||
16 | let len = bytes.length; |
||
17 | let i = 0; |
||
18 | while (i < len) { |
||
19 | swap(bytes, offset, i); |
||
20 | i += offset; |
||
21 | } |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * Swap the endianness of a unit of information in a byte array. |
||
26 | * The original array is modified in-place. |
||
27 | * @param {!Array<number>|!Array<string>|Uint8Array} bytes The bytes. |
||
28 | * @param {number} offset The number of bytes of the unit of information. |
||
29 | * @param {number} index The start index of the unit of information. |
||
30 | */ |
||
31 | function swap(bytes, offset, index) { |
||
32 | let x = 0; |
||
33 | let y = offset - 1; |
||
34 | let limit = parseInt(offset / 2, 10); |
||
35 | let swap; |
||
|
|||
36 | while(x < limit) { |
||
37 | swap = bytes[index + x]; |
||
38 | bytes[index + x] = bytes[index + y]; |
||
39 | bytes[index + y] = swap; |
||
40 | x++; |
||
41 | y--; |
||
42 | } |
||
43 | } |
||
44 | |||
45 | module.exports = endianness; |
||
46 |