Create an ALC packet from payload data.
25 throw std::runtime_error(
"Packet too short");
28 std::memcpy(&_lct_header,
data, 4);
29 if (_lct_header.version != 1) {
30 throw std::runtime_error(
"Unsupported LCT version");
33 char* hdr_ptr =
data + 4;
34 if (_lct_header.congestion_control_flag != 0) {
35 throw std::runtime_error(
"Unsupported CCI field length");
40 if (_lct_header.half_word_flag == 0 && _lct_header.tsi_flag == 0) {
41 throw std::runtime_error(
"TSI field not present");
44 if(_lct_header.half_word_flag == 1) {
45 _tsi = ntohs(*(uint16_t*)hdr_ptr);
49 if(_lct_header.tsi_flag == 1) {
50 _tsi |= ntohl(*(uint32_t*)hdr_ptr) << tsi_shift;
54 if ( _lct_header.close_session_flag == 0 && _lct_header.half_word_flag == 0 && _lct_header.toi_flag == 0) {
55 throw std::runtime_error(
"TOI field not present");
58 if(_lct_header.half_word_flag == 1) {
59 _toi = ntohs(*(uint16_t*)hdr_ptr);
63 switch(_lct_header.toi_flag) {
66 _toi |= ntohl(*(uint32_t*)hdr_ptr) << toi_shift;
71 throw std::runtime_error(
"TOI fields over 64 bits in length are not supported");
73 _toi = ntohl(*(uint32_t*)hdr_ptr);
75 _toi |= (uint64_t)(ntohl(*(uint32_t*)hdr_ptr)) << 32;
80 throw std::runtime_error(
"TOI fields over 64 bits in length are not supported");
83 if (_lct_header.codepoint == 0) {
86 throw std::runtime_error(
"Only Compact No-Code FEC is supported");
89 auto expected_header_len = 2 +
90 _lct_header.congestion_control_flag +
91 _lct_header.half_word_flag +
92 _lct_header.tsi_flag +
95 size_t ext_header_len = (_lct_header.lct_header_len - expected_header_len) * 4;
96 while (ext_header_len > 0) {
97 auto ext_ptr = hdr_ptr;
98 uint8_t het = *ext_ptr;
108 if (ext_len > ext_header_len) {
109 throw std::runtime_error(
"Header extension length exceeds remaining header length");
112 switch ((AlcPacket::HeaderExtension)het) {
121 throw std::runtime_error(
"Invalid length for EXT_FTI header extension");
123 _fec_oti.
transfer_length = (uint64_t)(ntohs(*(uint16_t*)ext_ptr)) << 32;
135 uint8_t flute_version = (*ext_ptr & 0xF0) >> 4;
136 if (flute_version > 2) {
137 throw std::runtime_error(
"Unsupported FLUTE version");
139 _fdt_instance_id = (*ext_ptr & 0x0F) << 16;
141 _fdt_instance_id |= ntohs(*(uint16_t*)ext_ptr);
145 uint8_t encoding = *ext_ptr;
156 ext_header_len -= ext_len;
char * data() const
Get a pointer to the payload data of the constructed packet.
uint32_t max_source_block_length
uint32_t encoding_symbol_length