/**************************************************************************/1/* packed_data_container.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "core/io/resource.h"3334class PackedDataContainer : public Resource {35GDCLASS(PackedDataContainer, Resource);3637enum : uint32_t {38TYPE_DICT = 0xFFFFFFFF,39TYPE_ARRAY = 0xFFFFFFFE,40};4142struct DictKey {43uint32_t hash;44Variant key;45bool operator<(const DictKey &p_key) const { return hash < p_key.hash; }46};4748Vector<uint8_t> data;49int datalen = 0;5051uint32_t _pack(const Variant &p_data, Vector<uint8_t> &tmpdata, HashMap<String, uint32_t> &string_cache);5253Variant _iter_init_ofs(const Array &p_iter, uint32_t p_offset);54Variant _iter_next_ofs(const Array &p_iter, uint32_t p_offset);55Variant _iter_get_ofs(const Variant &p_iter, uint32_t p_offset);5657Variant _iter_init(const Array &p_iter);58Variant _iter_next(const Array &p_iter);59Variant _iter_get(const Variant &p_iter);6061friend class PackedDataContainerRef;62Variant _key_at_ofs(uint32_t p_ofs, const Variant &p_key, bool &err) const;63Variant _get_at_ofs(uint32_t p_ofs, const uint8_t *p_buf, bool &err) const;64uint32_t _type_at_ofs(uint32_t p_ofs) const;65int _size(uint32_t p_ofs) const;6667protected:68void _set_data(const Vector<uint8_t> &p_data);69Vector<uint8_t> _get_data() const;70static void _bind_methods();7172public:73virtual Variant getvar(const Variant &p_key, bool *r_valid = nullptr) const override;74Error pack(const Variant &p_data);7576int size() const;7778PackedDataContainer() {}79};8081class PackedDataContainerRef : public RefCounted {82GDCLASS(PackedDataContainerRef, RefCounted);8384friend class PackedDataContainer;85uint32_t offset = 0;86Ref<PackedDataContainer> from;8788protected:89static void _bind_methods();9091public:92Variant _iter_init(const Array &p_iter);93Variant _iter_next(const Array &p_iter);94Variant _iter_get(const Variant &p_iter);9596int size() const;97virtual Variant getvar(const Variant &p_key, bool *r_valid = nullptr) const override;9899PackedDataContainerRef() {}100};101102103