11#ifndef PACS_NETWORK_PDU_DECODER_HPP
12#define PACS_NETWORK_PDU_DECODER_HPP
52 std::vector<presentation_data_value>
pdvs;
56 :
pdvs(std::move(values)) {}
62using pdu = std::variant<
99 default:
return "Unknown error";
151 [[nodiscard]]
static std::optional<size_t>
pdu_length(
152 std::span<const uint8_t> data);
160 std::span<const uint8_t> data);
173 std::span<const uint8_t> data);
181 std::span<const uint8_t> data);
189 std::span<const uint8_t> data);
197 std::span<const uint8_t> data);
205 std::span<const uint8_t> data);
213 std::span<const uint8_t> data);
221 std::span<const uint8_t> data);
233 std::span<const uint8_t> data,
size_t offset);
239 std::span<const uint8_t> data,
size_t offset);
245 std::span<const uint8_t> data,
size_t offset);
250 [[nodiscard]]
static std::string
read_uid(
251 std::span<const uint8_t> data,
size_t offset,
size_t length);
260 std::span<const uint8_t> data, uint8_t expected_type = 0);
267 std::vector<presentation_context_rq>,
268 std::vector<presentation_context_ac>,
276 std::span<const uint8_t> data);
Decoder for DICOM PDU (Protocol Data Unit) messages.
static DecodeResult< std::tuple< std::string, std::vector< presentation_context_rq >, std::vector< presentation_context_ac >, user_information > > decode_variable_items(std::span< const uint8_t > data, bool is_rq)
Decode variable items from ASSOCIATE-RQ/AC PDUs.
static DecodeResult< user_information > decode_user_info_item(std::span< const uint8_t > data)
Decode User Information sub-items.
static DecodeResult< associate_ac > decode_associate_ac(std::span< const uint8_t > data)
Decode an A-ASSOCIATE-AC PDU.
static DecodeResult< associate_rq > decode_associate_rq(std::span< const uint8_t > data)
Decode an A-ASSOCIATE-RQ PDU.
static DecodeResult< release_rp_pdu > decode_release_rp(std::span< const uint8_t > data)
Decode an A-RELEASE-RP PDU.
static DecodeResult< pdu > decode(std::span< const uint8_t > data)
Decode any PDU from bytes.
static uint16_t read_uint16_be(std::span< const uint8_t > data, size_t offset)
Read a 16-bit unsigned integer in big-endian format.
static std::string read_ae_title(std::span< const uint8_t > data, size_t offset)
Read an AE Title (16 bytes, space-trimmed).
static DecodeResult< abort_pdu > decode_abort(std::span< const uint8_t > data)
Decode an A-ABORT PDU.
static uint32_t read_uint32_be(std::span< const uint8_t > data, size_t offset)
Read a 32-bit unsigned integer in big-endian format.
static std::string read_uid(std::span< const uint8_t > data, size_t offset, size_t length)
Read a UID string (trim trailing null/space padding).
static DecodeResult< uint32_t > validate_pdu_header(std::span< const uint8_t > data, uint8_t expected_type=0)
Validate PDU header and extract length.
static DecodeResult< release_rq_pdu > decode_release_rq(std::span< const uint8_t > data)
Decode an A-RELEASE-RQ PDU.
static DecodeResult< associate_rj > decode_associate_rj(std::span< const uint8_t > data)
Decode an A-ASSOCIATE-RJ PDU.
static std::optional< size_t > pdu_length(std::span< const uint8_t > data)
Check if a complete PDU is available in the buffer.
static std::optional< pdu_type > peek_pdu_type(std::span< const uint8_t > data)
Get the PDU type from buffer without full decoding.
static DecodeResult< p_data_tf_pdu > decode_p_data_tf(std::span< const uint8_t > data)
Decode a P-DATA-TF PDU.
@ associate_rj
A-ASSOCIATE-RJ (Association Reject)
@ associate_ac
A-ASSOCIATE-AC (Association Accept)
@ associate_rq
A-ASSOCIATE-RQ (Association Request)
abort_reason
Abort reason values when source is service-provider.
@ not_specified
Reason not specified.
std::variant< associate_rq, associate_ac, associate_rj, p_data_tf_pdu, release_rq_pdu, release_rp_pdu, abort_pdu > pdu
Variant type that can hold any PDU.
constexpr const char * to_string(association_state state) noexcept
Convert association_state to string representation.
abort_source
Abort source values.
@ service_user
DICOM UL service-user.
pdu_decode_error
Error codes for PDU decoding errors.
@ incomplete_header
Less than 6 bytes available.
@ buffer_overflow
Item length exceeds PDU bounds.
@ malformed_pdu
PDU structure is invalid.
@ incomplete_pdu
PDU length exceeds available data.
@ invalid_item_type
Unknown item type in variable items.
@ invalid_protocol_version
Unsupported protocol version.
@ invalid_pdu_type
Unknown PDU type byte.
Result<T> type aliases and helpers for PACS system.
abort_pdu(abort_source src, abort_reason rsn)
abort_source source
Source of abort.
abort_reason reason
Reason for abort.
std::vector< presentation_data_value > pdvs
Presentation Data Values.
p_data_tf_pdu(std::vector< presentation_data_value > values)
A-RELEASE-RP has no data fields.
PDU variant type representing any DICOM Upper Layer PDU.A-RELEASE-RQ has no data fields.