Skip to content
0.2.0-dev Download ZIP
48 lines ·2.2 KB Raw
1<?xml version="1.0" encoding="UTF-8" ?>
2<class name="PackedDataContainer" inherits="Resource" api_type="core" deprecated="Use [method @GlobalScope.var_to_bytes] or [method FileAccess.store_var] instead. To enable data compression, use [method PackedByteArray.compress] or [method FileAccess.open_compressed]." xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3 <brief_description>
4 Efficiently packs and serializes [Array] or [Dictionary].
5 </brief_description>
6 <description>
7 [PackedDataContainer] can be used to efficiently store data from untyped containers. The data is packed into raw bytes and can be saved to file. Only [Array] and [Dictionary] can be stored this way.
8 You can retrieve the data by iterating on the container, which will work as if iterating on the packed data itself. If the packed container is a [Dictionary], the data can be retrieved by key names ([String]/[StringName] only).
9 [codeblock]
10 var data = { "key": "value", "another_key": 123, "lock": Vector2() }
11 var packed = PackedDataContainer.new()
12 packed.pack(data)
13 ResourceSaver.save(packed, "packed_data.res")
14 [/codeblock]
15 [codeblock]
16 var container = load("packed_data.res")
17 for key in container:
18 prints(key, container[key])
19 [/codeblock]
20 Prints:
21 [codeblock lang=text]
22 key value
23 lock (0, 0)
24 another_key 123
25 [/codeblock]
26 Nested containers will be packed recursively. While iterating, they will be returned as [PackedDataContainerRef].
27 </description>
28 <tutorials>
29 </tutorials>
30 <methods>
31 <method name="pack">
32 <return type="int" enum="Error" />
33 <returns_error number="0"/>
34 <returns_error number="30"/>
35 <param index="0" name="value" type="Variant" />
36 <description>
37 Packs the given container into a binary representation. The [param value] must be either [Array] or [Dictionary], any other type will result in invalid data error.
38 [b]Note:[/b] Subsequent calls to this method will overwrite the existing data.
39 </description>
40 </method>
41 <method name="size" qualifiers="const">
42 <return type="int" />
43 <description>
44 Returns the size of the packed container (see [method Array.size] and [method Dictionary.size]).
45 </description>
46 </method>
47 </methods>
48</class>