What can put_var of PacketPeer serialize? What are valid arguments for RPCs?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By raymoo
:warning: Old Version Published before Godot 3 was released.

What can put_var of PacketPeer (PacketPeer — Godot Engine (latest) documentation in English) serialize? Will it do a deep copy of nested objects?

I am guessing that RPC arguments have the same restrictions as put_var, but if not, what can RPC arguments be?

One thing that might make sense not to be serializable is an object with cyclical references. But you could serialize even those if you choose a suitable representation for object cycles (I think Scheme supports this for serialization).

:bust_in_silhouette: Reply From: quinno

Having a quick look at the source code for the function, you can see that it takes a Variant type. This is basically all the base types in Godot (including the containers). The containers are handled recursively (“deep copy”). There doesn’t look to be any system to handle cyclic references. RPC does appear to be the same.

The Variant is ultimately processed by the encode_variant function in marshalls.cpp if you’re curious: https://github.com/godotengine/godot/blob/master/core/io/marshalls.cpp#L694

Here’s the full list (taken from variant.h: https://github.com/godotengine/godot/blob/master/core/variant.h#L75)

NIL,

// atomic types
BOOL,
INT,
REAL,
STRING,

// math types
VECTOR2, // 5
RECT2,
VECTOR3,
TRANSFORM2D,
PLANE,
QUAT, // 10
RECT3,
BASIS,
TRANSFORM,

// misc types
COLOR,
NODE_PATH, // 15
_RID,
OBJECT,
DICTIONARY,
ARRAY, // 20

// arrays
POOL_BYTE_ARRAY,
POOL_INT_ARRAY,
POOL_REAL_ARRAY,
POOL_STRING_ARRAY,
POOL_VECTOR2_ARRAY, // 25
POOL_VECTOR3_ARRAY,
POOL_COLOR_ARRAY

Thank you, but does not fully answer the question since you didn’t say whether the encoding is a deep copy. I will look at marshalls.cpp and try to figure it out there, though.

raymoo | 2017-06-08 13:05

Looks like it does do a deep copy, and that there is no cycle checking.

raymoo | 2017-06-08 13:11

Yeah I had found the same. I updated the answer

quinno | 2017-06-08 13:16