0 votes

What can put_var of PacketPeer (https://godot.readthedocs.io/en/latest/classes/class_packetpeer.html#class-packetpeer-put-var) 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).

in Engine by (239 points)

1 Answer

+1 vote

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
by (58 points)
edited by

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.

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

Yeah I had found the same. I updated the answer

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.