|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright 2021-2023 Software Radio Systems Limited |
| 4 | + * |
| 5 | + * By using this file, you agree to the terms and conditions set |
| 6 | + * forth in the LICENSE file which can be found at the top level of |
| 7 | + * the distribution. |
| 8 | + * |
| 9 | + */ |
| 10 | + |
| 11 | +#include "srsran/ran/uci/uci_part2_size_calculator.h" |
| 12 | +#include "srsran/srsvec/bit.h" |
| 13 | + |
| 14 | +using namespace srsran; |
| 15 | + |
| 16 | +unsigned srsran::uci_part2_get_size(span<const uint8_t> part1, const uci_part2_size_description& descr) |
| 17 | +{ |
| 18 | + unsigned result = 0; |
| 19 | + |
| 20 | + // Iterate all entries. |
| 21 | + for (const uci_part2_size_description::entry& entry : descr.entries) { |
| 22 | + unsigned index = 0; |
| 23 | + unsigned index_bitwidth = 0; |
| 24 | + |
| 25 | + for (const uci_part2_size_description::parameter& parameter : entry.parameters) { |
| 26 | + // Extract the value of the parameter. |
| 27 | + unsigned value = srsvec::bit_pack(part1.subspan(parameter.offset, parameter.width)); |
| 28 | + |
| 29 | + // Combine the parameter value with the current index. |
| 30 | + index = (index << parameter.width) | value; |
| 31 | + |
| 32 | + // Accumulate the index bit width. |
| 33 | + index_bitwidth += parameter.width; |
| 34 | + } |
| 35 | + |
| 36 | + // Verify the map size is according to the index bit width. |
| 37 | + srsran_assert(entry.map.size() == (1U << index_bitwidth), |
| 38 | + "Invalid map size (i.e., {}), expected {} entries.", |
| 39 | + entry.map.size(), |
| 40 | + (1U << index_bitwidth)); |
| 41 | + |
| 42 | + // Verify that the index is within the map size. |
| 43 | + srsran_assert( |
| 44 | + index < entry.map.size(), "Index value (i.e., {}) exceeds the map size (i.e., {}).", index, entry.map.size()); |
| 45 | + |
| 46 | + // Add the Part 2 size corresponding to this entry. |
| 47 | + result += entry.map[index]; |
| 48 | + } |
| 49 | + |
| 50 | + return result; |
| 51 | +} |
0 commit comments