MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / decodeRunLengthSingle

Method decodeRunLengthSingle

src/OpenLoco/src/S5/SawyerStream.cpp:128–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

126}
127
128void SawyerStreamReader::decodeRunLengthSingle(MemoryStream& buffer, std::span<const std::byte> data)
129{
130 for (size_t i = 0; i < data.size(); i++)
131 {
132 uint8_t rleCodeByte = static_cast<uint8_t>(data[i]);
133 if (rleCodeByte & 128)
134 {
135 i++;
136 if (i >= data.size())
137 {
138 throw Exception::RuntimeError(exceptionInvalidRLE);
139 }
140
141 auto copyLen = static_cast<size_t>(257 - rleCodeByte);
142 auto copyByte = data[i];
143 fillStream(buffer, copyByte, copyLen);
144 }
145 else
146 {
147 if (i + 1 >= data.size() || i + 1 + rleCodeByte + 1 > data.size())
148 {
149 throw Exception::RuntimeError(exceptionInvalidRLE);
150 }
151
152 auto copyLen = static_cast<size_t>(rleCodeByte + 1);
153 buffer.write(&data[i + 1], copyLen);
154 i += rleCodeByte + 1;
155 }
156 }
157}
158
159void SawyerStreamReader::decodeRunLengthMulti(MemoryStream& buffer, std::span<const std::byte> data)
160{

Callers

nothing calls this directly

Calls 3

fillStreamFunction · 0.85
sizeMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected