diff OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp @ 4508:8f9090b137f1

Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 11 Feb 2021 11:00:05 +0100
parents b4c58795f3a8
children a3c6678aa7b1
line wrap: on
line diff
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp	Thu Feb 11 09:33:48 2021 +0100
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp	Thu Feb 11 11:00:05 2021 +0100
@@ -191,19 +191,18 @@
         if (!content.empty())
         {
           LOG(INFO) << "Uploading DICOM file from ZIP archive: " << filename;
-          
-          DicomInstanceToStore toStore;
-          toStore.SetOrigin(DicomInstanceOrigin::FromRest(call));
-          toStore.SetBuffer(content.c_str(), content.size());
+
+          std::unique_ptr<DicomInstanceToStore> toStore(DicomInstanceToStore::CreateFromBuffer(content));
+          toStore->SetOrigin(DicomInstanceOrigin::FromRest(call));
 
           std::string publicId;
 
           try
           {
-            StoreStatus status = context.Store(publicId, toStore, StoreInstanceMode_Default);
+            StoreStatus status = context.Store(publicId, *toStore, StoreInstanceMode_Default);
 
             Json::Value info;
-            SetupResourceAnswer(info, toStore, status, publicId);
+            SetupResourceAnswer(info, *toStore, status, publicId);
             answer.append(info);
           }
           catch (OrthancException& e)
@@ -228,24 +227,25 @@
       // latter can possibly store a reference to the former (*)
       std::string dicom;
 
-      DicomInstanceToStore toStore;
-      toStore.SetOrigin(DicomInstanceOrigin::FromRest(call));
+      std::unique_ptr<DicomInstanceToStore> toStore;
 
       if (boost::iequals(call.GetHttpHeader("content-encoding", ""), "gzip"))
       {
         GzipCompressor compressor;
         compressor.Uncompress(dicom, call.GetBodyData(), call.GetBodySize());
-        toStore.SetBuffer(dicom.c_str(), dicom.size());  // (*)
+        toStore.reset(DicomInstanceToStore::CreateFromBuffer(dicom));  // (*)
       }
       else
       {
-        toStore.SetBuffer(call.GetBodyData(), call.GetBodySize());
+        toStore.reset(DicomInstanceToStore::CreateFromBuffer(call.GetBodyData(), call.GetBodySize()));
       }    
 
+      toStore->SetOrigin(DicomInstanceOrigin::FromRest(call));
+
       std::string publicId;
-      StoreStatus status = context.Store(publicId, toStore, StoreInstanceMode_Default);
+      StoreStatus status = context.Store(publicId, *toStore, StoreInstanceMode_Default);
 
-      OrthancRestApi::GetApi(call).AnswerStoredInstance(call, toStore, status, publicId);
+      OrthancRestApi::GetApi(call).AnswerStoredInstance(call, *toStore, status, publicId);
     }
   }