Fix wrong implementation about encoding & decoding bundle raw
[platform/core/base/bundle.git] / src / bundle_cpp.cc
index f23f4d6..341dfce 100644 (file)
@@ -38,9 +38,12 @@ Bundle::Bundle()
     throw std::bad_alloc();
 }
 
-Bundle::Bundle(BundleRaw raw)
+Bundle::Bundle(BundleRaw raw, bool base64)
   : impl_(new Impl(this)) {
-  impl_->handle_ = bundle_decode(raw.first.get(), raw.second);
+  if (base64)
+    impl_->handle_ = bundle_decode(raw.first.get(), raw.second);
+  else
+    impl_->handle_ = bundle_decode_raw(raw.first.get(), raw.second);
   if (impl_->handle_ == nullptr)
     throw std::bad_alloc();
 }
@@ -257,10 +260,14 @@ std::vector<unsigned char> Bundle::GetByte(const std::string& key) const {
   return std::vector<unsigned char>(bytes, bytes + size);
 }
 
-Bundle::BundleRaw Bundle::ToRaw() {
+Bundle::BundleRaw Bundle::ToRaw(bool base64) {
   bundle_raw* raw = nullptr;
   int len = 0;
-  int ret = bundle_encode(impl_->handle_, &raw, &len);
+  int ret;
+  if (base64)
+    ret = bundle_encode(impl_->handle_, &raw, &len);
+  else
+    ret = bundle_encode_raw(impl_->handle_, &raw, &len);
   if (raw == nullptr) {
     LOGE("Fail to encode data (%d)", ret);
     throw std::bad_alloc();