-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtraInfoSegment.cxx
55 lines (42 loc) · 2.39 KB
/
ExtraInfoSegment.cxx
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
//
// Created by Zhiping Jiang on 2020/11/6.
//
#include "ExtraInfoSegment.hxx"
static auto parserWrapper = [](const uint8_t *buffer, const uint32_t bufferLength) -> ExtraInfo {
if (const auto eiOpt = ExtraInfo::fromBuffer(buffer, 0)) {
if (const auto calculatedLength = eiOpt->calculateBufferLength(); calculatedLength != bufferLength - 4)
throw std::runtime_error("ExtraInfoSegment cannot decode due to the mismatched buffer length.");
return eiOpt.value();
}
throw std::runtime_error("ExtraInfoSegment cannot decode the given buffer.");
};
std::map<uint16_t, std::function<ExtraInfo(const uint8_t *, uint32_t)>> ExtraInfoSegment::versionedSolutionMap = initializeSolutionMap();
std::map<uint16_t, std::function<ExtraInfo(const uint8_t *, uint32_t)>> ExtraInfoSegment::initializeSolutionMap() noexcept {
return std::map<uint16_t, std::function<ExtraInfo(const uint8_t *, uint32_t)>>{{0x1U, parserWrapper},
{0x2U, parserWrapper}};
}
ExtraInfoSegment::ExtraInfoSegment() : AbstractPicoScenesFrameSegment("ExtraInfo", 0x2U) {}
ExtraInfoSegment::ExtraInfoSegment(ExtraInfo&& extraInfoV): AbstractPicoScenesFrameSegment("ExtraInfo", 0x2U), extraInfo(std::move(extraInfoV)) {
setSegmentPayload(std::move(extraInfoV.toBuffer()));
}
ExtraInfoSegment::ExtraInfoSegment(const ExtraInfo &extraInfoV) : ExtraInfoSegment() {
extraInfo = extraInfoV;
setSegmentPayload(std::move(extraInfoV.toBuffer()));
}
ExtraInfoSegment::ExtraInfoSegment(const uint8_t *buffer, uint32_t bufferLength) : AbstractPicoScenesFrameSegment(buffer, bufferLength) {
if (segmentName != "ExtraInfo")
throw std::runtime_error("ExtraInfoSegment cannot parse the segment named " + segmentName + ".");
if (!versionedSolutionMap.contains(segmentVersionId))
throw std::runtime_error("ExtraInfoSegment cannot parse the segment with version v" + std::to_string(segmentVersionId) + ".");
extraInfo = versionedSolutionMap.at(segmentVersionId)(segmentPayload.data(), segmentPayload.size());
}
const ExtraInfo &ExtraInfoSegment::getExtraInfo() const {
return extraInfo;
}
void ExtraInfoSegment::setExtraInfo(const ExtraInfo &extraInfoV) {
extraInfo = extraInfoV;
setSegmentPayload(std::move(extraInfo.toBuffer()));
}
std::string ExtraInfoSegment::toString() const {
return extraInfo.toString();
}