2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* marshalls.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2019-01-01 12:53:14 +01:00
|
|
|
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "marshalls.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
|
|
|
|
#include "core/os/keyboard.h"
|
|
|
|
#include "core/print_string.h"
|
|
|
|
#include "core/reference.h"
|
|
|
|
|
2018-07-08 15:11:41 +02:00
|
|
|
#include <limits.h>
|
2014-02-10 02:10:30 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
void EncodedObjectAsID::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("set_object_id", "id"), &EncodedObjectAsID::set_object_id);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_object_id"), &EncodedObjectAsID::get_object_id);
|
2019-06-26 10:50:45 +02:00
|
|
|
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "object_id"), "set_object_id", "get_object_id");
|
2017-08-18 15:59:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EncodedObjectAsID::set_object_id(ObjectID p_id) {
|
|
|
|
id = p_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectID EncodedObjectAsID::get_object_id() const {
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2018-12-08 21:07:33 +01:00
|
|
|
EncodedObjectAsID::EncodedObjectAsID() :
|
|
|
|
id(0) {
|
2017-08-18 15:59:31 +02:00
|
|
|
}
|
|
|
|
|
2019-06-26 10:50:45 +02:00
|
|
|
#define _S(a) ((int32_t)a)
|
|
|
|
#define ERR_FAIL_ADD_OF(a, b, err) ERR_FAIL_COND_V(_S(b) < 0 || _S(a) < 0 || _S(a) > INT_MAX - _S(b), err)
|
|
|
|
#define ERR_FAIL_MUL_OF(a, b, err) ERR_FAIL_COND_V(_S(a) < 0 || _S(b) <= 0 || _S(a) > INT_MAX / _S(b), err)
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
#define ENCODE_MASK 0xFF
|
|
|
|
#define ENCODE_FLAG_64 1 << 16
|
2017-08-18 15:59:31 +02:00
|
|
|
#define ENCODE_FLAG_OBJECT_AS_ID 1 << 16
|
2017-01-09 00:58:39 +01:00
|
|
|
|
2017-08-14 16:58:10 +02:00
|
|
|
static Error _decode_string(const uint8_t *&buf, int &len, int *r_len, String &r_string) {
|
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
|
|
|
|
2018-07-08 15:11:41 +02:00
|
|
|
int32_t strlen = decode_uint32(buf);
|
|
|
|
int32_t pad = 0;
|
|
|
|
|
|
|
|
// Handle padding
|
|
|
|
if (strlen % 4) {
|
|
|
|
pad = 4 - strlen % 4;
|
|
|
|
}
|
|
|
|
|
2017-08-14 16:58:10 +02:00
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
2018-07-08 15:11:41 +02:00
|
|
|
|
|
|
|
// Ensure buffer is big enough
|
|
|
|
ERR_FAIL_ADD_OF(strlen, pad, ERR_FILE_EOF);
|
|
|
|
ERR_FAIL_COND_V(strlen < 0 || strlen + pad > len, ERR_FILE_EOF);
|
2017-08-14 16:58:10 +02:00
|
|
|
|
|
|
|
String str;
|
2018-07-08 15:11:41 +02:00
|
|
|
ERR_FAIL_COND_V(str.parse_utf8((const char *)buf, strlen), ERR_INVALID_DATA);
|
2017-08-14 16:58:10 +02:00
|
|
|
r_string = str;
|
|
|
|
|
2018-07-08 15:11:41 +02:00
|
|
|
// Add padding
|
|
|
|
strlen += pad;
|
2017-08-14 16:58:10 +02:00
|
|
|
|
2018-07-08 15:11:41 +02:00
|
|
|
// Update buffer pos, left data count, and return size
|
2017-08-14 16:58:10 +02:00
|
|
|
buf += strlen;
|
|
|
|
len -= strlen;
|
|
|
|
if (r_len) {
|
|
|
|
(*r_len) += 4 + strlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len, bool p_allow_objects) {
|
2017-01-09 00:58:39 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const uint8_t *buf = p_buffer;
|
|
|
|
int len = p_len;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-06-20 16:59:48 +02:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uint32_t type = decode_uint32(buf);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V((type & ENCODE_MASK) >= Variant::VARIANT_MAX, ERR_INVALID_DATA);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
if (r_len)
|
2017-03-05 16:44:50 +01:00
|
|
|
*r_len = 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (type & ENCODE_MASK) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
case Variant::NIL: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_variant = Variant();
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
|
|
|
case Variant::BOOL: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2014-02-10 02:10:30 +01:00
|
|
|
bool val = decode_uint32(buf);
|
2017-03-05 16:44:50 +01:00
|
|
|
r_variant = val;
|
2014-02-10 02:10:30 +01:00
|
|
|
if (r_len)
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
|
|
|
case Variant::INT: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (type & ENCODE_FLAG_64) {
|
2018-07-08 15:11:41 +02:00
|
|
|
ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA);
|
2017-01-09 00:58:39 +01:00
|
|
|
int64_t val = decode_uint64(buf);
|
2017-03-05 16:44:50 +01:00
|
|
|
r_variant = val;
|
2017-01-09 00:58:39 +01:00
|
|
|
if (r_len)
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += 8;
|
2017-01-09 00:58:39 +01:00
|
|
|
|
|
|
|
} else {
|
2018-07-08 15:11:41 +02:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2017-01-09 00:58:39 +01:00
|
|
|
int32_t val = decode_uint32(buf);
|
2017-03-05 16:44:50 +01:00
|
|
|
r_variant = val;
|
2017-01-09 00:58:39 +01:00
|
|
|
if (r_len)
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += 4;
|
2017-01-09 00:58:39 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::REAL: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (type & ENCODE_FLAG_64) {
|
2018-07-08 15:11:41 +02:00
|
|
|
ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA);
|
2017-01-09 00:58:39 +01:00
|
|
|
double val = decode_double(buf);
|
2017-03-05 16:44:50 +01:00
|
|
|
r_variant = val;
|
2017-01-09 00:58:39 +01:00
|
|
|
if (r_len)
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += 8;
|
2017-01-09 00:58:39 +01:00
|
|
|
} else {
|
2018-07-08 15:11:41 +02:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2017-01-09 00:58:39 +01:00
|
|
|
float val = decode_float(buf);
|
2017-03-05 16:44:50 +01:00
|
|
|
r_variant = val;
|
2017-01-09 00:58:39 +01:00
|
|
|
if (r_len)
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += 4;
|
2017-01-09 00:58:39 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::STRING: {
|
|
|
|
|
|
|
|
String str;
|
2017-08-14 16:58:10 +02:00
|
|
|
Error err = _decode_string(buf, len, r_len, str);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2017-03-05 16:44:50 +01:00
|
|
|
r_variant = str;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
|
2017-12-06 21:36:34 +01:00
|
|
|
// math types
|
2014-02-10 02:10:30 +01:00
|
|
|
case Variant::VECTOR2: {
|
|
|
|
|
2018-07-08 15:11:41 +02:00
|
|
|
ERR_FAIL_COND_V(len < 4 * 2, ERR_INVALID_DATA);
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector2 val;
|
2017-03-05 16:44:50 +01:00
|
|
|
val.x = decode_float(&buf[0]);
|
|
|
|
val.y = decode_float(&buf[4]);
|
|
|
|
r_variant = val;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += 4 * 2;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} break; // 5
|
2014-02-10 02:10:30 +01:00
|
|
|
case Variant::RECT2: {
|
|
|
|
|
2018-07-08 15:11:41 +02:00
|
|
|
ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
|
2014-02-10 02:10:30 +01:00
|
|
|
Rect2 val;
|
2017-06-04 00:25:13 +02:00
|
|
|
val.position.x = decode_float(&buf[0]);
|
|
|
|
val.position.y = decode_float(&buf[4]);
|
2017-03-05 16:44:50 +01:00
|
|
|
val.size.x = decode_float(&buf[8]);
|
|
|
|
val.size.y = decode_float(&buf[12]);
|
|
|
|
r_variant = val;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += 4 * 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::VECTOR3: {
|
|
|
|
|
2018-07-08 15:11:41 +02:00
|
|
|
ERR_FAIL_COND_V(len < 4 * 3, ERR_INVALID_DATA);
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector3 val;
|
2017-03-05 16:44:50 +01:00
|
|
|
val.x = decode_float(&buf[0]);
|
|
|
|
val.y = decode_float(&buf[4]);
|
|
|
|
val.z = decode_float(&buf[8]);
|
|
|
|
r_variant = val;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += 4 * 3;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2013-04-10 10:37:04 +02:00
|
|
|
} break;
|
2017-01-11 04:52:51 +01:00
|
|
|
case Variant::TRANSFORM2D: {
|
2013-04-10 10:37:04 +02:00
|
|
|
|
2018-07-08 15:11:41 +02:00
|
|
|
ERR_FAIL_COND_V(len < 4 * 6, ERR_INVALID_DATA);
|
2017-01-11 04:52:51 +01:00
|
|
|
Transform2D val;
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
for (int j = 0; j < 2; j++) {
|
2013-04-10 10:37:04 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
val.elements[i][j] = decode_float(&buf[(i * 2 + j) * 4]);
|
2013-04-10 10:37:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_variant = val;
|
2013-04-10 10:37:04 +02:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += 4 * 6;
|
2013-04-10 10:37:04 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
|
|
|
case Variant::PLANE: {
|
|
|
|
|
2018-07-08 15:11:41 +02:00
|
|
|
ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
|
2014-02-10 02:10:30 +01:00
|
|
|
Plane val;
|
2017-03-05 16:44:50 +01:00
|
|
|
val.normal.x = decode_float(&buf[0]);
|
|
|
|
val.normal.y = decode_float(&buf[4]);
|
|
|
|
val.normal.z = decode_float(&buf[8]);
|
|
|
|
val.d = decode_float(&buf[12]);
|
|
|
|
r_variant = val;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += 4 * 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::QUAT: {
|
|
|
|
|
2018-07-08 15:11:41 +02:00
|
|
|
ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
|
2014-02-10 02:10:30 +01:00
|
|
|
Quat val;
|
2017-03-05 16:44:50 +01:00
|
|
|
val.x = decode_float(&buf[0]);
|
|
|
|
val.y = decode_float(&buf[4]);
|
|
|
|
val.z = decode_float(&buf[8]);
|
|
|
|
val.w = decode_float(&buf[12]);
|
|
|
|
r_variant = val;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += 4 * 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
2017-11-17 03:09:00 +01:00
|
|
|
case Variant::AABB: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-07-08 15:11:41 +02:00
|
|
|
ERR_FAIL_COND_V(len < 4 * 6, ERR_INVALID_DATA);
|
2017-11-17 03:09:00 +01:00
|
|
|
AABB val;
|
2017-06-06 20:33:51 +02:00
|
|
|
val.position.x = decode_float(&buf[0]);
|
|
|
|
val.position.y = decode_float(&buf[4]);
|
|
|
|
val.position.z = decode_float(&buf[8]);
|
2017-03-05 16:44:50 +01:00
|
|
|
val.size.x = decode_float(&buf[12]);
|
|
|
|
val.size.y = decode_float(&buf[16]);
|
|
|
|
val.size.z = decode_float(&buf[20]);
|
|
|
|
r_variant = val;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += 4 * 6;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
2017-01-11 04:52:51 +01:00
|
|
|
case Variant::BASIS: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-07-08 15:11:41 +02:00
|
|
|
ERR_FAIL_COND_V(len < 4 * 9, ERR_INVALID_DATA);
|
2017-01-11 04:52:51 +01:00
|
|
|
Basis val;
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
for (int j = 0; j < 3; j++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
val.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_variant = val;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += 4 * 9;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::TRANSFORM: {
|
|
|
|
|
2018-07-08 15:11:41 +02:00
|
|
|
ERR_FAIL_COND_V(len < 4 * 12, ERR_INVALID_DATA);
|
2014-02-10 02:10:30 +01:00
|
|
|
Transform val;
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
for (int j = 0; j < 3; j++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
val.basis.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
val.origin[0] = decode_float(&buf[36]);
|
|
|
|
val.origin[1] = decode_float(&buf[40]);
|
|
|
|
val.origin[2] = decode_float(&buf[44]);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_variant = val;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += 4 * 12;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
// misc types
|
|
|
|
case Variant::COLOR: {
|
|
|
|
|
2018-07-08 15:11:41 +02:00
|
|
|
ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
|
2014-02-10 02:10:30 +01:00
|
|
|
Color val;
|
2017-03-05 16:44:50 +01:00
|
|
|
val.r = decode_float(&buf[0]);
|
|
|
|
val.g = decode_float(&buf[4]);
|
|
|
|
val.b = decode_float(&buf[8]);
|
|
|
|
val.a = decode_float(&buf[12]);
|
|
|
|
r_variant = val;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += 4 * 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::NODE_PATH: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2018-07-08 15:11:41 +02:00
|
|
|
int32_t strlen = decode_uint32(buf);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (strlen & 0x80000000) {
|
2014-03-14 02:57:24 +01:00
|
|
|
//new format
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(len < 12, ERR_INVALID_DATA);
|
2014-03-14 02:57:24 +01:00
|
|
|
Vector<StringName> names;
|
|
|
|
Vector<StringName> subnames;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uint32_t namecount = strlen &= 0x7FFFFFFF;
|
|
|
|
uint32_t subnamecount = decode_uint32(buf + 4);
|
|
|
|
uint32_t flags = decode_uint32(buf + 8);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
len -= 12;
|
|
|
|
buf += 12;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-01-18 21:37:17 +01:00
|
|
|
if (flags & 2) // Obsolete format with property separate from subpath
|
2017-05-30 22:20:15 +02:00
|
|
|
subnamecount++;
|
|
|
|
|
2017-08-31 23:30:35 +02:00
|
|
|
uint32_t total = namecount + subnamecount;
|
2014-03-14 02:57:24 +01:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += 12;
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2017-08-31 23:30:35 +02:00
|
|
|
for (uint32_t i = 0; i < total; i++) {
|
2014-03-14 02:57:24 +01:00
|
|
|
|
|
|
|
String str;
|
2018-07-08 15:11:41 +02:00
|
|
|
Error err = _decode_string(buf, len, r_len, str);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i < namecount)
|
2014-03-14 02:57:24 +01:00
|
|
|
names.push_back(str);
|
|
|
|
else
|
2017-05-30 22:20:15 +02:00
|
|
|
subnames.push_back(str);
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2017-05-30 22:20:15 +02:00
|
|
|
r_variant = NodePath(names, subnames, flags & 1);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
|
|
|
} else {
|
|
|
|
//old format, just a string
|
|
|
|
|
2018-07-08 15:11:41 +02:00
|
|
|
ERR_FAIL_V(ERR_INVALID_DATA);
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
/*case Variant::RESOURCE: {
|
|
|
|
|
|
|
|
ERR_EXPLAIN("Can't marshallize resources");
|
|
|
|
ERR_FAIL_V(ERR_INVALID_DATA); //no, i'm sorry, no go
|
|
|
|
} break;*/
|
|
|
|
case Variant::_RID: {
|
|
|
|
|
|
|
|
r_variant = RID();
|
|
|
|
} break;
|
|
|
|
case Variant::OBJECT: {
|
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
if (type & ENCODE_FLAG_OBJECT_AS_ID) {
|
|
|
|
//this _is_ allowed
|
2018-07-08 15:11:41 +02:00
|
|
|
ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA);
|
2017-08-18 15:59:31 +02:00
|
|
|
ObjectID val = decode_uint64(buf);
|
|
|
|
if (r_len)
|
|
|
|
(*r_len) += 8;
|
2017-08-14 16:58:10 +02:00
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
if (val == 0) {
|
|
|
|
r_variant = (Object *)NULL;
|
|
|
|
} else {
|
|
|
|
Ref<EncodedObjectAsID> obj_as_id;
|
|
|
|
obj_as_id.instance();
|
|
|
|
obj_as_id->set_object_id(val);
|
2017-08-14 16:58:10 +02:00
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
r_variant = obj_as_id;
|
|
|
|
}
|
2017-08-14 16:58:10 +02:00
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
} else {
|
|
|
|
ERR_FAIL_COND_V(!p_allow_objects, ERR_UNAUTHORIZED);
|
2017-08-14 16:58:10 +02:00
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
String str;
|
|
|
|
Error err = _decode_string(buf, len, r_len, str);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2017-08-14 16:58:10 +02:00
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
if (str == String()) {
|
|
|
|
r_variant = (Object *)NULL;
|
|
|
|
} else {
|
2017-08-14 16:58:10 +02:00
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
Object *obj = ClassDB::instance(str);
|
2017-08-14 16:58:10 +02:00
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
ERR_FAIL_COND_V(!obj, ERR_UNAVAILABLE);
|
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2017-08-14 16:58:10 +02:00
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
int32_t count = decode_uint32(buf);
|
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
2017-08-14 16:58:10 +02:00
|
|
|
if (r_len) {
|
2017-08-18 15:59:31 +02:00
|
|
|
(*r_len) += 4;
|
2017-08-14 16:58:10 +02:00
|
|
|
}
|
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
for (int i = 0; i < count; i++) {
|
2017-08-14 16:58:10 +02:00
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
str = String();
|
|
|
|
err = _decode_string(buf, len, r_len, str);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
Variant value;
|
|
|
|
int used;
|
|
|
|
err = decode_variant(value, buf, len, &used, p_allow_objects);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
buf += used;
|
|
|
|
len -= used;
|
|
|
|
if (r_len) {
|
|
|
|
(*r_len) += used;
|
|
|
|
}
|
|
|
|
|
|
|
|
obj->set(str, value);
|
|
|
|
}
|
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
if (Object::cast_to<Reference>(obj)) {
|
|
|
|
REF ref = REF(Object::cast_to<Reference>(obj));
|
2017-08-18 15:59:31 +02:00
|
|
|
r_variant = ref;
|
|
|
|
} else {
|
|
|
|
r_variant = obj;
|
|
|
|
}
|
2017-08-14 16:58:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
|
|
|
case Variant::DICTIONARY: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2018-07-08 15:11:41 +02:00
|
|
|
int32_t count = decode_uint32(buf);
|
2017-03-05 16:44:50 +01:00
|
|
|
// bool shared = count&0x80000000;
|
|
|
|
count &= 0x7FFFFFFF;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (r_len) {
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Dictionary d;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-07-08 15:11:41 +02:00
|
|
|
for (int i = 0; i < count; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant key, value;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
int used;
|
2017-08-14 16:58:10 +02:00
|
|
|
Error err = decode_variant(key, buf, len, &used, p_allow_objects);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(err, err);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
buf += used;
|
|
|
|
len -= used;
|
2014-02-10 02:10:30 +01:00
|
|
|
if (r_len) {
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += used;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-08-14 16:58:10 +02:00
|
|
|
err = decode_variant(value, buf, len, &used, p_allow_objects);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(err, err);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
buf += used;
|
|
|
|
len -= used;
|
2014-02-10 02:10:30 +01:00
|
|
|
if (r_len) {
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += used;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
d[key] = value;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_variant = d;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::ARRAY: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2018-07-08 15:11:41 +02:00
|
|
|
int32_t count = decode_uint32(buf);
|
2017-03-05 16:44:50 +01:00
|
|
|
// bool shared = count&0x80000000;
|
|
|
|
count &= 0x7FFFFFFF;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (r_len) {
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Array varr;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-07-08 15:11:41 +02:00
|
|
|
for (int i = 0; i < count; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int used = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
Variant v;
|
2017-08-14 16:58:10 +02:00
|
|
|
Error err = decode_variant(v, buf, len, &used, p_allow_objects);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(err, err);
|
|
|
|
buf += used;
|
|
|
|
len -= used;
|
2014-02-10 02:10:30 +01:00
|
|
|
varr.push_back(v);
|
|
|
|
if (r_len) {
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += used;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_variant = varr;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
// arrays
|
2017-01-11 04:52:51 +01:00
|
|
|
case Variant::POOL_BYTE_ARRAY: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2018-07-08 15:11:41 +02:00
|
|
|
int32_t count = decode_uint32(buf);
|
2017-03-05 16:44:50 +01:00
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
2018-07-08 15:11:41 +02:00
|
|
|
ERR_FAIL_COND_V(count < 0 || count > len, ERR_INVALID_DATA);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t> data;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (count) {
|
|
|
|
data.resize(count);
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t>::Write w = data.write();
|
2018-07-08 15:11:41 +02:00
|
|
|
for (int32_t i = 0; i < count; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
w[i] = buf[i];
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
w = PoolVector<uint8_t>::Write();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_variant = data;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (r_len) {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (count % 4)
|
|
|
|
(*r_len) += 4 - count % 4;
|
|
|
|
(*r_len) += 4 + count;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2017-01-11 04:52:51 +01:00
|
|
|
case Variant::POOL_INT_ARRAY: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2018-07-08 15:11:41 +02:00
|
|
|
int32_t count = decode_uint32(buf);
|
2017-03-05 16:44:50 +01:00
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
2018-07-08 15:11:41 +02:00
|
|
|
ERR_FAIL_MUL_OF(count, 4, ERR_INVALID_DATA);
|
|
|
|
ERR_FAIL_COND_V(count < 0 || count * 4 > len, ERR_INVALID_DATA);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<int> data;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (count) {
|
|
|
|
//const int*rbuf=(const int*)buf;
|
|
|
|
data.resize(count);
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<int>::Write w = data.write();
|
2018-07-08 15:11:41 +02:00
|
|
|
for (int32_t i = 0; i < count; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
w[i] = decode_uint32(&buf[i * 4]);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
w = PoolVector<int>::Write();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
r_variant = Variant(data);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (r_len) {
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += 4 + count * sizeof(int);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2017-01-11 04:52:51 +01:00
|
|
|
case Variant::POOL_REAL_ARRAY: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2018-07-08 15:11:41 +02:00
|
|
|
int32_t count = decode_uint32(buf);
|
2017-03-05 16:44:50 +01:00
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
2018-07-08 15:11:41 +02:00
|
|
|
ERR_FAIL_MUL_OF(count, 4, ERR_INVALID_DATA);
|
|
|
|
ERR_FAIL_COND_V(count < 0 || count * 4 > len, ERR_INVALID_DATA);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<float> data;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (count) {
|
|
|
|
//const float*rbuf=(const float*)buf;
|
|
|
|
data.resize(count);
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<float>::Write w = data.write();
|
2018-07-08 15:11:41 +02:00
|
|
|
for (int32_t i = 0; i < count; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
w[i] = decode_float(&buf[i * 4]);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
w = PoolVector<float>::Write();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
r_variant = data;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (r_len) {
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += 4 + count * sizeof(float);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2017-01-11 04:52:51 +01:00
|
|
|
case Variant::POOL_STRING_ARRAY: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2018-07-08 15:11:41 +02:00
|
|
|
int32_t count = decode_uint32(buf);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<String> strings;
|
2017-03-05 16:44:50 +01:00
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
//printf("string count: %i\n",count);
|
|
|
|
|
2018-07-08 15:11:41 +02:00
|
|
|
for (int32_t i = 0; i < count; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
String str;
|
2018-07-08 15:11:41 +02:00
|
|
|
Error err = _decode_string(buf, len, r_len, str);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
strings.push_back(str);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_variant = strings;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2013-04-10 10:37:04 +02:00
|
|
|
} break;
|
2017-01-11 04:52:51 +01:00
|
|
|
case Variant::POOL_VECTOR2_ARRAY: {
|
2013-04-10 10:37:04 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2018-07-08 15:11:41 +02:00
|
|
|
int32_t count = decode_uint32(buf);
|
2017-03-05 16:44:50 +01:00
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
2013-04-10 10:37:04 +02:00
|
|
|
|
2018-07-08 15:11:41 +02:00
|
|
|
ERR_FAIL_MUL_OF(count, 4 * 2, ERR_INVALID_DATA);
|
|
|
|
ERR_FAIL_COND_V(count < 0 || count * 4 * 2 > len, ERR_INVALID_DATA);
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector2> varray;
|
2013-04-10 10:37:04 +02:00
|
|
|
|
|
|
|
if (r_len) {
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += 4;
|
2013-04-10 10:37:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count) {
|
|
|
|
varray.resize(count);
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector2>::Write w = varray.write();
|
2013-04-10 10:37:04 +02:00
|
|
|
|
2018-07-08 15:11:41 +02:00
|
|
|
for (int32_t i = 0; i < count; i++) {
|
2013-04-10 10:37:04 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
w[i].x = decode_float(buf + i * 4 * 2 + 4 * 0);
|
|
|
|
w[i].y = decode_float(buf + i * 4 * 2 + 4 * 1);
|
2013-04-10 10:37:04 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int adv = 4 * 2 * count;
|
2013-04-10 10:37:04 +02:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += adv;
|
2013-04-10 10:37:04 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_variant = varray;
|
2013-04-10 10:37:04 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
2017-01-11 04:52:51 +01:00
|
|
|
case Variant::POOL_VECTOR3_ARRAY: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2018-07-08 15:11:41 +02:00
|
|
|
int32_t count = decode_uint32(buf);
|
2017-03-05 16:44:50 +01:00
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-07-08 15:11:41 +02:00
|
|
|
ERR_FAIL_MUL_OF(count, 4 * 3, ERR_INVALID_DATA);
|
|
|
|
ERR_FAIL_COND_V(count < 0 || count * 4 * 3 > len, ERR_INVALID_DATA);
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3> varray;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (r_len) {
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count) {
|
|
|
|
varray.resize(count);
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3>::Write w = varray.write();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-07-08 15:11:41 +02:00
|
|
|
for (int32_t i = 0; i < count; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
w[i].x = decode_float(buf + i * 4 * 3 + 4 * 0);
|
|
|
|
w[i].y = decode_float(buf + i * 4 * 3 + 4 * 1);
|
|
|
|
w[i].z = decode_float(buf + i * 4 * 3 + 4 * 2);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int adv = 4 * 3 * count;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += adv;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_variant = varray;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
2017-01-11 04:52:51 +01:00
|
|
|
case Variant::POOL_COLOR_ARRAY: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2018-07-08 15:11:41 +02:00
|
|
|
int32_t count = decode_uint32(buf);
|
2017-03-05 16:44:50 +01:00
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-07-08 15:11:41 +02:00
|
|
|
ERR_FAIL_MUL_OF(count, 4 * 4, ERR_INVALID_DATA);
|
|
|
|
ERR_FAIL_COND_V(count < 0 || count * 4 * 4 > len, ERR_INVALID_DATA);
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Color> carray;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (r_len) {
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count) {
|
|
|
|
carray.resize(count);
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Color>::Write w = carray.write();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-07-08 15:11:41 +02:00
|
|
|
for (int32_t i = 0; i < count; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
w[i].r = decode_float(buf + i * 4 * 4 + 4 * 0);
|
|
|
|
w[i].g = decode_float(buf + i * 4 * 4 + 4 * 1);
|
|
|
|
w[i].b = decode_float(buf + i * 4 * 4 + 4 * 2);
|
|
|
|
w[i].a = decode_float(buf + i * 4 * 4 + 4 * 3);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int adv = 4 * 4 * count;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-05 16:44:50 +01:00
|
|
|
(*r_len) += adv;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_variant = carray;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
2019-04-09 17:08:36 +02:00
|
|
|
default: {
|
|
|
|
ERR_FAIL_V(ERR_BUG);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-08-14 16:58:10 +02:00
|
|
|
static void _encode_string(const String &p_string, uint8_t *&buf, int &r_len) {
|
|
|
|
|
|
|
|
CharString utf8 = p_string.utf8();
|
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
encode_uint32(utf8.length(), buf);
|
|
|
|
buf += 4;
|
|
|
|
copymem(buf, utf8.get_data(), utf8.length());
|
2017-08-21 16:20:13 +02:00
|
|
|
buf += utf8.length();
|
2017-08-14 16:58:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
r_len += 4 + utf8.length();
|
2017-08-21 16:20:13 +02:00
|
|
|
while (r_len % 4) {
|
2017-08-14 16:58:10 +02:00
|
|
|
r_len++; //pad
|
2017-08-21 16:20:13 +02:00
|
|
|
if (buf) {
|
2018-03-04 18:45:33 +01:00
|
|
|
*(buf++) = 0;
|
2017-08-21 16:20:13 +02:00
|
|
|
}
|
|
|
|
}
|
2017-08-14 16:58:10 +02:00
|
|
|
}
|
|
|
|
|
2019-03-28 09:40:31 +01:00
|
|
|
Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bool p_full_objects) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uint8_t *buf = r_buffer;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uint32_t flags = 0;
|
2017-01-09 00:58:39 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (p_variant.get_type()) {
|
2017-01-09 00:58:39 +01:00
|
|
|
|
|
|
|
case Variant::INT: {
|
|
|
|
int64_t val = p_variant;
|
2018-09-18 18:31:37 +02:00
|
|
|
if (val > (int64_t)INT_MAX || val < (int64_t)INT_MIN) {
|
2017-03-05 16:44:50 +01:00
|
|
|
flags |= ENCODE_FLAG_64;
|
2017-01-09 00:58:39 +01:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case Variant::REAL: {
|
|
|
|
|
|
|
|
double d = p_variant;
|
|
|
|
float f = d;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (double(f) != d) {
|
|
|
|
flags |= ENCODE_FLAG_64; //always encode real as double
|
2017-01-09 00:58:39 +01:00
|
|
|
}
|
|
|
|
} break;
|
2017-08-18 15:59:31 +02:00
|
|
|
case Variant::OBJECT: {
|
2019-03-28 09:40:31 +01:00
|
|
|
if (!p_full_objects) {
|
2017-08-18 15:59:31 +02:00
|
|
|
flags |= ENCODE_FLAG_OBJECT_AS_ID;
|
|
|
|
}
|
|
|
|
} break;
|
2019-04-09 17:08:36 +02:00
|
|
|
default: {
|
|
|
|
} // nothing to do at this stage
|
2017-01-09 00:58:39 +01:00
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
if (buf) {
|
2017-03-05 16:44:50 +01:00
|
|
|
encode_uint32(p_variant.get_type() | flags, buf);
|
|
|
|
buf += 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (p_variant.get_type()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
case Variant::NIL: {
|
|
|
|
|
|
|
|
//nothing to do
|
|
|
|
} break;
|
|
|
|
case Variant::BOOL: {
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-05 16:44:50 +01:00
|
|
|
encode_uint32(p_variant.operator bool(), buf);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::INT: {
|
|
|
|
|
2018-09-18 18:31:37 +02:00
|
|
|
if (flags & ENCODE_FLAG_64) {
|
2017-01-09 00:58:39 +01:00
|
|
|
//64 bits
|
|
|
|
if (buf) {
|
2018-10-02 20:21:08 +02:00
|
|
|
encode_uint64(p_variant.operator int64_t(), buf);
|
2017-01-09 00:58:39 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 8;
|
2017-01-09 00:58:39 +01:00
|
|
|
} else {
|
|
|
|
if (buf) {
|
2018-10-02 20:21:08 +02:00
|
|
|
encode_uint32(p_variant.operator int32_t(), buf);
|
2017-01-09 00:58:39 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 4;
|
2017-01-09 00:58:39 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
|
|
|
case Variant::REAL: {
|
|
|
|
|
2018-09-18 18:31:37 +02:00
|
|
|
if (flags & ENCODE_FLAG_64) {
|
2017-01-09 00:58:39 +01:00
|
|
|
if (buf) {
|
2017-03-05 16:44:50 +01:00
|
|
|
encode_double(p_variant.operator double(), buf);
|
2017-01-09 00:58:39 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 8;
|
2017-01-09 00:58:39 +01:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (buf) {
|
2017-04-11 19:17:56 +02:00
|
|
|
encode_float(p_variant.operator float(), buf);
|
2017-01-09 00:58:39 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2014-03-14 02:57:24 +01:00
|
|
|
case Variant::NODE_PATH: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
NodePath np = p_variant;
|
2014-03-14 02:57:24 +01:00
|
|
|
if (buf) {
|
2017-03-05 16:44:50 +01:00
|
|
|
encode_uint32(uint32_t(np.get_name_count()) | 0x80000000, buf); //for compatibility with the old format
|
|
|
|
encode_uint32(np.get_subname_count(), buf + 4);
|
2019-02-12 21:10:08 +01:00
|
|
|
uint32_t np_flags = 0;
|
2014-03-14 02:57:24 +01:00
|
|
|
if (np.is_absolute())
|
2019-02-12 21:10:08 +01:00
|
|
|
np_flags |= 1;
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2019-02-12 21:10:08 +01:00
|
|
|
encode_uint32(np_flags, buf + 8);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
buf += 12;
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 12;
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int total = np.get_name_count() + np.get_subname_count();
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < total; i++) {
|
2014-03-14 02:57:24 +01:00
|
|
|
|
|
|
|
String str;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i < np.get_name_count())
|
|
|
|
str = np.get_name(i);
|
2014-03-14 02:57:24 +01:00
|
|
|
else
|
2017-05-30 22:20:15 +02:00
|
|
|
str = np.get_subname(i - np.get_name_count());
|
2014-03-14 02:57:24 +01:00
|
|
|
|
|
|
|
CharString utf8 = str.utf8();
|
|
|
|
|
|
|
|
int pad = 0;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (utf8.length() % 4)
|
|
|
|
pad = 4 - utf8.length() % 4;
|
2014-03-14 02:57:24 +01:00
|
|
|
|
|
|
|
if (buf) {
|
2017-03-05 16:44:50 +01:00
|
|
|
encode_uint32(utf8.length(), buf);
|
|
|
|
buf += 4;
|
|
|
|
copymem(buf, utf8.get_data(), utf8.length());
|
|
|
|
buf += pad + utf8.length();
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 4 + utf8.length() + pad;
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2014-02-10 02:10:30 +01:00
|
|
|
case Variant::STRING: {
|
|
|
|
|
2017-08-14 16:58:10 +02:00
|
|
|
_encode_string(p_variant, buf, r_len);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
|
2017-12-06 21:36:34 +01:00
|
|
|
// math types
|
2014-02-10 02:10:30 +01:00
|
|
|
case Variant::VECTOR2: {
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector2 v2 = p_variant;
|
|
|
|
encode_float(v2.x, &buf[0]);
|
|
|
|
encode_float(v2.y, &buf[4]);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 2 * 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} break; // 5
|
2014-02-10 02:10:30 +01:00
|
|
|
case Variant::RECT2: {
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-05 16:44:50 +01:00
|
|
|
Rect2 r2 = p_variant;
|
2017-06-04 00:25:13 +02:00
|
|
|
encode_float(r2.position.x, &buf[0]);
|
|
|
|
encode_float(r2.position.y, &buf[4]);
|
2017-03-05 16:44:50 +01:00
|
|
|
encode_float(r2.size.x, &buf[8]);
|
|
|
|
encode_float(r2.size.y, &buf[12]);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 4 * 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::VECTOR3: {
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 v3 = p_variant;
|
|
|
|
encode_float(v3.x, &buf[0]);
|
|
|
|
encode_float(v3.y, &buf[4]);
|
|
|
|
encode_float(v3.z, &buf[8]);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 3 * 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2013-04-10 10:37:04 +02:00
|
|
|
} break;
|
2017-01-11 04:52:51 +01:00
|
|
|
case Variant::TRANSFORM2D: {
|
2013-04-10 10:37:04 +02:00
|
|
|
|
|
|
|
if (buf) {
|
2017-03-05 16:44:50 +01:00
|
|
|
Transform2D val = p_variant;
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
for (int j = 0; j < 2; j++) {
|
2013-04-10 10:37:04 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
copymem(&buf[(i * 2 + j) * 4], &val.elements[i][j], sizeof(float));
|
2013-04-10 10:37:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 6 * 4;
|
2013-04-10 10:37:04 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
|
|
|
case Variant::PLANE: {
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-05 16:44:50 +01:00
|
|
|
Plane p = p_variant;
|
|
|
|
encode_float(p.normal.x, &buf[0]);
|
|
|
|
encode_float(p.normal.y, &buf[4]);
|
|
|
|
encode_float(p.normal.z, &buf[8]);
|
|
|
|
encode_float(p.d, &buf[12]);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 4 * 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::QUAT: {
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-05 16:44:50 +01:00
|
|
|
Quat q = p_variant;
|
|
|
|
encode_float(q.x, &buf[0]);
|
|
|
|
encode_float(q.y, &buf[4]);
|
|
|
|
encode_float(q.z, &buf[8]);
|
|
|
|
encode_float(q.w, &buf[12]);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 4 * 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
2017-11-17 03:09:00 +01:00
|
|
|
case Variant::AABB: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (buf) {
|
2017-11-17 03:09:00 +01:00
|
|
|
AABB aabb = p_variant;
|
2017-06-06 20:33:51 +02:00
|
|
|
encode_float(aabb.position.x, &buf[0]);
|
|
|
|
encode_float(aabb.position.y, &buf[4]);
|
|
|
|
encode_float(aabb.position.z, &buf[8]);
|
2017-03-05 16:44:50 +01:00
|
|
|
encode_float(aabb.size.x, &buf[12]);
|
|
|
|
encode_float(aabb.size.y, &buf[16]);
|
|
|
|
encode_float(aabb.size.z, &buf[20]);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 6 * 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
2017-01-11 04:52:51 +01:00
|
|
|
case Variant::BASIS: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (buf) {
|
2017-03-05 16:44:50 +01:00
|
|
|
Basis val = p_variant;
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
for (int j = 0; j < 3; j++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
copymem(&buf[(i * 3 + j) * 4], &val.elements[i][j], sizeof(float));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 9 * 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::TRANSFORM: {
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-05 16:44:50 +01:00
|
|
|
Transform val = p_variant;
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
for (int j = 0; j < 3; j++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
copymem(&buf[(i * 3 + j) * 4], &val.basis.elements[i][j], sizeof(float));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
encode_float(val.origin.x, &buf[36]);
|
|
|
|
encode_float(val.origin.y, &buf[40]);
|
|
|
|
encode_float(val.origin.z, &buf[44]);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 12 * 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
// misc types
|
|
|
|
case Variant::COLOR: {
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-05 16:44:50 +01:00
|
|
|
Color c = p_variant;
|
|
|
|
encode_float(c.r, &buf[0]);
|
|
|
|
encode_float(c.g, &buf[4]);
|
|
|
|
encode_float(c.b, &buf[8]);
|
|
|
|
encode_float(c.a, &buf[12]);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 4 * 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-03-09 00:00:52 +01:00
|
|
|
} break;
|
2014-02-10 02:10:30 +01:00
|
|
|
/*case Variant::RESOURCE: {
|
|
|
|
|
|
|
|
ERR_EXPLAIN("Can't marshallize resources");
|
|
|
|
ERR_FAIL_V(ERR_INVALID_DATA); //no, i'm sorry, no go
|
|
|
|
} break;*/
|
2017-08-14 16:58:10 +02:00
|
|
|
case Variant::_RID: {
|
|
|
|
|
|
|
|
} break;
|
2014-02-10 02:10:30 +01:00
|
|
|
case Variant::OBJECT: {
|
|
|
|
|
2019-03-28 09:40:31 +01:00
|
|
|
if (p_full_objects) {
|
2017-08-18 15:59:31 +02:00
|
|
|
|
|
|
|
Object *obj = p_variant;
|
|
|
|
if (!obj) {
|
|
|
|
if (buf) {
|
|
|
|
encode_uint32(0, buf);
|
|
|
|
}
|
2017-10-08 20:13:46 +02:00
|
|
|
r_len += 4;
|
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
} else {
|
|
|
|
_encode_string(obj->get_class(), buf, r_len);
|
2017-08-14 16:58:10 +02:00
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
List<PropertyInfo> props;
|
|
|
|
obj->get_property_list(&props);
|
2017-08-14 16:58:10 +02:00
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
int pc = 0;
|
|
|
|
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
|
2017-08-14 16:58:10 +02:00
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
|
|
|
|
continue;
|
|
|
|
pc++;
|
|
|
|
}
|
2017-08-14 16:58:10 +02:00
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
if (buf) {
|
|
|
|
encode_uint32(pc, buf);
|
|
|
|
buf += 4;
|
|
|
|
}
|
2017-08-14 16:58:10 +02:00
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
r_len += 4;
|
2017-08-14 16:58:10 +02:00
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
|
2017-08-14 16:58:10 +02:00
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
|
|
|
|
continue;
|
2017-08-14 16:58:10 +02:00
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
_encode_string(E->get().name, buf, r_len);
|
2017-08-14 16:58:10 +02:00
|
|
|
|
2017-08-18 15:59:31 +02:00
|
|
|
int len;
|
2019-03-28 09:40:31 +01:00
|
|
|
Error err = encode_variant(obj->get(E->get().name), buf, len, p_full_objects);
|
2017-08-18 15:59:31 +02:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
ERR_FAIL_COND_V(len % 4, ERR_BUG);
|
|
|
|
r_len += len;
|
|
|
|
if (buf)
|
|
|
|
buf += len;
|
|
|
|
}
|
2017-08-14 16:58:10 +02:00
|
|
|
}
|
2019-03-28 09:40:31 +01:00
|
|
|
} else {
|
|
|
|
if (buf) {
|
|
|
|
|
|
|
|
Object *obj = p_variant;
|
|
|
|
ObjectID id = 0;
|
|
|
|
if (obj && ObjectDB::instance_validate(obj)) {
|
|
|
|
id = obj->get_instance_id();
|
|
|
|
}
|
|
|
|
|
|
|
|
encode_uint64(id, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
r_len += 8;
|
2017-08-14 16:58:10 +02:00
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
|
|
|
case Variant::DICTIONARY: {
|
|
|
|
|
|
|
|
Dictionary d = p_variant;
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-05 16:44:50 +01:00
|
|
|
encode_uint32(uint32_t(d.size()), buf);
|
|
|
|
buf += 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
List<Variant> keys;
|
|
|
|
d.get_key_list(&keys);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
CharString utf8 = E->->utf8();
|
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
encode_uint32(utf8.length()+1,buf);
|
|
|
|
buf+=4;
|
|
|
|
copymem(buf,utf8.get_data(),utf8.length()+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
r_len+=4+utf8.length()+1;
|
|
|
|
while (r_len%4)
|
|
|
|
r_len++; //pad
|
|
|
|
*/
|
|
|
|
int len;
|
2019-03-28 09:40:31 +01:00
|
|
|
encode_variant(E->get(), buf, len, p_full_objects);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(len % 4, ERR_BUG);
|
|
|
|
r_len += len;
|
2014-02-10 02:10:30 +01:00
|
|
|
if (buf)
|
|
|
|
buf += len;
|
2018-01-24 19:24:18 +01:00
|
|
|
Variant *v = d.getptr(E->get());
|
|
|
|
ERR_FAIL_COND_V(!v, ERR_BUG);
|
2019-03-28 09:40:31 +01:00
|
|
|
encode_variant(*v, buf, len, p_full_objects);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(len % 4, ERR_BUG);
|
|
|
|
r_len += len;
|
2014-02-10 02:10:30 +01:00
|
|
|
if (buf)
|
|
|
|
buf += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::ARRAY: {
|
|
|
|
|
|
|
|
Array v = p_variant;
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-05 16:44:50 +01:00
|
|
|
encode_uint32(uint32_t(v.size()), buf);
|
|
|
|
buf += 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < v.size(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
int len;
|
2019-03-28 09:40:31 +01:00
|
|
|
encode_variant(v.get(i), buf, len, p_full_objects);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(len % 4, ERR_BUG);
|
|
|
|
r_len += len;
|
2014-02-10 02:10:30 +01:00
|
|
|
if (buf)
|
2017-03-05 16:44:50 +01:00
|
|
|
buf += len;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
// arrays
|
2017-01-11 04:52:51 +01:00
|
|
|
case Variant::POOL_BYTE_ARRAY: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t> data = p_variant;
|
2017-03-05 16:44:50 +01:00
|
|
|
int datalen = data.size();
|
|
|
|
int datasize = sizeof(uint8_t);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
if (buf) {
|
2017-03-05 16:44:50 +01:00
|
|
|
encode_uint32(datalen, buf);
|
|
|
|
buf += 4;
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t>::Read r = data.read();
|
2017-03-05 16:44:50 +01:00
|
|
|
copymem(buf, &r[0], datalen * datasize);
|
2019-05-19 19:09:16 +02:00
|
|
|
buf += datalen * datasize;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 4 + datalen * datasize;
|
2019-05-19 19:09:16 +02:00
|
|
|
while (r_len % 4) {
|
2014-02-10 02:10:30 +01:00
|
|
|
r_len++;
|
2019-05-19 19:09:16 +02:00
|
|
|
if (buf)
|
|
|
|
*(buf++) = 0;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
2017-01-11 04:52:51 +01:00
|
|
|
case Variant::POOL_INT_ARRAY: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<int> data = p_variant;
|
2017-03-05 16:44:50 +01:00
|
|
|
int datalen = data.size();
|
|
|
|
int datasize = sizeof(int32_t);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (buf) {
|
2017-03-05 16:44:50 +01:00
|
|
|
encode_uint32(datalen, buf);
|
|
|
|
buf += 4;
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<int>::Read r = data.read();
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < datalen; i++)
|
|
|
|
encode_uint32(r[i], &buf[i * datasize]);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 4 + datalen * datasize;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
2017-01-11 04:52:51 +01:00
|
|
|
case Variant::POOL_REAL_ARRAY: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<real_t> data = p_variant;
|
2017-03-05 16:44:50 +01:00
|
|
|
int datalen = data.size();
|
|
|
|
int datasize = sizeof(real_t);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (buf) {
|
2017-03-05 16:44:50 +01:00
|
|
|
encode_uint32(datalen, buf);
|
|
|
|
buf += 4;
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<real_t>::Read r = data.read();
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < datalen; i++)
|
|
|
|
encode_float(r[i], &buf[i * datasize]);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 4 + datalen * datasize;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
2017-01-11 04:52:51 +01:00
|
|
|
case Variant::POOL_STRING_ARRAY: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<String> data = p_variant;
|
2017-03-05 16:44:50 +01:00
|
|
|
int len = data.size();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (buf) {
|
2017-03-05 16:44:50 +01:00
|
|
|
encode_uint32(len, buf);
|
|
|
|
buf += 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < len; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
CharString utf8 = data.get(i).utf8();
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-05 16:44:50 +01:00
|
|
|
encode_uint32(utf8.length() + 1, buf);
|
|
|
|
buf += 4;
|
|
|
|
copymem(buf, utf8.get_data(), utf8.length() + 1);
|
|
|
|
buf += utf8.length() + 1;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 4 + utf8.length() + 1;
|
|
|
|
while (r_len % 4) {
|
2014-02-10 02:10:30 +01:00
|
|
|
r_len++; //pad
|
|
|
|
if (buf)
|
2018-07-08 15:11:41 +02:00
|
|
|
*(buf++) = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-10 10:37:04 +02:00
|
|
|
} break;
|
2017-01-11 04:52:51 +01:00
|
|
|
case Variant::POOL_VECTOR2_ARRAY: {
|
2013-04-10 10:37:04 +02:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector2> data = p_variant;
|
2017-03-05 16:44:50 +01:00
|
|
|
int len = data.size();
|
2013-04-10 10:37:04 +02:00
|
|
|
|
|
|
|
if (buf) {
|
2017-03-05 16:44:50 +01:00
|
|
|
encode_uint32(len, buf);
|
|
|
|
buf += 4;
|
2013-04-10 10:37:04 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 4;
|
2013-04-10 10:37:04 +02:00
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < len; i++) {
|
2013-04-10 10:37:04 +02:00
|
|
|
|
|
|
|
Vector2 v = data.get(i);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
encode_float(v.x, &buf[0]);
|
|
|
|
encode_float(v.y, &buf[4]);
|
|
|
|
buf += 4 * 2;
|
2013-04-10 10:37:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 4 * 2 * len;
|
2013-04-10 10:37:04 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
2017-01-11 04:52:51 +01:00
|
|
|
case Variant::POOL_VECTOR3_ARRAY: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3> data = p_variant;
|
2017-03-05 16:44:50 +01:00
|
|
|
int len = data.size();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (buf) {
|
2017-03-05 16:44:50 +01:00
|
|
|
encode_uint32(len, buf);
|
|
|
|
buf += 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < len; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Vector3 v = data.get(i);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
encode_float(v.x, &buf[0]);
|
|
|
|
encode_float(v.y, &buf[4]);
|
|
|
|
encode_float(v.z, &buf[8]);
|
|
|
|
buf += 4 * 3;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 4 * 3 * len;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
2017-01-11 04:52:51 +01:00
|
|
|
case Variant::POOL_COLOR_ARRAY: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Color> data = p_variant;
|
2017-03-05 16:44:50 +01:00
|
|
|
int len = data.size();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (buf) {
|
2017-03-05 16:44:50 +01:00
|
|
|
encode_uint32(len, buf);
|
|
|
|
buf += 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < len; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Color c = data.get(i);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
encode_float(c.r, &buf[0]);
|
|
|
|
encode_float(c.g, &buf[4]);
|
|
|
|
encode_float(c.b, &buf[8]);
|
|
|
|
encode_float(c.a, &buf[12]);
|
|
|
|
buf += 4 * 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_len += 4 * 4 * len;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
2019-04-09 17:08:36 +02:00
|
|
|
default: {
|
|
|
|
ERR_FAIL_V(ERR_BUG);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|