MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / set_code_buffer

Method set_code_buffer

modules/gdscript/gdscript_tokenizer_buffer.cpp:147–246  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

145}
146
147Error GDScriptTokenizerBuffer::set_code_buffer(const Vector<uint8_t> &p_buffer) {
148 const uint8_t *buf = p_buffer.ptr();
149 ERR_FAIL_COND_V(p_buffer.size() < 12 || p_buffer[0] != 'G' || p_buffer[1] != 'D' || p_buffer[2] != 'S' || p_buffer[3] != 'C', ERR_INVALID_DATA);
150
151 int version = decode_uint32(&buf[4]);
152 ERR_FAIL_COND_V_MSG(version != TOKENIZER_VERSION, ERR_INVALID_DATA, "Binary GDScript is not compatible with this engine version.");
153
154 int decompressed_size = decode_uint32(&buf[8]);
155
156 Vector<uint8_t> contents;
157 if (decompressed_size == 0) {
158 contents = p_buffer.slice(12);
159 } else {
160 contents.resize(decompressed_size);
161 const int64_t result = Compression::decompress(contents.ptrw(), contents.size(), &buf[12], p_buffer.size() - 12, Compression::MODE_ZSTD);
162 ERR_FAIL_COND_V_MSG(result != decompressed_size, ERR_INVALID_DATA, "Error decompressing GDScript tokenizer buffer.");
163 }
164
165 int total_len = contents.size();
166 buf = contents.ptr();
167 uint32_t identifier_count = decode_uint32(&buf[0]);
168 uint32_t constant_count = decode_uint32(&buf[4]);
169 uint32_t token_line_count = decode_uint32(&buf[8]);
170 uint32_t token_count = decode_uint32(&buf[12]);
171
172 const uint8_t *b = &buf[16];
173 total_len -= 16;
174
175 identifiers.resize(identifier_count);
176 for (uint32_t i = 0; i < identifier_count; i++) {
177 uint32_t len = decode_uint32(b);
178 total_len -= 4;
179 ERR_FAIL_COND_V((len * 4u) > (uint32_t)total_len, ERR_INVALID_DATA);
180 b += 4;
181 Vector<uint32_t> cs;
182 cs.resize(len);
183 for (uint32_t j = 0; j < len; j++) {
184 uint8_t tmp[4];
185 for (uint32_t k = 0; k < 4; k++) {
186 tmp[k] = b[j * 4 + k] ^ 0xb6;
187 }
188 cs.write[j] = decode_uint32(tmp);
189 }
190
191 String s = String::utf32(Span(reinterpret_cast<const char32_t *>(cs.ptr()), len));
192 b += len * 4;
193 total_len -= len * 4;
194 identifiers.write[i] = s;
195 }
196
197 constants.resize(constant_count);
198 for (uint32_t i = 0; i < constant_count; i++) {
199 Variant v;
200 int len;
201 Error err = decode_variant(v, b, total_len, &len, false);
202 if (err) {
203 return err;
204 }

Callers 2

parse_binaryMethod · 0.80
test_tokenizer_bufferFunction · 0.80

Calls 8

decode_uint32Function · 0.85
decode_variantFunction · 0.85
sizeMethod · 0.65
sliceMethod · 0.65
SpanClass · 0.50
ptrMethod · 0.45
resizeMethod · 0.45
ptrwMethod · 0.45

Tested by 1

test_tokenizer_bufferFunction · 0.64