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());
43 if (
uid.size() % 2 != 0) {
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) {
76 size_t uid_length = context_name.size();
77 if (uid_length % 2 != 0) {
98 const size_t start_pos =
buffer.size();
104 const size_t length_pos =
buffer.size();
118 if (abs_length % 2 != 0) {
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();
161 const size_t length_pos =
buffer.size();
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();
203 const size_t length_pos =
buffer.size();
218 if (uid_length % 2 != 0) {
231 if (name_length % 2 != 0) {
249 size_t uid_len = role.sop_class_uid.size();
250 if (uid_len % 2 != 0) {
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));
302 std::vector<uint8_t>
buffer;
324 std::vector<uint8_t>
buffer;
355 std::vector<uint8_t>
buffer;
377 std::vector<uint8_t>
buffer;
395 std::vector<uint8_t>
buffer;
416 std::vector<uint8_t>
buffer;
433 static_cast<uint8_t
>(reason));
437 const std::vector<presentation_data_value>& pdvs) {
439 std::vector<uint8_t>
buffer;
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.