18 lines
724 B
C++
18 lines
724 B
C++
#include "core/zxml.h"
|
|
#include <cstring>
|
|
|
|
namespace playground {
|
|
|
|
bool isZxml(const Bytes& b) { return b.size() >= 12 && std::memcmp(b.data(), "ZXML", 4) == 0; }
|
|
|
|
static uint32_t rd32(const uint8_t* p) { return p[0] | (p[1] << 8) | (p[2] << 16) | (uint32_t(p[3]) << 24); }
|
|
|
|
bool zxmlDecode(const Bytes& in, Bytes& out, std::string* err) {
|
|
if (!isZxml(in)) { if (err) *err = "not ZXML"; return false; }
|
|
uint32_t comp = rd32(in.data() + 4), raw = rd32(in.data() + 8);
|
|
if (size_t(comp) + 12 > in.size()) { if (err) *err = "ZXML truncated"; return false; }
|
|
if (!zlibInflate(in.data() + 12, comp, out, raw)) { if (err) *err = "ZXML inflate failed"; return false; }
|
|
return true;
|
|
}
|
|
|
|
} // namespace playground
|