pdu

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package pdu implements DICOM Upper Layer Protocol Data Units (PS3.8).

Encoding is big-endian. Behaviour aligns with pynetdicom's pdu module; golden fixtures live in fixtures_test.go (from pynetdicom tests).

Index

Constants

View Source
const (
	MCHCommand      byte = 0x01
	MCHLastFragment byte = 0x02
)

Message control header bits (PS3.8 Annex E).

View Source
const (
	TypeAAssociateRQ = 0x01
	TypeAAssociateAC = 0x02
	TypeAAssociateRJ = 0x03
	TypePDataTF      = 0x04
	TypeAReleaseRQ   = 0x05
	TypeAReleaseRP   = 0x06
	TypeAAbort       = 0x07
)

PDU type values (PS3.8 Table 9-1).

View Source
const (
	ItemApplicationContext     = 0x10
	ItemPresentationContextRQ  = 0x20
	ItemPresentationContextAC  = 0x21
	ItemAbstractSyntax         = 0x30
	ItemTransferSyntax         = 0x40
	ItemUserInformation        = 0x50
	ItemMaxLength              = 0x51
	ItemImplementationClassUID = 0x52
	ItemRoleSelection          = 0x54
	ItemImplementationVersion  = 0x55
	ItemUserIdentityRQ         = 0x58
	ItemUserIdentityAC         = 0x59
)

Item type values for A-ASSOCIATE variable items.

View Source
const (
	UserIdentityUsername         = 1
	UserIdentityUsernamePasscode = 2
	UserIdentityKerberos         = 3
	UserIdentitySAML             = 4
	UserIdentityJWT              = 5
)

User Identity Type values (PS3.7 Annex D.3.3.7).

View Source
const (
	ApplicationContextName = "1.2.840.10008.3.1.1.1"
	VerificationSOPClass   = "1.2.840.10008.1.1"
	ImplicitVRLittleEndian = "1.2.840.10008.1.2"
)

Standard UIDs used during association.

View Source
const DefaultMaxPDULength = 16382

DefaultMaxPDULength is a common Maximum Length Received default (16382).

Variables

View Source
var ErrUnexpectedType = errors.New("pdu: unexpected type")

ErrUnexpectedType is returned when a PDU type does not match expectations.

Functions

func PadAETitle

func PadAETitle(ae string) ([16]byte, error)

PadAETitle returns a 16-byte AE title (trailing spaces).

func TrimAETitle

func TrimAETitle(b []byte) string

TrimAETitle strips trailing spaces from a 16-byte AE title field.

func Write

func Write(w io.Writer, p PDU) error

Write encodes p and writes it to w.

Types

type AAbort

type AAbort struct {
	Source           byte
	ReasonDiagnostic byte
}

AAbort is an A-ABORT PDU.

func DecodeAAbort

func DecodeAAbort(raw []byte) (*AAbort, error)

DecodeAAbort parses an A-ABORT PDU.

func (*AAbort) Encode

func (p *AAbort) Encode() ([]byte, error)

Encode serializes the PDU.

func (*AAbort) Type

func (p *AAbort) Type() byte

type AAssociateAC

type AAssociateAC struct {
	ProtocolVersion        uint16
	CalledAETitle          string
	CallingAETitle         string
	ApplicationContextName string
	PresentationContexts   []PresentationContextAC
	UserInformation        UserInformation
}

AAssociateAC is an A-ASSOCIATE-AC PDU.

func DecodeAAssociateAC

func DecodeAAssociateAC(raw []byte) (*AAssociateAC, error)

DecodeAAssociateAC parses an A-ASSOCIATE-AC PDU.

func (*AAssociateAC) Encode

func (p *AAssociateAC) Encode() ([]byte, error)

Encode serializes the PDU.

func (*AAssociateAC) Type

func (p *AAssociateAC) Type() byte

type AAssociateRJ

type AAssociateRJ struct {
	Result           byte
	Source           byte
	ReasonDiagnostic byte
}

AAssociateRJ is an A-ASSOCIATE-RJ PDU.

func DecodeAAssociateRJ

func DecodeAAssociateRJ(raw []byte) (*AAssociateRJ, error)

DecodeAAssociateRJ parses an A-ASSOCIATE-RJ PDU.

func (*AAssociateRJ) Encode

func (p *AAssociateRJ) Encode() ([]byte, error)

Encode serializes the PDU.

func (*AAssociateRJ) Type

func (p *AAssociateRJ) Type() byte

type AAssociateRQ

type AAssociateRQ struct {
	ProtocolVersion        uint16
	CalledAETitle          string
	CallingAETitle         string
	ApplicationContextName string
	PresentationContexts   []PresentationContextRQ
	UserInformation        UserInformation
}

AAssociateRQ is an A-ASSOCIATE-RQ PDU.

func DecodeAAssociateRQ

func DecodeAAssociateRQ(raw []byte) (*AAssociateRQ, error)

DecodeAAssociateRQ parses an A-ASSOCIATE-RQ PDU.

func (*AAssociateRQ) Encode

func (p *AAssociateRQ) Encode() ([]byte, error)

Encode serializes the PDU.

func (*AAssociateRQ) Type

func (p *AAssociateRQ) Type() byte

type AReleaseRP

type AReleaseRP struct{}

AReleaseRP is an A-RELEASE-RP PDU.

func DecodeAReleaseRP

func DecodeAReleaseRP(raw []byte) (*AReleaseRP, error)

DecodeAReleaseRP parses an A-RELEASE-RP PDU.

func (*AReleaseRP) Encode

func (p *AReleaseRP) Encode() ([]byte, error)

Encode serializes the PDU.

func (*AReleaseRP) Type

func (p *AReleaseRP) Type() byte

type AReleaseRQ

type AReleaseRQ struct{}

AReleaseRQ is an A-RELEASE-RQ PDU.

func DecodeAReleaseRQ

func DecodeAReleaseRQ(raw []byte) (*AReleaseRQ, error)

DecodeAReleaseRQ parses an A-RELEASE-RQ PDU.

func (*AReleaseRQ) Encode

func (p *AReleaseRQ) Encode() ([]byte, error)

Encode serializes the PDU.

func (*AReleaseRQ) Type

func (p *AReleaseRQ) Type() byte

type PDU

type PDU interface {
	Type() byte
	Encode() ([]byte, error)
}

PDU is a DICOM Upper Layer Protocol Data Unit.

func Read

func Read(r io.Reader) (PDU, error)

Read reads one PDU from r (6-byte header + body).

type PDV

type PDV struct {
	ContextID byte
	Value     []byte // includes MCH as first byte
}

PDV is a Presentation Data Value item inside a P-DATA-TF PDU. Value is Message Control Header + fragment (command or dataset).

func NewCommandPDV

func NewCommandPDV(contextID byte, commandSet []byte) PDV

NewCommandPDV builds a single last-fragment command PDV.

func NewDataPDV

func NewDataPDV(contextID byte, dataset []byte) PDV

NewDataPDV builds a single last-fragment dataset PDV.

func (PDV) Fragment

func (p PDV) Fragment() []byte

Fragment returns the bytes after the Message Control Header.

func (PDV) IsCommand

func (p PDV) IsCommand() bool

IsCommand reports whether this PDV carries a command fragment.

func (PDV) IsLast

func (p PDV) IsLast() bool

IsLast reports whether this is the last fragment of the message part.

type PDataTF

type PDataTF struct {
	PDVs []PDV
}

PDataTF is a P-DATA-TF PDU.

func DecodePDataTF

func DecodePDataTF(raw []byte) (*PDataTF, error)

DecodePDataTF parses a P-DATA-TF PDU.

func FragmentMessage

func FragmentMessage(contextID byte, command, dataset []byte, maxPDULength uint32) ([]*PDataTF, error)

FragmentMessage builds P-DATA-TF PDUs for a command set and optional dataset.

maxPDULength is the peer's Maximum Length Received (0 = unlimited). Each P-DATA-TF PDV list is kept within that limit (PS3.8 Annex D), matching pynetdicom's encode_msg fragmentation.

func (*PDataTF) Encode

func (p *PDataTF) Encode() ([]byte, error)

Encode serializes the PDU.

func (*PDataTF) Type

func (p *PDataTF) Type() byte

type PresentationContextAC

type PresentationContextAC struct {
	ID             byte
	Result         byte // 0 = acceptance
	TransferSyntax string
}

PresentationContextAC is an accepted/rejected context in A-ASSOCIATE-AC.

type PresentationContextRQ

type PresentationContextRQ struct {
	ID               byte
	AbstractSyntax   string
	TransferSyntaxes []string
}

PresentationContextRQ is a proposed presentation context in A-ASSOCIATE-RQ.

type RoleSelection added in v0.4.0

type RoleSelection struct {
	SOPClassUID string
	SCURole     bool
	SCPRole     bool
}

RoleSelection is an SCP/SCU Role Selection Negotiation sub-item (0x54). Aligned with pynetdicom SCP_SCU_RoleSelectionNegotiation.

type UserIdentityAC added in v0.6.0

type UserIdentityAC struct {
	ServerResponse []byte
}

UserIdentityAC is a User Identity Negotiation response sub-item (0x59). Aligned with pynetdicom UserIdentitySubItemAC.

type UserIdentityRQ added in v0.6.0

type UserIdentityRQ struct {
	Type                      byte
	PositiveResponseRequested bool
	PrimaryField              []byte
	SecondaryField            []byte // used when Type == UserIdentityUsernamePasscode
}

UserIdentityRQ is a User Identity Negotiation request sub-item (0x58). Aligned with pynetdicom UserIdentitySubItemRQ.

type UserInformation

type UserInformation struct {
	MaxLength                 uint32
	ImplementationClassUID    string
	ImplementationVersionName string
	RoleSelections            []RoleSelection
	UserIdentityRQ            *UserIdentityRQ // A-ASSOCIATE-RQ only
	UserIdentityAC            *UserIdentityAC // A-ASSOCIATE-AC only
}

UserInformation carries association negotiation user items.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL