class_packeddatacontainer.rst 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/PackedDataContainer.xml.
  6. .. _class_PackedDataContainer:
  7. PackedDataContainer
  8. ===================
  9. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. Efficiently packs and serializes :ref:`Array<class_Array>` or :ref:`Dictionary<class_Dictionary>`.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. **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 :ref:`Array<class_Array>` and :ref:`Dictionary<class_Dictionary>` can be stored this way.
  15. 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 :ref:`Dictionary<class_Dictionary>`, the data can be retrieved by key names (:ref:`String<class_String>`/:ref:`StringName<class_StringName>` only).
  16. ::
  17. var data = { "key": "value", "another_key": 123, "lock": Vector2() }
  18. var packed = PackedDataContainer.new()
  19. packed.pack(data)
  20. ResourceSaver.save(packed, "packed_data.res")
  21. ::
  22. var container = load("packed_data.res")
  23. for key in container:
  24. prints(key, container[key])
  25. Prints:
  26. .. code:: text
  27. key value
  28. lock (0, 0)
  29. another_key 123
  30. Nested containers will be packed recursively. While iterating, they will be returned as :ref:`PackedDataContainerRef<class_PackedDataContainerRef>`.
  31. .. rst-class:: classref-reftable-group
  32. Methods
  33. -------
  34. .. table::
  35. :widths: auto
  36. +---------------------------------------+-------------------------------------------------------------------------------------------------+
  37. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`pack<class_PackedDataContainer_method_pack>`\ (\ value\: :ref:`Variant<class_Variant>`\ ) |
  38. +---------------------------------------+-------------------------------------------------------------------------------------------------+
  39. | :ref:`int<class_int>` | :ref:`size<class_PackedDataContainer_method_size>`\ (\ ) |const| |
  40. +---------------------------------------+-------------------------------------------------------------------------------------------------+
  41. .. rst-class:: classref-section-separator
  42. ----
  43. .. rst-class:: classref-descriptions-group
  44. Method Descriptions
  45. -------------------
  46. .. _class_PackedDataContainer_method_pack:
  47. .. rst-class:: classref-method
  48. :ref:`Error<enum_@GlobalScope_Error>` **pack**\ (\ value\: :ref:`Variant<class_Variant>`\ ) :ref:`🔗<class_PackedDataContainer_method_pack>`
  49. Packs the given container into a binary representation. The ``value`` must be either :ref:`Array<class_Array>` or :ref:`Dictionary<class_Dictionary>`, any other type will result in invalid data error.
  50. \ **Note:** Subsequent calls to this method will overwrite the existing data.
  51. .. rst-class:: classref-item-separator
  52. ----
  53. .. _class_PackedDataContainer_method_size:
  54. .. rst-class:: classref-method
  55. :ref:`int<class_int>` **size**\ (\ ) |const| :ref:`🔗<class_PackedDataContainer_method_size>`
  56. Returns the size of the packed container (see :ref:`Array.size<class_Array_method_size>` and :ref:`Dictionary.size<class_Dictionary_method_size>`).
  57. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  58. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  59. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  60. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  61. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  62. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  63. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  64. .. |void| replace:: :abbr:`void (No return value.)`