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

Method decodeHeader

src/modules/scripting/data/EmbeddedScript.cpp:65–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65std::optional<size_t> EmbeddedScript::decodeHeader(std::span<const uint8_t> data) {
66 // scan until a null byte is found
67 auto it = data.begin();
68
69
70 while (it != data.end() && *it != '\0') {
71 it++;
72 }
73
74 if (it == data.end()) {
75 return std::nullopt;
76 }
77
78 // skip null byte
79 it++;
80
81 size_t distance = std::distance(it, data.end());
82 if (distance < EMBEDDED_SCRIPT_MAGIC.size()) {
83 return std::nullopt;
84 }
85
86 for (auto m : EMBEDDED_SCRIPT_MAGIC) {
87 if ((uint8_t)m != *it) {
88 return std::nullopt;
89 }
90
91 it++;
92 }
93
94 return std::distance(data.begin(), it);
95}
96
97Result<std::vector<uint8_t>> EmbeddedScript::encode(bool includePrefix, std::string_view prefixStr) const {
98 qn::HeapByteWriter writer;

Callers

nothing calls this directly

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected