MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / decode_variant_2

Method decode_variant_2

compat/variant_decoder_compat.cpp:1156–1877  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1154}
1155
1156Error VariantDecoderCompat::decode_variant_2(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len, bool p_allow_objects) {
1157 const uint8_t *buf = p_buffer;
1158 int len = p_len;
1159
1160 ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
1161
1162 uint32_t type = decode_uint32(buf);
1163
1164 ERR_FAIL_COND_V((type & ENCODE_MASK) >= V2Type::VARIANT_MAX, ERR_INVALID_DATA);
1165
1166 buf += 4;
1167 len -= 4;
1168 if (r_len) {
1169 *r_len = 4;
1170 }
1171
1172 switch (type & ENCODE_MASK) {
1173 case V2Type::NIL: {
1174 r_variant = Variant();
1175 } break;
1176 case V2Type::BOOL: {
1177 ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
1178 bool val = decode_uint32(buf);
1179 r_variant = val;
1180 if (r_len) {
1181 (*r_len) += 4;
1182 }
1183 } break;
1184 case V2Type::INT: {
1185 if (type & ENCODE_FLAG_64) {
1186 ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA);
1187 int64_t val = decode_uint64(buf);
1188 r_variant = val;
1189 if (r_len) {
1190 (*r_len) += 8;
1191 }
1192
1193 } else {
1194 ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
1195 int32_t val = decode_uint32(buf);
1196 r_variant = val;
1197 if (r_len) {
1198 (*r_len) += 4;
1199 }
1200 }
1201
1202 } break;
1203 case V2Type::REAL: {
1204 if (type & ENCODE_FLAG_64) {
1205 ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA);
1206 double val = decode_double(buf);
1207 r_variant = val;
1208 if (r_len) {
1209 (*r_len) += 8;
1210 }
1211 } else {
1212 ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
1213 float val = decode_float(buf);

Callers

nothing calls this directly

Calls 7

_decode_stringFunction · 0.85
push_backMethod · 0.80
setMethod · 0.80
resizeMethod · 0.45
is_validMethod · 0.45
set_original_classMethod · 0.45
convertMethod · 0.45

Tested by

no test coverage detected