summaryrefslogtreecommitdiff
path: root/core/io/marshalls.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/io/marshalls.cpp')
-rw-r--r--core/io/marshalls.cpp274
1 files changed, 104 insertions, 170 deletions
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index 81bc45b2f7..eb39b1433f 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -49,13 +49,9 @@ void EncodedObjectAsID::set_object_id(ObjectID p_id) {
}
ObjectID EncodedObjectAsID::get_object_id() const {
-
return id;
}
-EncodedObjectAsID::EncodedObjectAsID() {
-}
-
#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)
@@ -100,7 +96,6 @@ static Error _decode_string(const uint8_t *&buf, int &len, int *r_len, String &r
}
Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len, bool p_allow_objects) {
-
const uint8_t *buf = p_buffer;
int len = p_len;
@@ -112,95 +107,95 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
buf += 4;
len -= 4;
- if (r_len)
+ if (r_len) {
*r_len = 4;
+ }
switch (type & ENCODE_MASK) {
-
case Variant::NIL: {
-
r_variant = Variant();
} break;
case Variant::BOOL: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
bool val = decode_uint32(buf);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4;
+ }
} break;
case Variant::INT: {
-
if (type & ENCODE_FLAG_64) {
ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA);
int64_t val = decode_uint64(buf);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 8;
+ }
} else {
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t val = decode_uint32(buf);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4;
+ }
}
} break;
case Variant::FLOAT: {
-
if (type & ENCODE_FLAG_64) {
ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA);
double val = decode_double(buf);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 8;
+ }
} else {
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
float val = decode_float(buf);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4;
+ }
}
} break;
case Variant::STRING: {
-
String str;
Error err = _decode_string(buf, len, r_len, str);
- if (err)
+ if (err) {
return err;
+ }
r_variant = str;
} break;
// math types
case Variant::VECTOR2: {
-
ERR_FAIL_COND_V(len < 4 * 2, ERR_INVALID_DATA);
Vector2 val;
val.x = decode_float(&buf[0]);
val.y = decode_float(&buf[4]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 2;
+ }
} break;
case Variant::VECTOR2I: {
-
ERR_FAIL_COND_V(len < 4 * 2, ERR_INVALID_DATA);
Vector2i val;
val.x = decode_uint32(&buf[0]);
val.y = decode_uint32(&buf[4]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 2;
+ }
} break;
case Variant::RECT2: {
-
ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
Rect2 val;
val.position.x = decode_float(&buf[0]);
@@ -209,12 +204,12 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.size.y = decode_float(&buf[12]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 4;
+ }
} break;
case Variant::RECT2I: {
-
ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
Rect2i val;
val.position.x = decode_uint32(&buf[0]);
@@ -223,12 +218,12 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.size.y = decode_uint32(&buf[12]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 4;
+ }
} break;
case Variant::VECTOR3: {
-
ERR_FAIL_COND_V(len < 4 * 3, ERR_INVALID_DATA);
Vector3 val;
val.x = decode_float(&buf[0]);
@@ -236,12 +231,12 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.z = decode_float(&buf[8]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 3;
+ }
} break;
case Variant::VECTOR3I: {
-
ERR_FAIL_COND_V(len < 4 * 3, ERR_INVALID_DATA);
Vector3i val;
val.x = decode_uint32(&buf[0]);
@@ -249,29 +244,28 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.z = decode_uint32(&buf[8]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 3;
+ }
} break;
case Variant::TRANSFORM2D: {
-
ERR_FAIL_COND_V(len < 4 * 6, ERR_INVALID_DATA);
Transform2D val;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
-
val.elements[i][j] = decode_float(&buf[(i * 2 + j) * 4]);
}
}
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 6;
+ }
} break;
case Variant::PLANE: {
-
ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
Plane val;
val.normal.x = decode_float(&buf[0]);
@@ -280,12 +274,12 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.d = decode_float(&buf[12]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 4;
+ }
} break;
case Variant::QUAT: {
-
ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
Quat val;
val.x = decode_float(&buf[0]);
@@ -294,12 +288,12 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.w = decode_float(&buf[12]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 4;
+ }
} break;
case Variant::AABB: {
-
ERR_FAIL_COND_V(len < 4 * 6, ERR_INVALID_DATA);
AABB val;
val.position.x = decode_float(&buf[0]);
@@ -310,34 +304,32 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.size.z = decode_float(&buf[20]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 6;
+ }
} break;
case Variant::BASIS: {
-
ERR_FAIL_COND_V(len < 4 * 9, ERR_INVALID_DATA);
Basis val;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
-
val.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]);
}
}
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 9;
+ }
} break;
case Variant::TRANSFORM: {
-
ERR_FAIL_COND_V(len < 4 * 12, ERR_INVALID_DATA);
Transform val;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
-
val.basis.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]);
}
}
@@ -347,14 +339,14 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 12;
+ }
} break;
// misc types
case Variant::COLOR: {
-
ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
Color val;
val.r = decode_float(&buf[0]);
@@ -363,22 +355,22 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.a = decode_float(&buf[12]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 4;
+ }
} break;
case Variant::STRING_NAME: {
-
String str;
Error err = _decode_string(buf, len, r_len, str);
- if (err)
+ if (err) {
return err;
+ }
r_variant = StringName(str);
} break;
case Variant::NODE_PATH: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t strlen = decode_uint32(buf);
@@ -395,25 +387,28 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
len -= 12;
buf += 12;
- if (flags & 2) // Obsolete format with property separate from subpath
+ if (flags & 2) { // Obsolete format with property separate from subpath
subnamecount++;
+ }
uint32_t total = namecount + subnamecount;
- if (r_len)
+ if (r_len) {
(*r_len) += 12;
+ }
for (uint32_t i = 0; i < total; i++) {
-
String str;
Error err = _decode_string(buf, len, r_len, str);
- if (err)
+ if (err) {
return err;
+ }
- if (i < namecount)
+ if (i < namecount) {
names.push_back(str);
- else
+ } else {
subnames.push_back(str);
+ }
}
r_variant = NodePath(names, subnames, flags & 1);
@@ -426,17 +421,16 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::_RID: {
-
r_variant = RID();
} break;
case Variant::OBJECT: {
-
if (type & ENCODE_FLAG_OBJECT_AS_ID) {
//this _is_ allowed
ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA);
ObjectID val = ObjectID(decode_uint64(buf));
- if (r_len)
+ if (r_len) {
(*r_len) += 8;
+ }
if (val.is_null()) {
r_variant = (Object *)nullptr;
@@ -453,13 +447,13 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
String str;
Error err = _decode_string(buf, len, r_len, str);
- if (err)
+ if (err) {
return err;
+ }
if (str == String()) {
r_variant = (Object *)nullptr;
} else {
-
Object *obj = ClassDB::instance(str);
ERR_FAIL_COND_V(!obj, ERR_UNAVAILABLE);
@@ -473,17 +467,18 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
}
for (int i = 0; i < count; i++) {
-
str = String();
err = _decode_string(buf, len, r_len, str);
- if (err)
+ if (err) {
return err;
+ }
Variant value;
int used;
err = decode_variant(value, buf, len, &used, p_allow_objects);
- if (err)
+ if (err) {
return err;
+ }
buf += used;
len -= used;
@@ -505,16 +500,13 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::CALLABLE: {
-
r_variant = Callable();
} break;
case Variant::SIGNAL: {
-
r_variant = Signal();
} break;
case Variant::DICTIONARY: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
// bool shared = count&0x80000000;
@@ -530,7 +522,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
Dictionary d;
for (int i = 0; i < count; i++) {
-
Variant key, value;
int used;
@@ -559,7 +550,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::ARRAY: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
// bool shared = count&0x80000000;
@@ -575,7 +565,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
Array varr;
for (int i = 0; i < count; i++) {
-
int used = 0;
Variant v;
Error err = decode_variant(v, buf, len, &used, p_allow_objects);
@@ -594,7 +583,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
// arrays
case Variant::PACKED_BYTE_ARRAY: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
buf += 4;
@@ -607,7 +595,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
data.resize(count);
uint8_t *w = data.ptrw();
for (int32_t i = 0; i < count; i++) {
-
w[i] = buf[i];
}
}
@@ -615,14 +602,14 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
r_variant = data;
if (r_len) {
- if (count % 4)
+ if (count % 4) {
(*r_len) += 4 - count % 4;
+ }
(*r_len) += 4 + count;
}
} break;
case Variant::PACKED_INT32_ARRAY: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
buf += 4;
@@ -637,7 +624,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
data.resize(count);
int32_t *w = data.ptrw();
for (int32_t i = 0; i < count; i++) {
-
w[i] = decode_uint32(&buf[i * 4]);
}
}
@@ -648,7 +634,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::PACKED_INT64_ARRAY: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int64_t count = decode_uint64(buf);
buf += 4;
@@ -663,7 +648,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
data.resize(count);
int64_t *w = data.ptrw();
for (int64_t i = 0; i < count; i++) {
-
w[i] = decode_uint64(&buf[i * 8]);
}
}
@@ -674,7 +658,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::PACKED_FLOAT32_ARRAY: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
buf += 4;
@@ -689,7 +672,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
data.resize(count);
float *w = data.ptrw();
for (int32_t i = 0; i < count; i++) {
-
w[i] = decode_float(&buf[i * 4]);
}
}
@@ -701,7 +683,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::PACKED_FLOAT64_ARRAY: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int64_t count = decode_uint64(buf);
buf += 4;
@@ -716,7 +697,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
data.resize(count);
double *w = data.ptrw();
for (int64_t i = 0; i < count; i++) {
-
w[i] = decode_double(&buf[i * 8]);
}
}
@@ -728,7 +708,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::PACKED_STRING_ARRAY: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
@@ -736,16 +715,17 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
buf += 4;
len -= 4;
- if (r_len)
+ if (r_len) {
(*r_len) += 4;
+ }
//printf("string count: %i\n",count);
for (int32_t i = 0; i < count; i++) {
-
String str;
Error err = _decode_string(buf, len, r_len, str);
- if (err)
+ if (err) {
return err;
+ }
strings.push_back(str);
}
@@ -754,7 +734,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::PACKED_VECTOR2_ARRAY: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
buf += 4;
@@ -773,22 +752,21 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
Vector2 *w = varray.ptrw();
for (int32_t i = 0; i < count; i++) {
-
w[i].x = decode_float(buf + i * 4 * 2 + 4 * 0);
w[i].y = decode_float(buf + i * 4 * 2 + 4 * 1);
}
int adv = 4 * 2 * count;
- if (r_len)
+ if (r_len) {
(*r_len) += adv;
+ }
}
r_variant = varray;
} break;
case Variant::PACKED_VECTOR3_ARRAY: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
buf += 4;
@@ -808,7 +786,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
Vector3 *w = varray.ptrw();
for (int32_t i = 0; i < count; i++) {
-
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);
@@ -816,15 +793,15 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
int adv = 4 * 3 * count;
- if (r_len)
+ if (r_len) {
(*r_len) += adv;
+ }
}
r_variant = varray;
} break;
case Variant::PACKED_COLOR_ARRAY: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
buf += 4;
@@ -844,7 +821,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
Color *w = carray.ptrw();
for (int32_t i = 0; i < count; i++) {
-
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);
@@ -853,8 +829,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
int adv = 4 * 4 * count;
- if (r_len)
+ if (r_len) {
(*r_len) += adv;
+ }
}
r_variant = carray;
@@ -869,7 +846,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
}
static void _encode_string(const String &p_string, uint8_t *&buf, int &r_len) {
-
CharString utf8 = p_string.utf8();
if (buf) {
@@ -889,7 +865,6 @@ static void _encode_string(const String &p_string, uint8_t *&buf, int &r_len) {
}
Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bool p_full_objects) {
-
uint8_t *buf = r_buffer;
r_len = 0;
@@ -897,7 +872,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
uint32_t flags = 0;
switch (p_variant.get_type()) {
-
case Variant::INT: {
int64_t val = p_variant;
if (val > (int64_t)INT_MAX || val < (int64_t)INT_MIN) {
@@ -905,7 +879,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
}
} break;
case Variant::FLOAT: {
-
double d = p_variant;
float f = d;
if (double(f) != d) {
@@ -913,7 +886,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
}
} break;
case Variant::OBJECT: {
-
// Test for potential wrong values sent by the debugger when it breaks.
Object *obj = p_variant.get_validated_object();
if (!obj) {
@@ -940,13 +912,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4;
switch (p_variant.get_type()) {
-
case Variant::NIL: {
-
//nothing to do
} break;
case Variant::BOOL: {
-
if (buf) {
encode_uint32(p_variant.operator bool(), buf);
}
@@ -955,7 +924,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::INT: {
-
if (flags & ENCODE_FLAG_64) {
//64 bits
if (buf) {
@@ -972,7 +940,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
}
} break;
case Variant::FLOAT: {
-
if (flags & ENCODE_FLAG_64) {
if (buf) {
encode_double(p_variant.operator double(), buf);
@@ -981,7 +948,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 8;
} else {
-
if (buf) {
encode_float(p_variant.operator float(), buf);
}
@@ -991,14 +957,14 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::NODE_PATH: {
-
NodePath np = p_variant;
if (buf) {
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 np_flags = 0;
- if (np.is_absolute())
+ if (np.is_absolute()) {
np_flags |= 1;
+ }
encode_uint32(np_flags, buf + 8);
@@ -1010,20 +976,21 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
int total = np.get_name_count() + np.get_subname_count();
for (int i = 0; i < total; i++) {
-
String str;
- if (i < np.get_name_count())
+ if (i < np.get_name_count()) {
str = np.get_name(i);
- else
+ } else {
str = np.get_subname(i - np.get_name_count());
+ }
CharString utf8 = str.utf8();
int pad = 0;
- if (utf8.length() % 4)
+ if (utf8.length() % 4) {
pad = 4 - utf8.length() % 4;
+ }
if (buf) {
encode_uint32(utf8.length(), buf);
@@ -1037,19 +1004,16 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::STRING: {
-
_encode_string(p_variant, buf, r_len);
} break;
case Variant::STRING_NAME: {
-
_encode_string(p_variant, buf, r_len);
} break;
// math types
case Variant::VECTOR2: {
-
if (buf) {
Vector2 v2 = p_variant;
encode_float(v2.x, &buf[0]);
@@ -1060,7 +1024,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::VECTOR2I: {
-
if (buf) {
Vector2i v2 = p_variant;
encode_uint32(v2.x, &buf[0]);
@@ -1071,7 +1034,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::RECT2: {
-
if (buf) {
Rect2 r2 = p_variant;
encode_float(r2.position.x, &buf[0]);
@@ -1083,7 +1045,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::RECT2I: {
-
if (buf) {
Rect2i r2 = p_variant;
encode_uint32(r2.position.x, &buf[0]);
@@ -1095,7 +1056,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::VECTOR3: {
-
if (buf) {
Vector3 v3 = p_variant;
encode_float(v3.x, &buf[0]);
@@ -1107,7 +1067,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::VECTOR3I: {
-
if (buf) {
Vector3i v3 = p_variant;
encode_uint32(v3.x, &buf[0]);
@@ -1119,12 +1078,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::TRANSFORM2D: {
-
if (buf) {
Transform2D val = p_variant;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
-
copymem(&buf[(i * 2 + j) * 4], &val.elements[i][j], sizeof(float));
}
}
@@ -1134,7 +1091,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::PLANE: {
-
if (buf) {
Plane p = p_variant;
encode_float(p.normal.x, &buf[0]);
@@ -1147,7 +1103,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::QUAT: {
-
if (buf) {
Quat q = p_variant;
encode_float(q.x, &buf[0]);
@@ -1160,7 +1115,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::AABB: {
-
if (buf) {
AABB aabb = p_variant;
encode_float(aabb.position.x, &buf[0]);
@@ -1175,12 +1129,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::BASIS: {
-
if (buf) {
Basis val = p_variant;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
-
copymem(&buf[(i * 3 + j) * 4], &val.elements[i][j], sizeof(float));
}
}
@@ -1190,12 +1142,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::TRANSFORM: {
-
if (buf) {
Transform val = p_variant;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
-
copymem(&buf[(i * 3 + j) * 4], &val.basis.elements[i][j], sizeof(float));
}
}
@@ -1211,7 +1161,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
// misc types
case Variant::COLOR: {
-
if (buf) {
Color c = p_variant;
encode_float(c.r, &buf[0]);
@@ -1224,18 +1173,13 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::_RID: {
-
} break;
case Variant::CALLABLE: {
-
} break;
case Variant::SIGNAL: {
-
} break;
case Variant::OBJECT: {
-
if (p_full_objects) {
-
Object *obj = p_variant;
if (!obj) {
if (buf) {
@@ -1251,9 +1195,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
int pc = 0;
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
-
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
+ }
pc++;
}
@@ -1265,25 +1209,26 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4;
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
-
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
+ }
_encode_string(E->get().name, buf, r_len);
int len;
Error err = encode_variant(obj->get(E->get().name), buf, len, p_full_objects);
- if (err)
+ if (err) {
return err;
+ }
ERR_FAIL_COND_V(len % 4, ERR_BUG);
r_len += len;
- if (buf)
+ if (buf) {
buf += len;
+ }
}
}
} else {
if (buf) {
-
Object *obj = p_variant.get_validated_object();
ObjectID id;
if (obj) {
@@ -1298,7 +1243,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::DICTIONARY: {
-
Dictionary d = p_variant;
if (buf) {
@@ -1311,7 +1255,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
d.get_key_list(&keys);
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
-
/*
CharString utf8 = E->->utf8();
@@ -1329,20 +1272,21 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
encode_variant(E->get(), buf, len, p_full_objects);
ERR_FAIL_COND_V(len % 4, ERR_BUG);
r_len += len;
- if (buf)
+ if (buf) {
buf += len;
+ }
Variant *v = d.getptr(E->get());
ERR_FAIL_COND_V(!v, ERR_BUG);
encode_variant(*v, buf, len, p_full_objects);
ERR_FAIL_COND_V(len % 4, ERR_BUG);
r_len += len;
- if (buf)
+ if (buf) {
buf += len;
+ }
}
} break;
case Variant::ARRAY: {
-
Array v = p_variant;
if (buf) {
@@ -1353,19 +1297,18 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4;
for (int i = 0; i < v.size(); i++) {
-
int len;
encode_variant(v.get(i), buf, len, p_full_objects);
ERR_FAIL_COND_V(len % 4, ERR_BUG);
r_len += len;
- if (buf)
+ if (buf) {
buf += len;
+ }
}
} break;
// arrays
case Variant::PACKED_BYTE_ARRAY: {
-
Vector<uint8_t> data = p_variant;
int datalen = data.size();
int datasize = sizeof(uint8_t);
@@ -1381,13 +1324,13 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4 + datalen * datasize;
while (r_len % 4) {
r_len++;
- if (buf)
+ if (buf) {
*(buf++) = 0;
+ }
}
} break;
case Variant::PACKED_INT32_ARRAY: {
-
Vector<int32_t> data = p_variant;
int datalen = data.size();
int datasize = sizeof(int32_t);
@@ -1396,15 +1339,15 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
encode_uint32(datalen, buf);
buf += 4;
const int32_t *r = data.ptr();
- for (int32_t i = 0; i < datalen; i++)
+ for (int32_t i = 0; i < datalen; i++) {
encode_uint32(r[i], &buf[i * datasize]);
+ }
}
r_len += 4 + datalen * datasize;
} break;
case Variant::PACKED_INT64_ARRAY: {
-
Vector<int64_t> data = p_variant;
int datalen = data.size();
int datasize = sizeof(int64_t);
@@ -1413,15 +1356,15 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
encode_uint64(datalen, buf);
buf += 4;
const int64_t *r = data.ptr();
- for (int64_t i = 0; i < datalen; i++)
+ for (int64_t i = 0; i < datalen; i++) {
encode_uint64(r[i], &buf[i * datasize]);
+ }
}
r_len += 4 + datalen * datasize;
} break;
case Variant::PACKED_FLOAT32_ARRAY: {
-
Vector<float> data = p_variant;
int datalen = data.size();
int datasize = sizeof(float);
@@ -1430,15 +1373,15 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
encode_uint32(datalen, buf);
buf += 4;
const float *r = data.ptr();
- for (int i = 0; i < datalen; i++)
+ for (int i = 0; i < datalen; i++) {
encode_float(r[i], &buf[i * datasize]);
+ }
}
r_len += 4 + datalen * datasize;
} break;
case Variant::PACKED_FLOAT64_ARRAY: {
-
Vector<double> data = p_variant;
int datalen = data.size();
int datasize = sizeof(double);
@@ -1447,15 +1390,15 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
encode_uint32(datalen, buf);
buf += 4;
const double *r = data.ptr();
- for (int i = 0; i < datalen; i++)
+ for (int i = 0; i < datalen; i++) {
encode_double(r[i], &buf[i * datasize]);
+ }
}
r_len += 4 + datalen * datasize;
} break;
case Variant::PACKED_STRING_ARRAY: {
-
Vector<String> data = p_variant;
int len = data.size();
@@ -1467,7 +1410,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4;
for (int i = 0; i < len; i++) {
-
CharString utf8 = data.get(i).utf8();
if (buf) {
@@ -1480,14 +1422,14 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4 + utf8.length() + 1;
while (r_len % 4) {
r_len++; //pad
- if (buf)
+ if (buf) {
*(buf++) = 0;
+ }
}
}
} break;
case Variant::PACKED_VECTOR2_ARRAY: {
-
Vector<Vector2> data = p_variant;
int len = data.size();
@@ -1499,9 +1441,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4;
if (buf) {
-
for (int i = 0; i < len; i++) {
-
Vector2 v = data.get(i);
encode_float(v.x, &buf[0]);
@@ -1514,7 +1454,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::PACKED_VECTOR3_ARRAY: {
-
Vector<Vector3> data = p_variant;
int len = data.size();
@@ -1526,9 +1465,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4;
if (buf) {
-
for (int i = 0; i < len; i++) {
-
Vector3 v = data.get(i);
encode_float(v.x, &buf[0]);
@@ -1542,7 +1479,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::PACKED_COLOR_ARRAY: {
-
Vector<Color> data = p_variant;
int len = data.size();
@@ -1554,9 +1490,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4;
if (buf) {
-
for (int i = 0; i < len; i++) {
-
Color c = data.get(i);
encode_float(c.r, &buf[0]);