17 buffer.push_back(
static_cast<uint8_t
>((value >> 8) & 0xFF));
18 buffer.push_back(
static_cast<uint8_t
>(value & 0xFF));
22 buffer.push_back(
static_cast<uint8_t
>((value >> 24) & 0xFF));
23 buffer.push_back(
static_cast<uint8_t
>((value >> 16) & 0xFF));
24 buffer.push_back(
static_cast<uint8_t
>((value >> 8) & 0xFF));
25 buffer.push_back(
static_cast<uint8_t
>(value & 0xFF));
29 const std::string& ae_title) {
31 std::string padded = ae_title;
37 buffer.insert(buffer.end(), padded.begin(), padded.end());
41 buffer.insert(buffer.end(),
uid.begin(),
uid.end());
43 if (
uid.size() % 2 != 0) {
44 buffer.push_back(0x00);
49 if (buffer.size() < 6) {
53 const uint32_t length =
static_cast<uint32_t
>(buffer.size() - 6);
54 buffer[2] =
static_cast<uint8_t
>((length >> 24) & 0xFF);
55 buffer[3] =
static_cast<uint8_t
>((length >> 16) & 0xFF);
56 buffer[4] =
static_cast<uint8_t
>((length >> 8) & 0xFF);
57 buffer[5] =
static_cast<uint8_t
>(length & 0xFF);
65 const std::string& context_name) {
73 buffer.push_back(0x00);
76 size_t uid_length = context_name.size();
77 if (uid_length % 2 != 0) {
98 const size_t start_pos = buffer.size();
101 buffer.push_back(0x00);
104 const size_t length_pos = buffer.size();
108 buffer.push_back(pc.
id);
109 buffer.push_back(0x00);
110 buffer.push_back(0x00);
111 buffer.push_back(0x00);
115 buffer.push_back(0x00);
118 if (abs_length % 2 != 0) {
127 buffer.push_back(0x00);
129 size_t ts_length =
ts.size();
130 if (ts_length % 2 != 0) {
138 const uint16_t item_length =
static_cast<uint16_t
>(buffer.size() - start_pos - 4);
139 buffer[length_pos] =
static_cast<uint8_t
>((item_length >> 8) & 0xFF);
140 buffer[length_pos + 1] =
static_cast<uint8_t
>(item_length & 0xFF);
155 const size_t start_pos = buffer.size();
158 buffer.push_back(0x00);
161 const size_t length_pos = buffer.size();
164 buffer.push_back(pc.
id);
165 buffer.push_back(0x00);
166 buffer.push_back(
static_cast<uint8_t
>(pc.
result));
167 buffer.push_back(0x00);
173 buffer.push_back(0x00);
176 if (ts_length % 2 != 0) {
184 const uint16_t item_length =
static_cast<uint16_t
>(buffer.size() - start_pos - 4);
185 buffer[length_pos] =
static_cast<uint8_t
>((item_length >> 8) & 0xFF);
186 buffer[length_pos + 1] =
static_cast<uint8_t
>(item_length & 0xFF);
197 const size_t start_pos = buffer.size();
200 buffer.push_back(0x00);
203 const size_t length_pos = buffer.size();
208 buffer.push_back(0x00);
215 buffer.push_back(0x00);
218 if (uid_length % 2 != 0) {
228 buffer.push_back(0x00);
231 if (name_length % 2 != 0) {
236 buffer.insert(buffer.end(),
240 buffer.push_back(
' ');
247 buffer.push_back(0x00);
249 size_t uid_len = role.sop_class_uid.size();
250 if (uid_len % 2 != 0) {
257 write_uint16_be(buffer,
static_cast<uint16_t
>(role.sop_class_uid.size()));
260 buffer.push_back(role.scu_role ? 0x01 : 0x00);
261 buffer.push_back(role.scp_role ? 0x01 : 0x00);
265 const uint16_t item_length =
static_cast<uint16_t
>(buffer.size() - start_pos - 4);
266 buffer[length_pos] =
static_cast<uint8_t
>((item_length >> 8) & 0xFF);
267 buffer[length_pos + 1] =
static_cast<uint8_t
>(item_length & 0xFF);
272 const std::string& called_ae,
273 const std::string& calling_ae) {
275 buffer.push_back(
static_cast<uint8_t
>(type));
276 buffer.push_back(0x00);
294 buffer.insert(buffer.end(), 32, 0x00);
302 std::vector<uint8_t> buffer;
324 std::vector<uint8_t> buffer;
355 std::vector<uint8_t> buffer;
359 buffer.push_back(0x00);
362 buffer.push_back(0x00);
363 buffer.push_back(
static_cast<uint8_t
>(rj.
result));
364 buffer.push_back(rj.
source);
365 buffer.push_back(rj.
reason);
377 std::vector<uint8_t> buffer;
381 buffer.push_back(0x00);
395 std::vector<uint8_t> buffer;
399 buffer.push_back(0x00);
416 std::vector<uint8_t> buffer;
420 buffer.push_back(0x00);
422 buffer.push_back(0x00);
423 buffer.push_back(0x00);
424 buffer.push_back(source);
425 buffer.push_back(reason);
433 static_cast<uint8_t
>(reason));
437 const std::vector<presentation_data_value>& pdvs) {
439 std::vector<uint8_t> buffer;
444 buffer.push_back(0x00);
450 for (
const auto& pdv : pdvs) {
457 const uint32_t pdv_length =
static_cast<uint32_t
>(2 + pdv.data.size());
460 buffer.push_back(pdv.context_id);
466 if (pdv.is_command) {
472 buffer.push_back(control);
474 buffer.insert(buffer.end(), pdv.data.begin(), pdv.data.end());
static void write_uint32_be(std::vector< uint8_t > &buffer, uint32_t value)
Writes a 32-bit unsigned integer in big-endian format.
static std::vector< uint8_t > encode_associate_rq(const associate_rq &rq)
Encodes an A-ASSOCIATE-RQ PDU.
static std::vector< uint8_t > encode_release_rp()
Encodes an A-RELEASE-RP PDU.
static void encode_associate_header(std::vector< uint8_t > &buffer, pdu_type type, const std::string &called_ae, const std::string &calling_ae)
Encodes the common header portion for ASSOCIATE-RQ/AC PDUs.
static std::vector< uint8_t > encode_p_data_tf(const std::vector< presentation_data_value > &pdvs)
Encodes a P-DATA-TF PDU.
static void encode_user_information(std::vector< uint8_t > &buffer, const user_information &user_info)
Encodes a User Information item.
static std::vector< uint8_t > encode_associate_ac(const associate_ac &ac)
Encodes an A-ASSOCIATE-AC PDU.
static void encode_presentation_context_rq(std::vector< uint8_t > &buffer, const presentation_context_rq &pc)
Encodes a Presentation Context item for A-ASSOCIATE-RQ.
static void update_pdu_length(std::vector< uint8_t > &buffer)
Updates the PDU length field at position 2-5.
static void encode_presentation_context_ac(std::vector< uint8_t > &buffer, const presentation_context_ac &pc)
Encodes a Presentation Context item for A-ASSOCIATE-AC.
static void write_ae_title(std::vector< uint8_t > &buffer, const std::string &ae_title)
Writes an AE Title (16 bytes, space-padded).
static std::vector< uint8_t > encode_associate_rj(const associate_rj &rj)
Encodes an A-ASSOCIATE-RJ PDU.
static std::vector< uint8_t > encode_release_rq()
Encodes an A-RELEASE-RQ PDU.
static std::vector< uint8_t > encode_abort(uint8_t source, uint8_t reason)
Encodes an A-ABORT PDU.
static void write_uint16_be(std::vector< uint8_t > &buffer, uint16_t value)
Writes a 16-bit unsigned integer in big-endian format.
static void write_uid(std::vector< uint8_t > &buffer, const std::string &uid)
Writes a UID string.
static void encode_application_context(std::vector< uint8_t > &buffer, const std::string &context_name)
Encodes an Application Context item.
pdu_type
PDU (Protocol Data Unit) types as defined in DICOM PS3.8.
@ associate_rj
A-ASSOCIATE-RJ (Association Reject)
@ associate_ac
A-ASSOCIATE-AC (Association Accept)
@ p_data_tf
P-DATA-TF (Data Transfer)
@ release_rq
A-RELEASE-RQ (Release Request)
@ release_rp
A-RELEASE-RP (Release Response)
@ associate_rq
A-ASSOCIATE-RQ (Association Request)
@ maximum_length
Maximum Length Sub-item.
@ transfer_syntax
Transfer Syntax Sub-item.
@ presentation_context_rq
Presentation Context Item (RQ)
@ presentation_context_ac
Presentation Context Item (AC)
@ scp_scu_role_selection
SCP/SCU Role Selection Sub-item.
@ implementation_class_uid
Implementation Class UID Sub-item.
@ abstract_syntax
Abstract Syntax Sub-item.
@ implementation_version_name
Implementation Version Name Sub-item.
@ application_context
Application Context Item.
@ user_information
User Information Item.
constexpr uint16_t DICOM_PROTOCOL_VERSION
DICOM Protocol Version.
constexpr const char * DICOM_APPLICATION_CONTEXT
Default DICOM Application Context Name (PS3.7)
abort_reason
Abort reason values when source is service-provider.
constexpr size_t AE_TITLE_LENGTH
AE Title length (fixed 16 characters, space-padded)
abort_source
Abort source values.
std::string calling_ae_title
Calling AE Title (16 chars max)
user_information user_info
User Information.
std::string called_ae_title
Called AE Title (16 chars max)
std::string application_context
Application Context Name UID.
std::vector< presentation_context_ac > presentation_contexts
Presentation Contexts.
uint8_t reason
Reason/Diagnostic.
reject_result result
Result (1=permanent, 2=transient)
std::string called_ae_title
Called AE Title (16 chars max)
std::string application_context
Application Context Name UID.
user_information user_info
User Information.
std::string calling_ae_title
Calling AE Title (16 chars max)
std::vector< presentation_context_rq > presentation_contexts
Presentation Contexts.
Presentation Context for A-ASSOCIATE-AC.
presentation_context_result result
Result/Reason.
uint8_t id
Presentation Context ID.
std::string transfer_syntax
Accepted Transfer Syntax UID.
Presentation Context for A-ASSOCIATE-RQ.
uint8_t id
Presentation Context ID (odd number 1-255)
std::string abstract_syntax
Abstract Syntax UID (SOP Class)
std::vector< std::string > transfer_syntaxes
Proposed Transfer Syntaxes.
Presentation Data Value (PDV) item for P-DATA-TF.