Fix wrong implementation about encoding & decoding bundle raw
[platform/core/base/bundle.git] / src / stub.cc
index 3efcf95..7bf991a 100644 (file)
@@ -350,12 +350,40 @@ extern "C" EXPORT_API bundle* bundle_decode(const bundle_raw* r,
 
 extern "C" EXPORT_API int bundle_encode_raw(bundle* b, bundle_raw** r,
     int* len) {
-  return bundle_encode(b, r, len);
+  if (b == nullptr || r == nullptr || len == nullptr)
+    return BUNDLE_ERROR_INVALID_PARAMETER;
+
+  auto* h = reinterpret_cast<Bundle*>(b);
+  try {
+    *r = reinterpret_cast<bundle_raw*>(h->EncodeRaw(len));
+  } catch (Exception& e) {
+    return e.GetErrorCode();
+  }
+  return BUNDLE_ERROR_NONE;
 }
 
 extern "C" EXPORT_API bundle* bundle_decode_raw(const bundle_raw* r,
     const int data_size) {
-  return bundle_decode(r, data_size);
+  if (r == nullptr) {
+    set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
+    return nullptr;
+  }
+
+  bundle* b = bundle_create();
+  if (b == nullptr)
+    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);
+    return nullptr;
+  }
+
+  set_last_result(BUNDLE_ERROR_NONE);
+  return b;
 }
 
 extern "C" EXPORT_API int bundle_get_type(bundle* b, const char* key) {