C++: parser code: propagate format version into individual parsing methods

This allows us to differentiate once we introduce new formats.
backup
Christian Seiler 2 weeks ago
parent c77efa8461
commit efc4ed8de4
  1. 77
      cpp/src/monoformat_parseonly.cpp
  2. 82
      cpp/src/monoformat_structured.cpp
  3. 22
      cpp/src/monoformat_structured.hpp

@ -23,16 +23,18 @@ struct TimeBasedDrawnSectionMetaData {
std::int64_t endTimestamp{};
};
static std::expected<void, ParseError> handleImage(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts);
static std::expected<void, ParseError> handleAnimation(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts);
static std::expected<void, ParseError> handleHScrollImage(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts);
static std::expected<void, ParseError> handleVScrollImage(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts);
static std::expected<void, ParseError> handleLine(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts);
static std::expected<void, ParseError> handleClippedText(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts);
static std::expected<void, ParseError> handleHScrollText(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts);
static std::expected<void, ParseError> handleCurrentTime(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts);
static std::expected<AlwaysDrawnSectionMetaData, ParseError> parseAlwaysDrawnSection(std::span<std::byte const>& data) {
static std::expected<void, ParseError> handleImage(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts, std::uint32_t formatVersion);
static std::expected<void, ParseError> handleAnimation(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts, std::uint32_t formatVersion);
static std::expected<void, ParseError> handleHScrollImage(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts, std::uint32_t formatVersion);
static std::expected<void, ParseError> handleVScrollImage(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts, std::uint32_t formatVersion);
static std::expected<void, ParseError> handleLine(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts, std::uint32_t formatVersion);
static std::expected<void, ParseError> handleClippedText(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts, std::uint32_t formatVersion);
static std::expected<void, ParseError> handleHScrollText(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts, std::uint32_t formatVersion);
static std::expected<void, ParseError> handleCurrentTime(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts, std::uint32_t formatVersion);
static std::expected<AlwaysDrawnSectionMetaData, ParseError> parseAlwaysDrawnSection(std::span<std::byte const>& data, std::uint32_t formatVersion) {
std::ignore = formatVersion;
auto type = readU8LE(data);
if (!type) {
return std::unexpected(type.error());
@ -71,7 +73,9 @@ static std::expected<AlwaysDrawnSectionMetaData, ParseError> parseAlwaysDrawnSec
return result;
}
static std::expected<TimeBasedDrawnSectionMetaData, ParseError> parseTimeBasedDrawnSection(std::span<std::byte const>& data) {
static std::expected<TimeBasedDrawnSectionMetaData, ParseError> parseTimeBasedDrawnSection(std::span<std::byte const>& data, std::uint32_t formatVersion) {
std::ignore = formatVersion;
auto type = readU8LE(data);
if (!type) {
return std::unexpected(type.error());
@ -120,7 +124,9 @@ static std::expected<TimeBasedDrawnSectionMetaData, ParseError> parseTimeBasedDr
return result;
}
static std::expected<std::span<std::byte const>, ParseError> parseCustomFontSection(std::span<std::byte const>& data) {
static std::expected<std::span<std::byte const>, ParseError> parseCustomFontSection(std::span<std::byte const>& data, std::uint32_t formatVersion) {
std::ignore = formatVersion;
auto type = readU8LE(data);
if (!type) {
return std::unexpected(type.error());
@ -197,7 +203,7 @@ std::expected<void, ParseError> parseAndApply(std::span<std::byte const> data, O
}
if (static_cast<SectionType>(*sectionType) == SectionType::CustomFont) {
auto fontData = parseCustomFontSection(*rawSectionData);
auto fontData = parseCustomFontSection(*rawSectionData, *version);
if (!fontData) {
return std::unexpected(fontData.error());
}
@ -209,13 +215,13 @@ std::expected<void, ParseError> parseAndApply(std::span<std::byte const> data, O
AlwaysDrawnSectionMetaData section;
if (static_cast<SectionType>(*sectionType) == SectionType::AlwaysDrawn) {
auto metaData = parseAlwaysDrawnSection(*rawSectionData);
auto metaData = parseAlwaysDrawnSection(*rawSectionData, *version);
if (!metaData) {
return std::unexpected(metaData.error());
}
section = *metaData;
} else if (static_cast<SectionType>(*sectionType) == SectionType::TimeBasedDrawn) {
auto metaData = parseTimeBasedDrawnSection(*rawSectionData);
auto metaData = parseTimeBasedDrawnSection(*rawSectionData, *version);
if (!metaData) {
return std::unexpected(metaData.error());
}
@ -249,14 +255,14 @@ std::expected<void, ParseError> parseAndApply(std::span<std::byte const> data, O
auto eType = static_cast<ElementType>(*type);
std::expected<void, ParseError> parseResult;
switch (eType) {
case ElementType::Image: parseResult = handleImage(section.elementData, screen, animationTick, currentTimestamp, std::span{customFonts}.subspan(0, customFontIndex)); break;
case ElementType::Animation: parseResult = handleAnimation(section.elementData, screen, animationTick, currentTimestamp, std::span{customFonts}.subspan(0, customFontIndex)); break;
case ElementType::HScrollImage: parseResult = handleHScrollImage(section.elementData, screen, animationTick, currentTimestamp, std::span{customFonts}.subspan(0, customFontIndex)); break;
case ElementType::VScrollImage: parseResult = handleVScrollImage(section.elementData, screen, animationTick, currentTimestamp, std::span{customFonts}.subspan(0, customFontIndex)); break;
case ElementType::Line: parseResult = handleLine(section.elementData, screen, animationTick, currentTimestamp, std::span{customFonts}.subspan(0, customFontIndex)); break;
case ElementType::ClippedText: parseResult = handleClippedText(section.elementData, screen, animationTick, currentTimestamp, std::span{customFonts}.subspan(0, customFontIndex)); break;
case ElementType::HScrollText: parseResult = handleHScrollText(section.elementData, screen, animationTick, currentTimestamp, std::span{customFonts}.subspan(0, customFontIndex)); break;
case ElementType::CurrentTime: parseResult = handleCurrentTime(section.elementData, screen, animationTick, currentTimestamp, std::span{customFonts}.subspan(0, customFontIndex)); break;
case ElementType::Image: parseResult = handleImage(section.elementData, screen, animationTick, currentTimestamp, std::span{customFonts}.subspan(0, customFontIndex), *version); break;
case ElementType::Animation: parseResult = handleAnimation(section.elementData, screen, animationTick, currentTimestamp, std::span{customFonts}.subspan(0, customFontIndex), *version); break;
case ElementType::HScrollImage: parseResult = handleHScrollImage(section.elementData, screen, animationTick, currentTimestamp, std::span{customFonts}.subspan(0, customFontIndex), *version); break;
case ElementType::VScrollImage: parseResult = handleVScrollImage(section.elementData, screen, animationTick, currentTimestamp, std::span{customFonts}.subspan(0, customFontIndex), *version); break;
case ElementType::Line: parseResult = handleLine(section.elementData, screen, animationTick, currentTimestamp, std::span{customFonts}.subspan(0, customFontIndex), *version); break;
case ElementType::ClippedText: parseResult = handleClippedText(section.elementData, screen, animationTick, currentTimestamp, std::span{customFonts}.subspan(0, customFontIndex), *version); break;
case ElementType::HScrollText: parseResult = handleHScrollText(section.elementData, screen, animationTick, currentTimestamp, std::span{customFonts}.subspan(0, customFontIndex), *version); break;
case ElementType::CurrentTime: parseResult = handleCurrentTime(section.elementData, screen, animationTick, currentTimestamp, std::span{customFonts}.subspan(0, customFontIndex), *version); break;
default: parseResult = std::unexpected(ParseError::InvalidValue);
}
@ -269,7 +275,9 @@ std::expected<void, ParseError> parseAndApply(std::span<std::byte const> data, O
return {};
}
std::expected<void, ParseError> handleImage(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts) {
std::expected<void, ParseError> handleImage(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts, std::uint32_t formatVersion) {
std::ignore = formatVersion;
auto type = readU16LE(buffer);
if (!type) {
return std::unexpected(type.error());
@ -324,7 +332,8 @@ std::expected<void, ParseError> handleImage(std::span<std::byte const>& buffer,
return {};
}
std::expected<void, ParseError> handleAnimation(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts) {
std::expected<void, ParseError> handleAnimation(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts, std::uint32_t formatVersion) {
std::ignore = formatVersion;
std::ignore = currentTimestamp;
std::ignore = customFonts;
@ -396,7 +405,8 @@ std::expected<void, ParseError> handleAnimation(std::span<std::byte const>& buff
return {};
}
std::expected<void, ParseError> handleHScrollImage(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts) {
std::expected<void, ParseError> handleHScrollImage(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts, std::uint32_t formatVersion) {
std::ignore = formatVersion;
std::ignore = currentTimestamp;
std::ignore = customFonts;
@ -561,7 +571,8 @@ std::expected<void, ParseError> handleHScrollImage(std::span<std::byte const>& b
return {};
}
std::expected<void, ParseError> handleVScrollImage(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts) {
std::expected<void, ParseError> handleVScrollImage(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts, std::uint32_t formatVersion) {
std::ignore = formatVersion;
std::ignore = currentTimestamp;
std::ignore = customFonts;
@ -726,7 +737,8 @@ std::expected<void, ParseError> handleVScrollImage(std::span<std::byte const>& b
return {};
}
std::expected<void, ParseError> handleLine(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts) {
std::expected<void, ParseError> handleLine(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts, std::uint32_t formatVersion) {
std::ignore = formatVersion;
std::ignore = animationTick;
std::ignore = currentTimestamp;
std::ignore = customFonts;
@ -798,7 +810,8 @@ std::expected<void, ParseError> handleLine(std::span<std::byte const>& buffer, O
return {};
}
std::expected<void, ParseError> handleClippedText(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts) {
std::expected<void, ParseError> handleClippedText(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts, std::uint32_t formatVersion) {
std::ignore = formatVersion;
std::ignore = animationTick;
std::ignore = currentTimestamp;
@ -867,7 +880,8 @@ std::expected<void, ParseError> handleClippedText(std::span<std::byte const>& bu
return {};
}
std::expected<void, ParseError> handleHScrollText(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts) {
std::expected<void, ParseError> handleHScrollText(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts, std::uint32_t formatVersion) {
std::ignore = formatVersion;
std::ignore = currentTimestamp;
auto type = readU16LE(buffer);
@ -1028,7 +1042,8 @@ std::expected<void, ParseError> handleHScrollText(std::span<std::byte const>& bu
return {};
}
std::expected<void, ParseError> handleCurrentTime(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts) {
std::expected<void, ParseError> handleCurrentTime(std::span<std::byte const>& buffer, OneBitBufferInterface* screen, std::size_t animationTick, std::int64_t currentTimestamp, std::span<std::span<std::byte const>> customFonts, std::uint32_t formatVersion) {
std::ignore = formatVersion;
std::ignore = animationTick;
auto type = readU16LE(buffer);

@ -85,7 +85,9 @@ void ImageElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animat
}
}
std::expected<std::unique_ptr<ImageElement>, ParseError> ImageElement::parse(std::span<std::byte const>& buffer) {
std::expected<std::unique_ptr<ImageElement>, ParseError> ImageElement::parse(std::span<std::byte const>& buffer, std::uint32_t formatVersion) {
std::ignore = formatVersion;
auto type = readU16LE(buffer);
if (!type) {
return std::unexpected(type.error());
@ -242,7 +244,9 @@ void AnimationElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t an
}
}
std::expected<std::unique_ptr<AnimationElement>, ParseError> AnimationElement::parse(std::span<std::byte const>& buffer) {
std::expected<std::unique_ptr<AnimationElement>, ParseError> AnimationElement::parse(std::span<std::byte const>& buffer, std::uint32_t formatVersion) {
std::ignore = formatVersion;
auto type = readU16LE(buffer);
if (!type) {
return std::unexpected(type.error());
@ -482,7 +486,9 @@ void HScrollImageElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t
}
}
std::expected<std::unique_ptr<HScrollImageElement>, ParseError> HScrollImageElement::parse(std::span<std::byte const>& buffer) {
std::expected<std::unique_ptr<HScrollImageElement>, ParseError> HScrollImageElement::parse(std::span<std::byte const>& buffer, std::uint32_t formatVersion) {
std::ignore = formatVersion;
auto type = readU16LE(buffer);
if (!type) {
return std::unexpected(type.error());
@ -726,7 +732,9 @@ void VScrollImageElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t
}
}
std::expected<std::unique_ptr<VScrollImageElement>, ParseError> VScrollImageElement::parse(std::span<std::byte const>& buffer) {
std::expected<std::unique_ptr<VScrollImageElement>, ParseError> VScrollImageElement::parse(std::span<std::byte const>& buffer, std::uint32_t formatVersion) {
std::ignore = formatVersion;
auto type = readU16LE(buffer);
if (!type) {
return std::unexpected(type.error());
@ -861,7 +869,9 @@ void LineElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animati
}
}
std::expected<std::unique_ptr<LineElement>, ParseError> LineElement::parse(std::span<std::byte const>& buffer) {
std::expected<std::unique_ptr<LineElement>, ParseError> LineElement::parse(std::span<std::byte const>& buffer, std::uint32_t formatVersion) {
std::ignore = formatVersion;
auto type = readU16LE(buffer);
if (!type) {
return std::unexpected(type.error());
@ -978,7 +988,9 @@ void ClippedTextElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t
renderer.render(m_text, Point{0, static_cast<std::int32_t>(renderer.lineHeight() - 1)}, target, true, false);
}
std::expected<std::unique_ptr<ClippedTextElement>, ParseError> ClippedTextElement::parse(std::span<std::byte const>& buffer) {
std::expected<std::unique_ptr<ClippedTextElement>, ParseError> ClippedTextElement::parse(std::span<std::byte const>& buffer, std::uint32_t formatVersion) {
std::ignore = formatVersion;
auto type = readU16LE(buffer);
if (!type) {
return std::unexpected(type.error());
@ -1190,7 +1202,9 @@ void HScrollTextElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t
}
}
std::expected<std::unique_ptr<HScrollTextElement>, ParseError> HScrollTextElement::parse(std::span<std::byte const>& buffer) {
std::expected<std::unique_ptr<HScrollTextElement>, ParseError> HScrollTextElement::parse(std::span<std::byte const>& buffer, std::uint32_t formatVersion) {
std::ignore = formatVersion;
auto type = readU16LE(buffer);
if (!type) {
return std::unexpected(type.error());
@ -1356,7 +1370,9 @@ void CurrentTimeElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t
renderer.render(text, Point{0, static_cast<std::int32_t>(renderer.lineHeight() - 1)}, target, true, false);
}
std::expected<std::unique_ptr<CurrentTimeElement>, ParseError> CurrentTimeElement::parse(std::span<std::byte const>& buffer) {
std::expected<std::unique_ptr<CurrentTimeElement>, ParseError> CurrentTimeElement::parse(std::span<std::byte const>& buffer, std::uint32_t formatVersion) {
std::ignore = formatVersion;
auto type = readU16LE(buffer);
if (!type) {
return std::unexpected(type.error());
@ -1492,7 +1508,9 @@ std::size_t AlwaysDrawnSection::serializeTo(std::span<std::byte> target) const {
return pos;
}
std::expected<std::unique_ptr<AlwaysDrawnSection>, ParseError> AlwaysDrawnSection::parse(std::span<std::byte const>& buffer) {
std::expected<std::unique_ptr<AlwaysDrawnSection>, ParseError> AlwaysDrawnSection::parse(std::span<std::byte const>& buffer, std::uint32_t formatVersion) {
std::ignore = formatVersion;
auto type = readU8LE(buffer);
if (!type) {
return std::unexpected(type.error());
@ -1529,14 +1547,14 @@ std::expected<std::unique_ptr<AlwaysDrawnSection>, ParseError> AlwaysDrawnSectio
}
std::expected<std::unique_ptr<Element>, ParseError> element;
switch (static_cast<ElementType>(*type)) {
case ElementType::Image: element = ImageElement::parse(sectionData); break;
case ElementType::Animation: element = AnimationElement::parse(sectionData); break;
case ElementType::HScrollImage: element = HScrollImageElement::parse(sectionData); break;
case ElementType::VScrollImage: element = VScrollImageElement::parse(sectionData); break;
case ElementType::Line: element = LineElement::parse(sectionData); break;
case ElementType::ClippedText: element = ClippedTextElement::parse(sectionData); break;
case ElementType::HScrollText: element = HScrollTextElement::parse(sectionData); break;
case ElementType::CurrentTime: element = CurrentTimeElement::parse(sectionData); break;
case ElementType::Image: element = ImageElement::parse(sectionData, formatVersion); break;
case ElementType::Animation: element = AnimationElement::parse(sectionData, formatVersion); break;
case ElementType::HScrollImage: element = HScrollImageElement::parse(sectionData, formatVersion); break;
case ElementType::VScrollImage: element = VScrollImageElement::parse(sectionData, formatVersion); break;
case ElementType::Line: element = LineElement::parse(sectionData, formatVersion); break;
case ElementType::ClippedText: element = ClippedTextElement::parse(sectionData, formatVersion); break;
case ElementType::HScrollText: element = HScrollTextElement::parse(sectionData, formatVersion); break;
case ElementType::CurrentTime: element = CurrentTimeElement::parse(sectionData, formatVersion); break;
default:
return std::unexpected(ParseError::InvalidValue);
}
@ -1662,7 +1680,9 @@ std::size_t TimeBasedDrawnSection::serializeTo(std::span<std::byte> target) cons
return pos;
}
std::expected<std::unique_ptr<TimeBasedDrawnSection>, ParseError> TimeBasedDrawnSection::parse(std::span<std::byte const>& buffer) {
std::expected<std::unique_ptr<TimeBasedDrawnSection>, ParseError> TimeBasedDrawnSection::parse(std::span<std::byte const>& buffer, std::uint32_t formatVersion) {
std::ignore = formatVersion;
auto type = readU8LE(buffer);
if (!type) {
return std::unexpected(type.error());
@ -1709,14 +1729,14 @@ std::expected<std::unique_ptr<TimeBasedDrawnSection>, ParseError> TimeBasedDrawn
}
std::expected<std::unique_ptr<Element>, ParseError> element;
switch (static_cast<ElementType>(*type)) {
case ElementType::Image: element = ImageElement::parse(sectionData); break;
case ElementType::Animation: element = AnimationElement::parse(sectionData); break;
case ElementType::HScrollImage: element = HScrollImageElement::parse(sectionData); break;
case ElementType::VScrollImage: element = VScrollImageElement::parse(sectionData); break;
case ElementType::Line: element = LineElement::parse(sectionData); break;
case ElementType::ClippedText: element = ClippedTextElement::parse(sectionData); break;
case ElementType::HScrollText: element = HScrollTextElement::parse(sectionData); break;
case ElementType::CurrentTime: element = CurrentTimeElement::parse(sectionData); break;
case ElementType::Image: element = ImageElement::parse(sectionData, formatVersion); break;
case ElementType::Animation: element = AnimationElement::parse(sectionData, formatVersion); break;
case ElementType::HScrollImage: element = HScrollImageElement::parse(sectionData, formatVersion); break;
case ElementType::VScrollImage: element = VScrollImageElement::parse(sectionData, formatVersion); break;
case ElementType::Line: element = LineElement::parse(sectionData, formatVersion); break;
case ElementType::ClippedText: element = ClippedTextElement::parse(sectionData, formatVersion); break;
case ElementType::HScrollText: element = HScrollTextElement::parse(sectionData, formatVersion); break;
case ElementType::CurrentTime: element = CurrentTimeElement::parse(sectionData, formatVersion); break;
default:
return std::unexpected(ParseError::InvalidValue);
}
@ -1757,7 +1777,9 @@ std::size_t CustomFontSection::serializeTo(std::span<std::byte> target) const {
return pos;
}
std::expected<std::unique_ptr<CustomFontSection>, ParseError> CustomFontSection::parse(std::span<std::byte const>& buffer) {
std::expected<std::unique_ptr<CustomFontSection>, ParseError> CustomFontSection::parse(std::span<std::byte const>& buffer, std::uint32_t formatVersion) {
std::ignore = formatVersion;
auto type = readU8LE(buffer);
if (!type) {
return std::unexpected(type.error());
@ -1849,9 +1871,9 @@ std::expected<File, ParseError> parseFile(std::span<std::byte const> data) {
std::expected<std::unique_ptr<Section>, ParseError> section;
switch (static_cast<SectionType>(*sectionType)) {
case SectionType::AlwaysDrawn: section = AlwaysDrawnSection::parse(data); break;
case SectionType::TimeBasedDrawn: section = TimeBasedDrawnSection::parse(data); break;
case SectionType::CustomFont: section = CustomFontSection::parse(data); break;
case SectionType::AlwaysDrawn: section = AlwaysDrawnSection::parse(data, *version); break;
case SectionType::TimeBasedDrawn: section = TimeBasedDrawnSection::parse(data, *version); break;
case SectionType::CustomFont: section = CustomFontSection::parse(data, *version); break;
default: return std::unexpected(ParseError::InvalidValue);
}

@ -51,7 +51,7 @@ struct ImageElement : public Element {
virtual std::size_t serializeTo(std::span<std::byte> target) const override;
virtual void drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp, std::span<CustomFontSection const*> customFonts) override;
static std::expected<std::unique_ptr<ImageElement>, ParseError> parse(std::span<std::byte const>& buffer);
static std::expected<std::unique_ptr<ImageElement>, ParseError> parse(std::span<std::byte const>& buffer, std::uint32_t formatVersion);
private:
std::uint16_t m_x{};
@ -83,7 +83,7 @@ struct AnimationElement : public Element {
virtual std::size_t serializeTo(std::span<std::byte> target) const override;
virtual void drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp, std::span<CustomFontSection const*> customFonts) override;
static std::expected<std::unique_ptr<AnimationElement>, ParseError> parse(std::span<std::byte const>& buffer);
static std::expected<std::unique_ptr<AnimationElement>, ParseError> parse(std::span<std::byte const>& buffer, std::uint32_t formatVersion);
private:
std::uint16_t m_x{};
@ -116,7 +116,7 @@ struct HScrollImageElement : public Element {
virtual std::size_t serializeTo(std::span<std::byte> target) const override;
virtual void drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp, std::span<CustomFontSection const*> customFonts) override;
static std::expected<std::unique_ptr<HScrollImageElement>, ParseError> parse(std::span<std::byte const>& buffer);
static std::expected<std::unique_ptr<HScrollImageElement>, ParseError> parse(std::span<std::byte const>& buffer, std::uint32_t formatVersion);
private:
std::uint16_t m_x{};
@ -150,7 +150,7 @@ struct VScrollImageElement : public Element {
virtual std::size_t serializeTo(std::span<std::byte> target) const override;
virtual void drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp, std::span<CustomFontSection const*> customFonts) override;
static std::expected<std::unique_ptr<VScrollImageElement>, ParseError> parse(std::span<std::byte const>& buffer);
static std::expected<std::unique_ptr<VScrollImageElement>, ParseError> parse(std::span<std::byte const>& buffer, std::uint32_t formatVersion);
private:
std::uint16_t m_x{};
@ -178,7 +178,7 @@ struct LineElement : public Element {
virtual std::size_t serializeTo(std::span<std::byte> target) const override;
virtual void drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp, std::span<CustomFontSection const*> customFonts) override;
static std::expected<std::unique_ptr<LineElement>, ParseError> parse(std::span<std::byte const>& buffer);
static std::expected<std::unique_ptr<LineElement>, ParseError> parse(std::span<std::byte const>& buffer, std::uint32_t formatVersion);
private:
std::uint16_t m_originX{};
@ -204,7 +204,7 @@ struct ClippedTextElement : public Element {
virtual std::size_t serializeTo(std::span<std::byte> target) const override;
virtual void drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp, std::span<CustomFontSection const*> customFonts) override;
static std::expected<std::unique_ptr<ClippedTextElement>, ParseError> parse(std::span<std::byte const>& buffer);
static std::expected<std::unique_ptr<ClippedTextElement>, ParseError> parse(std::span<std::byte const>& buffer, std::uint32_t formatVersion);
private:
std::uint16_t m_x{};
@ -232,7 +232,7 @@ struct HScrollTextElement : public Element {
virtual std::size_t serializeTo(std::span<std::byte> target) const override;
virtual void drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp, std::span<CustomFontSection const*> customFonts) override;
static std::expected<std::unique_ptr<HScrollTextElement>, ParseError> parse(std::span<std::byte const>& buffer);
static std::expected<std::unique_ptr<HScrollTextElement>, ParseError> parse(std::span<std::byte const>& buffer, std::uint32_t formatVersion);
private:
std::uint16_t m_x{};
@ -261,7 +261,7 @@ struct CurrentTimeElement : public Element {
virtual std::size_t serializeTo(std::span<std::byte> target) const override;
virtual void drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp, std::span<CustomFontSection const*> customFonts) override;
static std::expected<std::unique_ptr<CurrentTimeElement>, ParseError> parse(std::span<std::byte const>& buffer);
static std::expected<std::unique_ptr<CurrentTimeElement>, ParseError> parse(std::span<std::byte const>& buffer, std::uint32_t formatVersion);
private:
std::uint16_t m_x{};
@ -296,7 +296,7 @@ struct AlwaysDrawnSection : public Section {
virtual SectionType sectionType() const override;
virtual std::size_t serializeTo(std::span<std::byte> target) const override;
static std::expected<std::unique_ptr<AlwaysDrawnSection>, ParseError> parse(std::span<std::byte const>& buffer);
static std::expected<std::unique_ptr<AlwaysDrawnSection>, ParseError> parse(std::span<std::byte const>& buffer, std::uint32_t formatVersion);
private:
std::vector<std::unique_ptr<Element>> m_elements;
@ -333,7 +333,7 @@ struct TimeBasedDrawnSection : public Section {
virtual SectionType sectionType() const override;
virtual std::size_t serializeTo(std::span<std::byte> target) const override;
static std::expected<std::unique_ptr<TimeBasedDrawnSection>, ParseError> parse(std::span<std::byte const>& buffer);
static std::expected<std::unique_ptr<TimeBasedDrawnSection>, ParseError> parse(std::span<std::byte const>& buffer, std::uint32_t formatVersion);
private:
std::vector<std::unique_ptr<Element>> m_elements;
@ -354,7 +354,7 @@ struct CustomFontSection : public Section {
virtual SectionType sectionType() const override;
virtual std::size_t serializeTo(std::span<std::byte> target) const override;
static std::expected<std::unique_ptr<CustomFontSection>, ParseError> parse(std::span<std::byte const>& buffer);
static std::expected<std::unique_ptr<CustomFontSection>, ParseError> parse(std::span<std::byte const>& buffer, std::uint32_t formatVersion);
private:
std::vector<std::byte> m_fontData;

Loading…
Cancel
Save