Exemplo n.º 1
0
 /// <summary>
 /// Decodes a byte array back to a <c>Variant</c> value.
 /// If <paramref name="allowObjects"/> is <see langword="true"/> decoding objects is allowed.
 ///
 /// WARNING: Deserialized object can contain code which gets executed.
 /// Do not set <paramref name="allowObjects"/> to <see langword="true"/>
 /// if the serialized object comes from untrusted sources to avoid
 /// potential security threats (remote code execution).
 /// </summary>
 /// <param name="bytes">Byte array that will be decoded to a <c>Variant</c>.</param>
 /// <param name="allowObjects">If objects should be decoded.</param>
 /// <returns>The decoded <c>Variant</c>.</returns>
 public static Variant BytesToVar(Span <byte> bytes, bool allowObjects = false)
 {
     using var varBytes = Marshaling.ConvertSystemArrayToNativePackedByteArray(bytes);
     NativeFuncs.godotsharp_bytes_to_var(varBytes, allowObjects.ToGodotBool(), out godot_variant ret);
     return(Variant.CreateTakingOwnershipOfDisposableValue(ret));
 }