| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
#include "core/io/file_access.h" |
| 36 |
|
| 37 |
class PListNode; |
| 38 |
|
| 39 |
class PList : public RefCounted { |
| 40 |
GDSOFTCLASS(PList, RefCounted); |
| 41 |
|
| 42 |
friend class PListNode; |
| 43 |
|
| 44 |
public: |
| 45 |
enum PLNodeType { |
| 46 |
PL_NODE_TYPE_NIL, |
| 47 |
PL_NODE_TYPE_STRING, |
| 48 |
PL_NODE_TYPE_ARRAY, |
| 49 |
PL_NODE_TYPE_DICT, |
| 50 |
PL_NODE_TYPE_BOOLEAN, |
| 51 |
PL_NODE_TYPE_INTEGER, |
| 52 |
PL_NODE_TYPE_REAL, |
| 53 |
PL_NODE_TYPE_DATA, |
| 54 |
PL_NODE_TYPE_DATE, |
| 55 |
}; |
| 56 |
|
| 57 |
private: |
| 58 |
struct PListTrailer { |
| 59 |
uint8_t offset_size; |
| 60 |
uint8_t ref_size; |
| 61 |
uint64_t object_num; |
| 62 |
uint64_t root_offset_idx; |
| 63 |
uint64_t offset_table_start; |
| 64 |
}; |
| 65 |
|
| 66 |
PListTrailer trailer; |
| 67 |
Ref<PListNode> root; |
| 68 |
|
| 69 |
uint64_t read_bplist_var_size_int(Ref<FileAccess> p_file, uint8_t p_size); |
| 70 |
Ref<PListNode> read_bplist_obj(Ref<FileAccess> p_file, uint64_t p_offset_idx); |
| 71 |
|
| 72 |
public: |
| 73 |
PList(); |
| 74 |
PList(const String &p_string); |
| 75 |
|
| 76 |
bool load_file(const String &p_filename); |
| 77 |
bool load_string(const String &p_string, String &r_err_out); |
| 78 |
|
| 79 |
PackedByteArray save_asn1() const; |
| 80 |
String save_text() const; |
| 81 |
|
| 82 |
Ref<PListNode> get_root(); |
| 83 |
}; |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
class PListNode : public RefCounted { |
| 88 |
GDSOFTCLASS(PListNode, RefCounted); |
| 89 |
|
| 90 |
static int _asn1_size_len(uint8_t p_len_octets); |
| 91 |
|
| 92 |
public: |
| 93 |
PList::PLNodeType data_type = PList::PLNodeType::PL_NODE_TYPE_NIL; |
| 94 |
|
| 95 |
CharString data_string; |
| 96 |
Vector<Ref<PListNode>> data_array; |
| 97 |
HashMap<String, Ref<PListNode>> data_dict; |
| 98 |
union { |
| 99 |
int64_t data_int; |
| 100 |
bool data_bool; |
| 101 |
double data_real; |
| 102 |
}; |
| 103 |
|
| 104 |
PList::PLNodeType get_type() const; |
| 105 |
Variant get_value() const; |
| 106 |
|
| 107 |
static Ref<PListNode> new_node(const Variant &p_value); |
| 108 |
static Ref<PListNode> new_array(); |
| 109 |
static Ref<PListNode> new_dict(); |
| 110 |
static Ref<PListNode> new_string(const String &p_string); |
| 111 |
static Ref<PListNode> new_data(const String &p_string); |
| 112 |
static Ref<PListNode> new_date(const String &p_string); |
| 113 |
static Ref<PListNode> new_bool(bool p_bool); |
| 114 |
static Ref<PListNode> new_int(int64_t p_int); |
| 115 |
static Ref<PListNode> new_real(double p_real); |
| 116 |
|
| 117 |
bool push_subnode(const Ref<PListNode> &p_node, const String &p_key = ""); |
| 118 |
|
| 119 |
size_t get_asn1_size(uint8_t p_len_octets) const; |
| 120 |
|
| 121 |
void store_asn1_size(PackedByteArray &p_stream, uint8_t p_len_octets) const; |
| 122 |
bool store_asn1(PackedByteArray &p_stream, uint8_t p_len_octets) const; |
| 123 |
void store_text(String &p_stream, uint8_t p_indent) const; |
| 124 |
}; |