-
Notifications
You must be signed in to change notification settings - Fork 3
/
section_header.hpp
68 lines (55 loc) · 1.19 KB
/
section_header.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef _TSD_SECTION_HEADER_HPP_
#define _TSD_SECTION_HEADER_HPP_
#include <cstdint>
#include "util.hpp"
namespace tsd
{
class section_header
{
public:
uint8_t table_id;
uint8_t section_syntax_indicator;
uint16_t section_length;
uint16_t table_id_extension;
uint8_t version;
uint8_t current_next_indicator;
uint8_t section_number;
uint8_t last_section_number;
public:
void unpack(
const uint8_t** pp,
const uint8_t* pend) {
const uint8_t* p = *pp;
if(pend - p < 3)
throw std::runtime_error("");
table_id = get8(p);
p += 1;
section_syntax_indicator = get8(p) >> 7;
section_length = get16(p) & 0x0FFF;
p += 2;
if(section_syntax_indicator == 0) {
*pp = p;
return;
}
if(pend - p < 5)
throw std::runtime_error("");
table_id_extension = get16(p);
p += 2;
version = (get8(p) >> 1) & 0x1F;
current_next_indicator = get8(p) & 0x01;
p += 1;
section_number = get8(p);
p += 1;
last_section_number = get8(p);
p += 1;
*pp = p;
}
size_t get_payload_length() const {
if(section_syntax_indicator)
return section_length-5;
else
return section_length;
}
};
}
#endif