2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* marshalls.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:11:45 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2017-01-01 21:01:57 +00:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-07 22:45:00 +00:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00: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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "marshalls.h"
|
|
|
|
#include "os/keyboard.h"
|
2017-03-18 23:36:26 +00:00
|
|
|
#include "print_string.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const uint8_t *buf = p_buffer;
|
|
|
|
int len = p_len;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (len < 4) {
|
2015-10-21 19:52:43 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2015-10-21 19:52:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
uint32_t type = decode_uint32(buf);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(type >= Variant::VARIANT_MAX, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_len = 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case Variant::NIL: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_variant = Variant();
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case Variant::BOOL: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
bool val = decode_uint32(buf);
|
2017-03-18 23:36:26 +00:00
|
|
|
r_variant = val;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case Variant::INT: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
int val = decode_uint32(buf);
|
2017-03-18 23:36:26 +00:00
|
|
|
r_variant = val;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::REAL: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < (int)4, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
float val = decode_float(buf);
|
2017-03-18 23:36:26 +00:00
|
|
|
r_variant = val;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::STRING: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
uint32_t strlen = decode_uint32(buf);
|
2017-03-18 23:36:26 +00:00
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
|
|
|
ERR_FAIL_COND_V((int)strlen > len, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String str;
|
2017-03-18 23:36:26 +00:00
|
|
|
str.parse_utf8((const char *)buf, strlen);
|
|
|
|
r_variant = str;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-03-08 23:00:52 +00:00
|
|
|
if (r_len) {
|
2017-03-18 23:36:26 +00:00
|
|
|
if (strlen % 4)
|
|
|
|
(*r_len) += 4 - strlen % 4;
|
|
|
|
(*r_len) += 4 + strlen;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
// math types
|
|
|
|
|
|
|
|
case Variant::VECTOR2: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < (int)4 * 2, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector2 val;
|
2017-03-18 23:36:26 +00:00
|
|
|
val.x = decode_float(&buf[0]);
|
|
|
|
val.y = decode_float(&buf[4]);
|
|
|
|
r_variant = val;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4 * 2;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} break; // 5
|
2014-02-10 01:10:30 +00:00
|
|
|
case Variant::RECT2: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < (int)4 * 4, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
Rect2 val;
|
2017-03-18 23:36:26 +00:00
|
|
|
val.pos.x = decode_float(&buf[0]);
|
|
|
|
val.pos.y = decode_float(&buf[4]);
|
|
|
|
val.size.x = decode_float(&buf[8]);
|
|
|
|
val.size.y = decode_float(&buf[12]);
|
|
|
|
r_variant = val;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4 * 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::VECTOR3: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < (int)4 * 3, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector3 val;
|
2017-03-18 23:36:26 +00: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 01:10:30 +00:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4 * 3;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2013-04-10 08:37:04 +00:00
|
|
|
} break;
|
|
|
|
case Variant::MATRIX32: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < (int)4 * 6, ERR_INVALID_DATA);
|
2013-04-10 08:37:04 +00:00
|
|
|
Matrix32 val;
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
for (int j = 0; j < 2; j++) {
|
2013-04-10 08:37:04 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
val.elements[i][j] = decode_float(&buf[(i * 2 + j) * 4]);
|
2013-04-10 08:37:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_variant = val;
|
2013-04-10 08:37:04 +00:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4 * 6;
|
2013-04-10 08:37:04 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case Variant::PLANE: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < (int)4 * 4, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
Plane val;
|
2017-03-18 23:36:26 +00: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 01:10:30 +00:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4 * 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::QUAT: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < (int)4 * 4, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
Quat val;
|
2017-03-18 23:36:26 +00: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 01:10:30 +00:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4 * 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::_AABB: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < (int)4 * 6, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
AABB val;
|
2017-03-18 23:36:26 +00:00
|
|
|
val.pos.x = decode_float(&buf[0]);
|
|
|
|
val.pos.y = decode_float(&buf[4]);
|
|
|
|
val.pos.z = decode_float(&buf[8]);
|
|
|
|
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 01:10:30 +00:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4 * 6;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::MATRIX3: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < (int)4 * 9, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
Matrix3 val;
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
for (int j = 0; j < 3; j++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
val.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_variant = val;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4 * 9;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::TRANSFORM: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < (int)4 * 12, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
Transform val;
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
for (int j = 0; j < 3; j++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
val.basis.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-18 23:36:26 +00: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 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_variant = val;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4 * 12;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
// misc types
|
|
|
|
case Variant::COLOR: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < (int)4 * 4, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
Color val;
|
2017-03-18 23:36:26 +00: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 01:10:30 +00:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4 * 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::IMAGE: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < (int)5 * 4, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
Image::Format fmt = (Image::Format)decode_uint32(&buf[0]);
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_INDEX_V(fmt, Image::FORMAT_MAX, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
uint32_t mipmaps = decode_uint32(&buf[4]);
|
|
|
|
uint32_t w = decode_uint32(&buf[8]);
|
|
|
|
uint32_t h = decode_uint32(&buf[12]);
|
|
|
|
uint32_t datalen = decode_uint32(&buf[16]);
|
|
|
|
|
|
|
|
Image img;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (datalen > 0) {
|
|
|
|
len -= 5 * 4;
|
|
|
|
ERR_FAIL_COND_V(len < datalen, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
DVector<uint8_t> data;
|
|
|
|
data.resize(datalen);
|
|
|
|
DVector<uint8_t>::Write wr = data.write();
|
2017-03-18 23:36:26 +00:00
|
|
|
copymem(&wr[0], &buf[20], datalen);
|
2014-02-10 01:10:30 +00:00
|
|
|
wr = DVector<uint8_t>::Write();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
img = Image(w, h, mipmaps, fmt, data);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_variant = img;
|
2014-03-14 01:57:24 +00:00
|
|
|
if (r_len) {
|
2017-03-18 23:36:26 +00:00
|
|
|
if (datalen % 4)
|
|
|
|
(*r_len) += 4 - datalen % 4;
|
2014-03-14 01:57:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4 * 5 + datalen;
|
2014-03-14 01:57:24 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::NODE_PATH: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
uint32_t strlen = decode_uint32(buf);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (strlen & 0x80000000) {
|
2014-03-14 01:57:24 +00:00
|
|
|
//new format
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < 12, ERR_INVALID_DATA);
|
2014-03-14 01:57:24 +00:00
|
|
|
Vector<StringName> names;
|
|
|
|
Vector<StringName> subnames;
|
|
|
|
StringName prop;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
uint32_t namecount = strlen &= 0x7FFFFFFF;
|
|
|
|
uint32_t subnamecount = decode_uint32(buf + 4);
|
|
|
|
uint32_t flags = decode_uint32(buf + 8);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
len -= 12;
|
|
|
|
buf += 12;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int total = namecount + subnamecount;
|
|
|
|
if (flags & 2)
|
2014-03-14 01:57:24 +00:00
|
|
|
total++;
|
|
|
|
|
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 12;
|
2014-03-14 01:57:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < total; i++) {
|
2014-03-14 01:57:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V((int)len < 4, ERR_INVALID_DATA);
|
2014-03-14 01:57:24 +00:00
|
|
|
strlen = decode_uint32(buf);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int pad = 0;
|
2014-03-14 01:57:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (strlen % 4)
|
|
|
|
pad += 4 - strlen % 4;
|
2014-03-14 01:57:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
|
|
|
ERR_FAIL_COND_V((int)strlen + pad > len, ERR_INVALID_DATA);
|
2014-03-14 01:57:24 +00:00
|
|
|
|
|
|
|
String str;
|
2017-03-18 23:36:26 +00:00
|
|
|
str.parse_utf8((const char *)buf, strlen);
|
2014-03-14 01:57:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (i < namecount)
|
2014-03-14 01:57:24 +00:00
|
|
|
names.push_back(str);
|
2017-03-18 23:36:26 +00:00
|
|
|
else if (i < namecount + subnamecount)
|
2014-03-14 01:57:24 +00:00
|
|
|
subnames.push_back(str);
|
|
|
|
else
|
2017-03-18 23:36:26 +00:00
|
|
|
prop = str;
|
2014-03-14 01:57:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
buf += strlen + pad;
|
|
|
|
len -= strlen + pad;
|
2014-03-14 01:57:24 +00:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4 + strlen + pad;
|
2014-03-14 01:57:24 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_variant = NodePath(names, subnames, flags & 1, prop);
|
2014-03-14 01:57:24 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
//old format, just a string
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
|
|
|
ERR_FAIL_COND_V((int)strlen > len, ERR_INVALID_DATA);
|
2014-03-14 01:57:24 +00:00
|
|
|
|
|
|
|
String str;
|
2017-03-18 23:36:26 +00:00
|
|
|
str.parse_utf8((const char *)buf, strlen);
|
2014-03-14 01:57:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_variant = NodePath(str);
|
2014-03-14 01:57:24 +00:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4 + strlen;
|
2014-03-14 01:57:24 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00: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-03-18 23:36:26 +00:00
|
|
|
r_variant = (Object *)NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case Variant::INPUT_EVENT: {
|
|
|
|
|
|
|
|
InputEvent ie;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ie.type = decode_uint32(&buf[0]);
|
|
|
|
ie.device = decode_uint32(&buf[4]);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 12;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (ie.type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case InputEvent::KEY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
uint32_t mods = decode_uint32(&buf[12]);
|
|
|
|
if (mods & KEY_MASK_SHIFT)
|
|
|
|
ie.key.mod.shift = true;
|
|
|
|
if (mods & KEY_MASK_CTRL)
|
|
|
|
ie.key.mod.control = true;
|
|
|
|
if (mods & KEY_MASK_ALT)
|
|
|
|
ie.key.mod.alt = true;
|
|
|
|
if (mods & KEY_MASK_META)
|
|
|
|
ie.key.mod.meta = true;
|
|
|
|
ie.key.scancode = decode_uint32(&buf[16]);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 8;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case InputEvent::MOUSE_BUTTON: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ie.mouse_button.button_index = decode_uint32(&buf[12]);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case InputEvent::JOYSTICK_BUTTON: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ie.joy_button.button_index = decode_uint32(&buf[12]);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case InputEvent::SCREEN_TOUCH: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ie.screen_touch.index = decode_uint32(&buf[12]);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case InputEvent::JOYSTICK_MOTION: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ie.joy_motion.axis = decode_uint32(&buf[12]);
|
|
|
|
ie.joy_motion.axis_value = decode_float(&buf[16]);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 8;
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
r_variant = ie;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::DICTIONARY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
|
|
|
uint32_t count = decode_uint32(buf);
|
|
|
|
bool shared = count & 0x80000000;
|
|
|
|
count &= 0x7FFFFFFF;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (r_len) {
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Dictionary d(shared);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Variant key, value;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int used;
|
2017-03-18 23:36:26 +00:00
|
|
|
Error err = decode_variant(key, buf, len, &used);
|
|
|
|
ERR_FAIL_COND_V(err, err);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
buf += used;
|
|
|
|
len -= used;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (r_len) {
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += used;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
err = decode_variant(value, buf, len, &used);
|
|
|
|
ERR_FAIL_COND_V(err, err);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
buf += used;
|
|
|
|
len -= used;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (r_len) {
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += used;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
d[key] = value;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_variant = d;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
uint32_t count = decode_uint32(buf);
|
2017-03-18 23:36:26 +00:00
|
|
|
bool shared = count & 0x80000000;
|
|
|
|
count &= 0x7FFFFFFF;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (r_len) {
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Array varr(shared);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int used = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
Variant v;
|
2017-03-18 23:36:26 +00:00
|
|
|
Error err = decode_variant(v, buf, len, &used);
|
|
|
|
ERR_FAIL_COND_V(err, err);
|
|
|
|
buf += used;
|
|
|
|
len -= used;
|
2014-02-10 01:10:30 +00:00
|
|
|
varr.push_back(v);
|
|
|
|
if (r_len) {
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += used;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_variant = varr;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
// arrays
|
|
|
|
case Variant::RAW_ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
uint32_t count = decode_uint32(buf);
|
2017-03-18 23:36:26 +00:00
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
|
|
|
ERR_FAIL_COND_V((int)count > len, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
DVector<uint8_t> data;
|
|
|
|
|
|
|
|
if (count) {
|
|
|
|
data.resize(count);
|
|
|
|
DVector<uint8_t>::Write w = data.write();
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < count; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
w[i] = buf[i];
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
w = DVector<uint8_t>::Write();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_variant = data;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (r_len) {
|
2017-03-18 23:36:26 +00:00
|
|
|
if (count % 4)
|
|
|
|
(*r_len) += 4 - count % 4;
|
|
|
|
(*r_len) += 4 + count;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::INT_ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
uint32_t count = decode_uint32(buf);
|
2017-03-18 23:36:26 +00:00
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
|
|
|
ERR_FAIL_COND_V((int)count * 4 > len, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
DVector<int> data;
|
|
|
|
|
|
|
|
if (count) {
|
|
|
|
//const int*rbuf=(const int*)buf;
|
|
|
|
data.resize(count);
|
|
|
|
DVector<int>::Write w = data.write();
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < count; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
w[i] = decode_uint32(&buf[i * 4]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
w = DVector<int>::Write();
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
r_variant = Variant(data);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (r_len) {
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4 + count * sizeof(int);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::REAL_ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
uint32_t count = decode_uint32(buf);
|
2017-03-18 23:36:26 +00:00
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
|
|
|
ERR_FAIL_COND_V((int)count * 4 > len, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
DVector<float> data;
|
|
|
|
|
|
|
|
if (count) {
|
|
|
|
//const float*rbuf=(const float*)buf;
|
|
|
|
data.resize(count);
|
|
|
|
DVector<float>::Write w = data.write();
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < count; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
w[i] = decode_float(&buf[i * 4]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
w = DVector<float>::Write();
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
r_variant = data;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (r_len) {
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4 + count * sizeof(float);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::STRING_ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
uint32_t count = decode_uint32(buf);
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(count < 0, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
DVector<String> strings;
|
2017-03-18 23:36:26 +00:00
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
//printf("string count: %i\n",count);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < (int)count; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
uint32_t strlen = decode_uint32(buf);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
|
|
|
ERR_FAIL_COND_V((int)strlen > len, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//printf("loaded string: %s\n",(const char*)buf);
|
|
|
|
String str;
|
2017-03-18 23:36:26 +00:00
|
|
|
str.parse_utf8((const char *)buf, strlen);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
strings.push_back(str);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
buf += strlen;
|
|
|
|
len -= strlen;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4 + strlen;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (strlen % 4) {
|
|
|
|
int pad = 4 - (strlen % 4);
|
|
|
|
buf += pad;
|
|
|
|
len -= pad;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (r_len) {
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += pad;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_variant = strings;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2013-04-10 08:37:04 +00:00
|
|
|
} break;
|
|
|
|
case Variant::VECTOR2_ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2013-04-10 08:37:04 +00:00
|
|
|
uint32_t count = decode_uint32(buf);
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(count < 0, ERR_INVALID_DATA);
|
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
2013-04-10 08:37:04 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V((int)count * 4 * 2 > len, ERR_INVALID_DATA);
|
2013-04-10 08:37:04 +00:00
|
|
|
DVector<Vector2> varray;
|
|
|
|
|
|
|
|
if (r_len) {
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4;
|
2013-04-10 08:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count) {
|
|
|
|
varray.resize(count);
|
|
|
|
DVector<Vector2>::Write w = varray.write();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < (int)count; i++) {
|
2013-04-10 08:37:04 +00:00
|
|
|
|
2017-03-18 23:36:26 +00: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 08:37:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int adv = 4 * 2 * count;
|
2013-04-10 08:37:04 +00:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += adv;
|
|
|
|
len -= adv;
|
|
|
|
buf += adv;
|
2013-04-10 08:37:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_variant = varray;
|
2013-04-10 08:37:04 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case Variant::VECTOR3_ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
uint32_t count = decode_uint32(buf);
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(count < 0, ERR_INVALID_DATA);
|
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V((int)count * 4 * 3 > len, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
DVector<Vector3> varray;
|
|
|
|
|
|
|
|
if (r_len) {
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count) {
|
|
|
|
varray.resize(count);
|
|
|
|
DVector<Vector3>::Write w = varray.write();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < (int)count; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00: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 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int adv = 4 * 3 * count;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += adv;
|
|
|
|
len -= adv;
|
|
|
|
buf += adv;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_variant = varray;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::COLOR_ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
uint32_t count = decode_uint32(buf);
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(count < 0, ERR_INVALID_DATA);
|
|
|
|
buf += 4;
|
|
|
|
len -= 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V((int)count * 4 * 4 > len, ERR_INVALID_DATA);
|
2014-02-10 01:10:30 +00:00
|
|
|
DVector<Color> carray;
|
|
|
|
|
|
|
|
if (r_len) {
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count) {
|
|
|
|
carray.resize(count);
|
|
|
|
DVector<Color>::Write w = carray.write();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < (int)count; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00: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 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int adv = 4 * 4 * count;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (r_len)
|
2017-03-18 23:36:26 +00:00
|
|
|
(*r_len) += adv;
|
|
|
|
len -= adv;
|
|
|
|
buf += adv;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_variant = carray;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
default: { ERR_FAIL_V(ERR_BUG); }
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
uint8_t *buf = r_buffer;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(p_variant.get_type(), buf);
|
|
|
|
buf += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (p_variant.get_type()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case Variant::NIL: {
|
|
|
|
|
|
|
|
//nothing to do
|
|
|
|
} break;
|
|
|
|
case Variant::BOOL: {
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(p_variant.operator bool(), buf);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::INT: {
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(p_variant.operator int(), buf);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::REAL: {
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_float(p_variant.operator float(), buf);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
2014-03-14 01:57:24 +00:00
|
|
|
case Variant::NODE_PATH: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
NodePath np = p_variant;
|
2014-03-14 01:57:24 +00:00
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00: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);
|
|
|
|
uint32_t flags = 0;
|
2014-03-14 01:57:24 +00:00
|
|
|
if (np.is_absolute())
|
2017-03-18 23:36:26 +00:00
|
|
|
flags |= 1;
|
|
|
|
if (np.get_property() != StringName())
|
|
|
|
flags |= 2;
|
2014-03-14 01:57:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(flags, buf + 8);
|
2014-03-14 01:57:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
buf += 12;
|
2014-03-14 01:57:24 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 12;
|
2014-03-14 01:57:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int total = np.get_name_count() + np.get_subname_count();
|
|
|
|
if (np.get_property() != StringName())
|
2014-03-14 01:57:24 +00:00
|
|
|
total++;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < total; i++) {
|
2014-03-14 01:57:24 +00:00
|
|
|
|
|
|
|
String str;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (i < np.get_name_count())
|
|
|
|
str = np.get_name(i);
|
|
|
|
else if (i < np.get_name_count() + np.get_subname_count())
|
|
|
|
str = np.get_subname(i - np.get_subname_count());
|
2014-03-14 01:57:24 +00:00
|
|
|
else
|
2017-03-18 23:36:26 +00:00
|
|
|
str = np.get_property();
|
2014-03-14 01:57:24 +00:00
|
|
|
|
|
|
|
CharString utf8 = str.utf8();
|
|
|
|
|
|
|
|
int pad = 0;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (utf8.length() % 4)
|
|
|
|
pad = 4 - utf8.length() % 4;
|
2014-03-14 01:57:24 +00:00
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(utf8.length(), buf);
|
|
|
|
buf += 4;
|
|
|
|
copymem(buf, utf8.get_data(), utf8.length());
|
|
|
|
buf += pad + utf8.length();
|
2014-03-14 01:57:24 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 4 + utf8.length() + pad;
|
2014-03-14 01:57:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case Variant::STRING: {
|
|
|
|
|
|
|
|
CharString utf8 = p_variant.operator String().utf8();
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(utf8.length(), buf);
|
|
|
|
buf += 4;
|
|
|
|
copymem(buf, utf8.get_data(), utf8.length());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 4 + utf8.length();
|
|
|
|
while (r_len % 4)
|
2014-02-10 01:10:30 +00:00
|
|
|
r_len++; //pad
|
|
|
|
|
|
|
|
} break;
|
|
|
|
// math types
|
|
|
|
|
|
|
|
case Variant::VECTOR2: {
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00:00
|
|
|
Vector2 v2 = p_variant;
|
|
|
|
encode_float(v2.x, &buf[0]);
|
|
|
|
encode_float(v2.y, &buf[4]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 2 * 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} break; // 5
|
2014-02-10 01:10:30 +00:00
|
|
|
case Variant::RECT2: {
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00:00
|
|
|
Rect2 r2 = p_variant;
|
|
|
|
encode_float(r2.pos.x, &buf[0]);
|
|
|
|
encode_float(r2.pos.y, &buf[4]);
|
|
|
|
encode_float(r2.size.x, &buf[8]);
|
|
|
|
encode_float(r2.size.y, &buf[12]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 4 * 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::VECTOR3: {
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00: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 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 3 * 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2013-04-10 08:37:04 +00:00
|
|
|
} break;
|
|
|
|
case Variant::MATRIX32: {
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00:00
|
|
|
Matrix32 val = p_variant;
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
for (int j = 0; j < 2; j++) {
|
2013-04-10 08:37:04 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
copymem(&buf[(i * 2 + j) * 4], &val.elements[i][j], sizeof(float));
|
2013-04-10 08:37:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 6 * 4;
|
2013-04-10 08:37:04 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case Variant::PLANE: {
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00: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 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 4 * 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::QUAT: {
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00: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 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 4 * 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::_AABB: {
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00:00
|
|
|
AABB aabb = p_variant;
|
|
|
|
encode_float(aabb.pos.x, &buf[0]);
|
|
|
|
encode_float(aabb.pos.y, &buf[4]);
|
|
|
|
encode_float(aabb.pos.z, &buf[8]);
|
|
|
|
encode_float(aabb.size.x, &buf[12]);
|
|
|
|
encode_float(aabb.size.y, &buf[16]);
|
|
|
|
encode_float(aabb.size.z, &buf[20]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 6 * 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::MATRIX3: {
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00:00
|
|
|
Matrix3 val = p_variant;
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
for (int j = 0; j < 3; j++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
copymem(&buf[(i * 3 + j) * 4], &val.elements[i][j], sizeof(float));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 9 * 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::TRANSFORM: {
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00:00
|
|
|
Transform val = p_variant;
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
for (int j = 0; j < 3; j++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
copymem(&buf[(i * 3 + j) * 4], &val.basis.elements[i][j], sizeof(float));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00: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 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 12 * 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
// misc types
|
|
|
|
case Variant::COLOR: {
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00: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 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 4 * 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::IMAGE: {
|
|
|
|
|
|
|
|
Image image = p_variant;
|
2017-03-18 23:36:26 +00:00
|
|
|
DVector<uint8_t> data = image.get_data();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(image.get_format(), &buf[0]);
|
|
|
|
encode_uint32(image.get_mipmaps(), &buf[4]);
|
|
|
|
encode_uint32(image.get_width(), &buf[8]);
|
|
|
|
encode_uint32(image.get_height(), &buf[12]);
|
|
|
|
int ds = data.size();
|
|
|
|
encode_uint32(ds, &buf[16]);
|
2014-02-10 01:10:30 +00:00
|
|
|
DVector<uint8_t>::Read r = data.read();
|
2017-03-18 23:36:26 +00:00
|
|
|
copymem(&buf[20], &r[0], ds);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int pad = 0;
|
|
|
|
if (data.size() % 4)
|
|
|
|
pad = 4 - data.size() % 4;
|
2014-03-14 01:57:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += data.size() + 5 * 4 + pad;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-03-08 23:00:52 +00:00
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
/*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:
|
|
|
|
case Variant::OBJECT: {
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::INPUT_EVENT: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
InputEvent ie = p_variant;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(ie.type, &buf[0]);
|
|
|
|
encode_uint32(ie.device, &buf[4]);
|
|
|
|
encode_uint32(0, &buf[8]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int llen = 12;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (ie.type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case InputEvent::KEY: {
|
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
uint32_t mods = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (ie.key.mod.shift)
|
2017-03-18 23:36:26 +00:00
|
|
|
mods |= KEY_MASK_SHIFT;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (ie.key.mod.control)
|
2017-03-18 23:36:26 +00:00
|
|
|
mods |= KEY_MASK_CTRL;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (ie.key.mod.alt)
|
2017-03-18 23:36:26 +00:00
|
|
|
mods |= KEY_MASK_ALT;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (ie.key.mod.meta)
|
2017-03-18 23:36:26 +00:00
|
|
|
mods |= KEY_MASK_META;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(mods, &buf[llen]);
|
|
|
|
encode_uint32(ie.key.scancode, &buf[llen + 4]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
llen += 8;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case InputEvent::MOUSE_BUTTON: {
|
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(ie.mouse_button.button_index, &buf[llen]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
llen += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case InputEvent::JOYSTICK_BUTTON: {
|
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(ie.joy_button.button_index, &buf[llen]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
llen += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case InputEvent::SCREEN_TOUCH: {
|
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(ie.screen_touch.index, &buf[llen]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
llen += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case InputEvent::JOYSTICK_MOTION: {
|
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
|
|
|
|
int axis = ie.joy_motion.axis;
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(axis, &buf[llen]);
|
|
|
|
encode_float(ie.joy_motion.axis_value, &buf[llen + 4]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
llen += 8;
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buf)
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(llen, &buf[8]);
|
|
|
|
r_len += llen;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
// not supported
|
|
|
|
} break;
|
|
|
|
case Variant::DICTIONARY: {
|
|
|
|
|
|
|
|
Dictionary d = p_variant;
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(uint32_t(d.size()) | (d.is_shared() ? 0x80000000 : 0), buf);
|
|
|
|
buf += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
List<Variant> keys;
|
|
|
|
d.get_key_list(&keys);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00: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;
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_variant(E->get(), buf, len);
|
|
|
|
ERR_FAIL_COND_V(len % 4, ERR_BUG);
|
|
|
|
r_len += len;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (buf)
|
|
|
|
buf += len;
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_variant(d[E->get()], buf, len);
|
|
|
|
ERR_FAIL_COND_V(len % 4, ERR_BUG);
|
|
|
|
r_len += len;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (buf)
|
|
|
|
buf += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::ARRAY: {
|
|
|
|
|
|
|
|
Array v = p_variant;
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(uint32_t(v.size()) | (v.is_shared() ? 0x80000000 : 0), buf);
|
|
|
|
buf += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < v.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int len;
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_variant(v.get(i), buf, len);
|
|
|
|
ERR_FAIL_COND_V(len % 4, ERR_BUG);
|
|
|
|
r_len += len;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (buf)
|
2017-03-18 23:36:26 +00:00
|
|
|
buf += len;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
// arrays
|
|
|
|
case Variant::RAW_ARRAY: {
|
|
|
|
|
|
|
|
DVector<uint8_t> data = p_variant;
|
2017-03-18 23:36:26 +00:00
|
|
|
int datalen = data.size();
|
|
|
|
int datasize = sizeof(uint8_t);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(datalen, buf);
|
|
|
|
buf += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
DVector<uint8_t>::Read r = data.read();
|
2017-03-18 23:36:26 +00:00
|
|
|
copymem(buf, &r[0], datalen * datasize);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 4 + datalen * datasize;
|
|
|
|
while (r_len % 4)
|
2014-02-10 01:10:30 +00:00
|
|
|
r_len++;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::INT_ARRAY: {
|
|
|
|
|
|
|
|
DVector<int> data = p_variant;
|
2017-03-18 23:36:26 +00:00
|
|
|
int datalen = data.size();
|
|
|
|
int datasize = sizeof(int32_t);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(datalen, buf);
|
|
|
|
buf += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
DVector<int>::Read r = data.read();
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < datalen; i++)
|
|
|
|
encode_uint32(r[i], &buf[i * datasize]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 4 + datalen * datasize;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::REAL_ARRAY: {
|
|
|
|
|
|
|
|
DVector<real_t> data = p_variant;
|
2017-03-18 23:36:26 +00:00
|
|
|
int datalen = data.size();
|
|
|
|
int datasize = sizeof(real_t);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(datalen, buf);
|
|
|
|
buf += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
DVector<real_t>::Read r = data.read();
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < datalen; i++)
|
|
|
|
encode_float(r[i], &buf[i * datasize]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 4 + datalen * datasize;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::STRING_ARRAY: {
|
|
|
|
|
|
|
|
DVector<String> data = p_variant;
|
2017-03-18 23:36:26 +00:00
|
|
|
int len = data.size();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(len, buf);
|
|
|
|
buf += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < len; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
CharString utf8 = data.get(i).utf8();
|
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(utf8.length() + 1, buf);
|
|
|
|
buf += 4;
|
|
|
|
copymem(buf, utf8.get_data(), utf8.length() + 1);
|
|
|
|
buf += utf8.length() + 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 4 + utf8.length() + 1;
|
|
|
|
while (r_len % 4) {
|
2014-02-10 01:10:30 +00:00
|
|
|
r_len++; //pad
|
|
|
|
if (buf)
|
|
|
|
buf++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-10 08:37:04 +00:00
|
|
|
} break;
|
|
|
|
case Variant::VECTOR2_ARRAY: {
|
|
|
|
|
|
|
|
DVector<Vector2> data = p_variant;
|
2017-03-18 23:36:26 +00:00
|
|
|
int len = data.size();
|
2013-04-10 08:37:04 +00:00
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(len, buf);
|
|
|
|
buf += 4;
|
2013-04-10 08:37:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 4;
|
2013-04-10 08:37:04 +00:00
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < len; i++) {
|
2013-04-10 08:37:04 +00:00
|
|
|
|
|
|
|
Vector2 v = data.get(i);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_float(v.x, &buf[0]);
|
|
|
|
encode_float(v.y, &buf[4]);
|
|
|
|
buf += 4 * 2;
|
2013-04-10 08:37:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 4 * 2 * len;
|
2013-04-10 08:37:04 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case Variant::VECTOR3_ARRAY: {
|
|
|
|
|
|
|
|
DVector<Vector3> data = p_variant;
|
2017-03-18 23:36:26 +00:00
|
|
|
int len = data.size();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(len, buf);
|
|
|
|
buf += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < len; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Vector3 v = data.get(i);
|
|
|
|
|
2017-03-18 23:36:26 +00: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 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 4 * 3 * len;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::COLOR_ARRAY: {
|
|
|
|
|
|
|
|
DVector<Color> data = p_variant;
|
2017-03-18 23:36:26 +00:00
|
|
|
int len = data.size();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (buf) {
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(len, buf);
|
|
|
|
buf += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < len; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Color c = data.get(i);
|
|
|
|
|
2017-03-18 23:36:26 +00: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 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_len += 4 * 4 * len;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
default: { ERR_FAIL_V(ERR_BUG); }
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|