|
|
@ -197,19 +197,19 @@ int bit_ref_impl<Ptr>::distance_bytes() const
|
|
|
|
return ((int)(ptr - start_ptr)) + ((offset) ? 1 : 0);
|
|
|
|
return ((int)(ptr - start_ptr)) + ((offset) ? 1 : 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SRSASN_CODE bit_ref::pack(uint32_t val, uint32_t n_bits)
|
|
|
|
SRSASN_CODE bit_ref::pack(uint64_t val, uint32_t n_bits)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (n_bits >= 32) {
|
|
|
|
if (n_bits >= 64) {
|
|
|
|
log_error("This method only supports packing up to 32 bits\n");
|
|
|
|
log_error("This method only supports packing up to 64 bits\n");
|
|
|
|
return SRSASN_ERROR_ENCODE_FAIL;
|
|
|
|
return SRSASN_ERROR_ENCODE_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uint32_t mask;
|
|
|
|
uint64_t mask;
|
|
|
|
while (n_bits > 0) {
|
|
|
|
while (n_bits > 0) {
|
|
|
|
if (ptr >= max_ptr) {
|
|
|
|
if (ptr >= max_ptr) {
|
|
|
|
log_error("Buffer size limit was achieved\n");
|
|
|
|
log_error("Buffer size limit was achieved\n");
|
|
|
|
return SRSASN_ERROR_ENCODE_FAIL;
|
|
|
|
return SRSASN_ERROR_ENCODE_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mask = ((1u << n_bits) - 1u);
|
|
|
|
mask = ((1ul << n_bits) - 1ul);
|
|
|
|
val = val & mask;
|
|
|
|
val = val & mask;
|
|
|
|
uint8_t keepmask = ((uint8_t)-1) - (uint8_t)((1u << (8u - offset)) - 1u);
|
|
|
|
uint8_t keepmask = ((uint8_t)-1) - (uint8_t)((1u << (8u - offset)) - 1u);
|
|
|
|
if ((uint32_t)(8 - offset) > n_bits) {
|
|
|
|
if ((uint32_t)(8 - offset) > n_bits) {
|
|
|
@ -531,14 +531,12 @@ SRSASN_CODE pack_constrained_whole_number(bit_ref& bref, IntType n, IntType lb,
|
|
|
|
HANDLE_CODE(bref.pack(toencode, n_bits));
|
|
|
|
HANDLE_CODE(bref.pack(toencode, n_bits));
|
|
|
|
ret = bref.align_bytes_zero();
|
|
|
|
ret = bref.align_bytes_zero();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// TODO: Check if this is correct
|
|
|
|
|
|
|
|
uint32_t n_bits_len = (uint32_t)ceilf(log2f(ceil_frac(n_bits, 8u)));
|
|
|
|
uint32_t n_bits_len = (uint32_t)ceilf(log2f(ceil_frac(n_bits, 8u)));
|
|
|
|
n_bits = (uint32_t)floorf(log2f(SRSLTE_MAX(toencode, 1)) + 1);
|
|
|
|
n_bits = (uint32_t)floorf(log2f(std::max(toencode, (IntType)1)) + 1);
|
|
|
|
uint32_t n_octets = (uint32_t)((n_bits + 7) / 8);
|
|
|
|
uint32_t n_octets = ceil_frac(n_bits, 8u);
|
|
|
|
HANDLE_CODE(bref.pack(n_octets - 1, n_bits_len));
|
|
|
|
HANDLE_CODE(bref.pack(n_octets - 1, n_bits_len));
|
|
|
|
HANDLE_CODE(bref.align_bytes_zero());
|
|
|
|
HANDLE_CODE(bref.align_bytes_zero());
|
|
|
|
HANDLE_CODE(bref.pack(0, (n_octets * 8) - n_bits));
|
|
|
|
ret = bref.pack(toencode, n_octets * 8u);
|
|
|
|
ret = bref.pack(toencode, n_bits);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -601,7 +599,6 @@ SRSASN_CODE unpack_constrained_whole_number(IntType& n, cbit_ref& bref, IntType
|
|
|
|
HANDLE_CODE(bref.unpack(n, n_octets * 8));
|
|
|
|
HANDLE_CODE(bref.unpack(n, n_octets * 8));
|
|
|
|
HANDLE_CODE(bref.align_bytes());
|
|
|
|
HANDLE_CODE(bref.align_bytes());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// TODO: Check if this is correct
|
|
|
|
|
|
|
|
uint32_t n_bits_len = (uint32_t)ceilf(log2f(ceil_frac(n_bits, 8u)));
|
|
|
|
uint32_t n_bits_len = (uint32_t)ceilf(log2f(ceil_frac(n_bits, 8u)));
|
|
|
|
uint32_t n_octets;
|
|
|
|
uint32_t n_octets;
|
|
|
|
HANDLE_CODE(bref.unpack(n_octets, n_bits_len));
|
|
|
|
HANDLE_CODE(bref.unpack(n_octets, n_bits_len));
|
|
|
@ -974,10 +971,7 @@ template SRSASN_CODE unpack_unconstrained_integer<int64_t>(int64_t& n, cbit_ref&
|
|
|
|
// standalone packer
|
|
|
|
// standalone packer
|
|
|
|
template <class IntType>
|
|
|
|
template <class IntType>
|
|
|
|
integer_packer<IntType>::integer_packer(IntType lb_, IntType ub_, bool has_ext_, bool aligned_) :
|
|
|
|
integer_packer<IntType>::integer_packer(IntType lb_, IntType ub_, bool has_ext_, bool aligned_) :
|
|
|
|
lb(lb_),
|
|
|
|
lb(lb_), ub(ub_), has_ext(has_ext_), aligned(aligned_)
|
|
|
|
ub(ub_),
|
|
|
|
|
|
|
|
has_ext(has_ext_),
|
|
|
|
|
|
|
|
aligned(aligned_)
|
|
|
|
|
|
|
|
{}
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
template <class IntType>
|
|
|
|
template <class IntType>
|
|
|
|