Bundle::Bundle() = default;
-Bundle::Bundle(unsigned char* raw, int size) {
- int ret = Decode(raw, size);
+Bundle::Bundle(unsigned char* raw, int size, bool base64) {
+ int ret;
+ if (base64)
+ ret = Decode(raw, size);
+ else
+ ret = DecodeRaw(raw, size);
if (ret != BUNDLE_ERROR_NONE)
THROW(ret);
}
};
Bundle();
- Bundle(unsigned char* raw, int size);
+ Bundle(unsigned char* raw, int size, bool base64 = true);
Bundle(int argc, char** argv);
virtual ~Bundle();
return nullptr;
}
- bundle* b = bundle_create();
- if (b == nullptr)
+ Bundle* b = nullptr;
+ try {
+ auto* raw = const_cast<bundle_raw*>(r);
+ b = new Bundle(static_cast<unsigned char*>(raw), data_size, false);
+ } catch (Exception& e) {
+ set_last_result(e.GetErrorCode());
return nullptr;
-
- auto* h = reinterpret_cast<Bundle*>(b);
- auto* raw = const_cast<bundle_raw*>(r);
- int ret = h->DecodeRaw(static_cast<unsigned char*>(raw), data_size);
- if (ret != BUNDLE_ERROR_NONE) {
- bundle_free(b);
- set_last_result(ret);
+ } catch (const std::bad_alloc& ba) {
+ set_last_result(BUNDLE_ERROR_OUT_OF_MEMORY);
return nullptr;
}
set_last_result(BUNDLE_ERROR_NONE);
- return b;
+ return reinterpret_cast<bundle*>(b);
}
extern "C" EXPORT_API int bundle_get_type(bundle* b, const char* key) {