MCPcopy Create free account
hub / github.com/GlobedGD/globed2 / decode

Method decode

src/core/data/MultiColor.cpp:87–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85}
86
87Result<MultiColor> MultiColor::decode(std::span<const uint8_t> data) {
88 qn::ByteReader reader{data};
89 auto header = READER_UNWRAP(reader.readU8());
90 size_t count = header & 0b00111111;
91
92 Type type;
93 std::vector<Color3> colors;
94
95 switch (header >> 6) {
96 case 0b00: return Err("Invalid color type");
97 case 0b01: {
98 type = Type::Static;
99 colors.push_back(GEODE_UNWRAP(readRgb(reader)));
100 } break;
101
102 case 0b10: {
103 type = Type::Tinting;
104 colors = GEODE_UNWRAP(readColorList(reader, count));
105 } break;
106
107 case 0b11: {
108 type = Type::Gradient;
109 colors = GEODE_UNWRAP(readColorList(reader, count));
110 } break;
111 }
112
113 return Ok(MultiColor(
114 type,
115 std::move(colors)
116 ));
117}
118
119MultiColor MultiColor::fromColor(const Color3& color) {
120 return MultiColor(Type::Static, { color });

Callers

nothing calls this directly

Calls 3

readRgbFunction · 0.85
readColorListFunction · 0.85
MultiColorClass · 0.85

Tested by

no test coverage detected