etsi_its_messages
v3.5.0
Toggle main menu visibility
Loading...
Searching...
No Matches
asn1_primitives_getters.h
1
// SPDX-License-Identifier: MIT
2
// Copyright Institute for Automotive Engineering (ika), RWTH Aachen University
3
4
#ifndef ETSI_ITS_MSGS_UTILS_IMPL_ASN1_PRIMITIVES_ASN1_PRIMITIVES_GETTERS_H
5
#define ETSI_ITS_MSGS_UTILS_IMPL_ASN1_PRIMITIVES_ASN1_PRIMITIVES_GETTERS_H
6
11
19
inline
std::vector<bool> getBitString(
const
std::vector<uint8_t>& buffer,
const
int
bits_unused) {
20
21
// bit string size
22
const
int
bits_per_byte = 8;
23
const
int
n_bytes = buffer.size();
24
const
int
n_bits = n_bytes * bits_per_byte;
25
std::vector<bool> bits;
26
bits.resize(n_bits - bits_unused, 0);
27
28
// loop over bytes
29
for
(
int
byte_idx = 0; byte_idx < n_bytes; byte_idx++) {
30
31
// loop over bits in a byte
32
for
(
int
bit_idx_in_byte = 0; bit_idx_in_byte < bits_per_byte; bit_idx_in_byte++) {
33
34
// map bit index in byte to bit index in total bitstring
35
int
bit_idx = bit_idx_in_byte + byte_idx * bits_per_byte;
36
if
((byte_idx + 1) >= n_bytes && (bit_idx_in_byte + bits_unused) >= bits_per_byte)
break
;
37
38
// extract bit from bitstring and set output array entry appropriately
39
bool
byte_has_true_bit =
static_cast<
bool
>
(buffer[byte_idx] & (1 << (bits_per_byte - 1 - bit_idx_in_byte)));
40
if
(byte_has_true_bit) bits[bit_idx] =
true
;
41
}
42
}
43
return
bits;
44
}
45
46
#endif
// ETSI_ITS_MSGS_UTILS_IMPL_ASN1_PRIMITIVES_GETTERS_H
etsi_its_msgs_utils
include
etsi_its_msgs_utils
impl
asn1_primitives
asn1_primitives_getters.h
Generated by
1.17.0