comparison Framework/DicomInstanceInfo.cpp @ 0:95226b754d9e

initial release
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 17 Sep 2018 11:34:55 +0200
parents
children 7e207ade2f1a
comparison
equal deleted inserted replaced
-1:000000000000 0:95226b754d9e
1 /**
2 * Transfers accelerator plugin for Orthanc
3 * Copyright (C) 2018 Osimis, Belgium
4 *
5 * This program is free software: you can redistribute it and/or
6 * modify it under the terms of the GNU Affero General Public License
7 * as published by the Free Software Foundation, either version 3 of
8 * the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 **/
18
19
20 #include "DicomInstanceInfo.h"
21
22 #include <Core/OrthancException.h>
23 #include <Core/Toolbox.h>
24 #include <Plugins/Samples/Common/OrthancPluginCppWrapper.h>
25
26 static const char *KEY_ID = "ID";
27 static const char *KEY_MD5 = "MD5";
28 static const char *KEY_SIZE = "Size";
29
30
31 namespace OrthancPlugins
32 {
33 DicomInstanceInfo::DicomInstanceInfo(const std::string& id,
34 const MemoryBuffer& buffer) :
35 id_(id),
36 size_(buffer.GetSize())
37 {
38 Orthanc::Toolbox::ComputeMD5(md5_, buffer.GetData(), buffer.GetSize());
39 }
40
41
42 DicomInstanceInfo::DicomInstanceInfo(const std::string& id,
43 size_t size,
44 const std::string& md5) :
45 id_(id),
46 size_(size),
47 md5_(md5)
48 {
49 }
50
51
52 DicomInstanceInfo::DicomInstanceInfo(const Json::Value& serialized)
53 {
54 if (serialized.type() != Json::objectValue ||
55 !serialized.isMember(KEY_ID) ||
56 !serialized.isMember(KEY_SIZE) ||
57 !serialized.isMember(KEY_MD5) ||
58 serialized[KEY_ID].type() != Json::stringValue ||
59 serialized[KEY_SIZE].type() != Json::stringValue ||
60 serialized[KEY_MD5].type() != Json::stringValue)
61 {
62 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
63 }
64 else
65 {
66 id_ = serialized[KEY_ID].asString();
67 md5_ = serialized[KEY_MD5].asString();
68
69 try
70 {
71 size_ = boost::lexical_cast<size_t>(serialized[KEY_SIZE].asString());
72 }
73 catch (boost::bad_lexical_cast&)
74 {
75 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
76 }
77 }
78 }
79
80
81 void DicomInstanceInfo::Serialize(Json::Value& target) const
82 {
83 target = Json::objectValue;
84 target[KEY_ID] = id_;
85 target[KEY_SIZE] = boost::lexical_cast<std::string>(size_);
86 target[KEY_MD5] = md5_;
87 }
88 }