MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / encode_variant_2

Method encode_variant_2

compat/variant_decoder_compat.cpp:2524–3065  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2522}
2523
2524Error VariantDecoderCompat::encode_variant_2(const Variant &p_variant, uint8_t *r_buffer, int &r_len) {
2525 uint8_t *buf = r_buffer;
2526 r_len = 0;
2527 if (p_variant.get_type() == Variant::OBJECT) {
2528 Ref<InputEvent> ie = p_variant;
2529 Ref<Image> image = p_variant;
2530
2531 // V2 InputEvent variants
2532 if (ie.is_valid()) {
2533 if (buf) {
2534 encode_uint32(V2Type::INPUT_EVENT, buf);
2535 buf += 4;
2536 }
2537 r_len += 4;
2538 int llen = InputEventParserV2::encode_input_event(ie, buf);
2539
2540 if (buf) {
2541 buf += llen;
2542 }
2543 r_len += llen;
2544 return OK;
2545 } else if (image.is_valid()) { // V2 Image variants
2546 if (buf) {
2547 encode_uint32(V2Type::IMAGE, buf);
2548 buf += 4;
2549 }
2550 r_len += 4;
2551
2552 Vector<uint8_t> data = image->get_data();
2553
2554 if (buf) {
2555 encode_uint32(ImageEnumCompat::convert_image_format_enum_v4_to_v2(image->get_format()), &buf[0]);
2556 encode_uint32(image->get_mipmap_count(), &buf[4]);
2557 encode_uint32(image->get_width(), &buf[8]);
2558 encode_uint32(image->get_height(), &buf[12]);
2559 int ds = data.size();
2560 encode_uint32(ds, &buf[16]);
2561 if (ds > 0) {
2562 memcpy(&buf[20], data.ptr(), ds);
2563 }
2564 }
2565
2566 int pad = 0;
2567 if (data.size() % 4) {
2568 pad = 4 - data.size() % 4;
2569 }
2570
2571 r_len += data.size() + 5 * 4 + pad;
2572 return OK;
2573 }
2574 // else fall through
2575 }
2576
2577 if (buf) {
2578 encode_uint32(convert_variant_type_to_old(p_variant.get_type(), 2), buf);
2579 buf += 4;
2580 }
2581 r_len += 4;

Callers

nothing calls this directly

Calls 8

_encode_stringFunction · 0.85
lengthMethod · 0.80
get_typeMethod · 0.45
is_validMethod · 0.45
get_dataMethod · 0.45
sizeMethod · 0.45
get_nameMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected