diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2019-03-28 09:40:31 +0100 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2019-03-28 10:43:34 +0100 |
commit | e61a074a8e7cc6f4a5435ca8e96a82e3fed917e6 (patch) | |
tree | 2b0c261740dba458a2d083dc362ac3c6b37f5c1b /core/io | |
parent | 174b19f768f50c7078ba49dcdf85d9d85ac4e875 (diff) |
Use same boolean for objects encode and decode.
In a very unintuitive move encode needed false to encode an object,
decode needed true to decode it.
They now need the same value: `true`.
Diffstat (limited to 'core/io')
-rw-r--r-- | core/io/marshalls.cpp | 41 | ||||
-rw-r--r-- | core/io/marshalls.h | 4 | ||||
-rw-r--r-- | core/io/packet_peer.cpp | 4 |
3 files changed, 24 insertions, 25 deletions
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index 5087a63b68..363460311c 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -794,7 +794,7 @@ 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_object_as_id) { +Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bool p_full_objects) { uint8_t *buf = r_buffer; @@ -819,7 +819,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } } break; case Variant::OBJECT: { - if (p_object_as_id) { + if (!p_full_objects) { flags |= ENCODE_FLAG_OBJECT_AS_ID; } } break; @@ -1086,22 +1086,8 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::OBJECT: { - if (p_object_as_id) { + if (p_full_objects) { - 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; - - } else { Object *obj = p_variant; if (!obj) { if (buf) { @@ -1139,7 +1125,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo _encode_string(E->get().name, buf, r_len); int len; - Error err = encode_variant(obj->get(E->get().name), buf, len, p_object_as_id); + Error err = encode_variant(obj->get(E->get().name), buf, len, p_full_objects); if (err) return err; ERR_FAIL_COND_V(len % 4, ERR_BUG); @@ -1148,6 +1134,19 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo buf += len; } } + } 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; } } break; @@ -1180,14 +1179,14 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len++; //pad */ int len; - encode_variant(E->get(), buf, len, p_object_as_id); + encode_variant(E->get(), buf, len, p_full_objects); ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; if (buf) buf += len; Variant *v = d.getptr(E->get()); ERR_FAIL_COND_V(!v, ERR_BUG); - encode_variant(*v, buf, len, p_object_as_id); + encode_variant(*v, buf, len, p_full_objects); ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; if (buf) @@ -1209,7 +1208,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo for (int i = 0; i < v.size(); i++) { int len; - encode_variant(v.get(i), buf, len, p_object_as_id); + encode_variant(v.get(i), buf, len, p_full_objects); ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; if (buf) diff --git a/core/io/marshalls.h b/core/io/marshalls.h index 11c4b2c98e..f361c29754 100644 --- a/core/io/marshalls.h +++ b/core/io/marshalls.h @@ -199,7 +199,7 @@ public: EncodedObjectAsID(); }; -Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len = NULL, bool p_allow_objects = true); -Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bool p_object_as_id = false); +Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len = NULL, bool p_allow_objects = false); +Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bool p_full_objects = false); #endif diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp index d7bfdbbb37..609a60c6ff 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -93,7 +93,7 @@ Error PacketPeer::get_var(Variant &r_variant) { Error PacketPeer::put_var(const Variant &p_packet) { int len; - Error err = encode_variant(p_packet, NULL, len, !allow_object_decoding); // compute len first + Error err = encode_variant(p_packet, NULL, len, allow_object_decoding); // compute len first if (err) return err; @@ -102,7 +102,7 @@ Error PacketPeer::put_var(const Variant &p_packet) { uint8_t *buf = (uint8_t *)alloca(len); ERR_FAIL_COND_V(!buf, ERR_OUT_OF_MEMORY); - err = encode_variant(p_packet, buf, len, !allow_object_decoding); + err = encode_variant(p_packet, buf, len, allow_object_decoding); ERR_FAIL_COND_V(err, err); return put_packet(buf, len); |