Mercurial > hg > orthanc-transfers
annotate Framework/DicomInstanceInfo.cpp @ 78:0898578d5708 OrthancTransfers-1.3 tip
closing OrthancTransfers-1.3
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 30 May 2024 22:45:33 +0200 |
parents | 44a0430d7899 |
children | 1e396fb509ca |
rev | line source |
---|---|
0 | 1 /** |
2 * Transfers accelerator plugin for Orthanc | |
33
44a0430d7899
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
3 * Copyright (C) 2018-2021 Osimis S.A., Belgium |
0 | 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 | 22 #include "../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h" |
23 | |
20 | 24 #include <OrthancException.h> |
25 #include <Toolbox.h> | |
0 | 26 |
27 static const char *KEY_ID = "ID"; | |
28 static const char *KEY_MD5 = "MD5"; | |
29 static const char *KEY_SIZE = "Size"; | |
30 | |
31 | |
32 namespace OrthancPlugins | |
33 { | |
34 DicomInstanceInfo::DicomInstanceInfo(const std::string& id, | |
35 const MemoryBuffer& buffer) : | |
36 id_(id), | |
37 size_(buffer.GetSize()) | |
38 { | |
39 Orthanc::Toolbox::ComputeMD5(md5_, buffer.GetData(), buffer.GetSize()); | |
40 } | |
41 | |
42 | |
43 DicomInstanceInfo::DicomInstanceInfo(const std::string& id, | |
44 size_t size, | |
45 const std::string& md5) : | |
46 id_(id), | |
47 size_(size), | |
48 md5_(md5) | |
49 { | |
50 } | |
51 | |
52 | |
53 DicomInstanceInfo::DicomInstanceInfo(const Json::Value& serialized) | |
54 { | |
55 if (serialized.type() != Json::objectValue || | |
56 !serialized.isMember(KEY_ID) || | |
57 !serialized.isMember(KEY_SIZE) || | |
58 !serialized.isMember(KEY_MD5) || | |
59 serialized[KEY_ID].type() != Json::stringValue || | |
60 serialized[KEY_SIZE].type() != Json::stringValue || | |
61 serialized[KEY_MD5].type() != Json::stringValue) | |
62 { | |
63 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
64 } | |
65 else | |
66 { | |
67 id_ = serialized[KEY_ID].asString(); | |
68 md5_ = serialized[KEY_MD5].asString(); | |
69 | |
70 try | |
71 { | |
72 size_ = boost::lexical_cast<size_t>(serialized[KEY_SIZE].asString()); | |
73 } | |
74 catch (boost::bad_lexical_cast&) | |
75 { | |
76 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
77 } | |
78 } | |
79 } | |
80 | |
81 | |
82 void DicomInstanceInfo::Serialize(Json::Value& target) const | |
83 { | |
84 target = Json::objectValue; | |
85 target[KEY_ID] = id_; | |
86 target[KEY_SIZE] = boost::lexical_cast<std::string>(size_); | |
87 target[KEY_MD5] = md5_; | |
88 } | |
89 } |