TSDU

TSDU (Transport Service Data Unit) Handling

This module implements parsing and building logic for TSDUs as defined in §8.1 of the X.225 specification.

A TSDU is the unit of data exchanged between the session layer and the transport layer. It may contain:

  • One SPDU mapped directly to a TSDU (Category 1)

  • Multiple SPDUs concatenated (Category 0 + Category 2, or multiple Category 2s)

  • In special cases, only a Category 0 SPDU

Concatenation rules are defined in §6.3.7:

  • Category 0 SPDUs may be mapped one-to-one onto a TSDU or

    concatenated with one or more Category 2 SPDUs.

  • Category 1 SPDUs are always mapped one-to-one to a TSDU (no

    concatenation).

  • Category 2 SPDUs are never mapped one-to-one — they appear only after

    a Category 0 SPDU in the same TSDU.

See also

  • §6.3.7 Concatenation rules

  • §8.1 TSDU structure

  • §8.2 SPDU structure

class icspacket.proto.iso_ses.tsdu.TSDU[source]

TSDU container for one or more concatenated SPDUs — X.225 §8.1

Usage:

>>> tsdu = TSDU.from_octets(data)   # Parse a raw TSDU from bytes
>>> tsdu.build()                    # Encode back to raw bytes
add_spdu(code: int, category: SPDU_Category | None = None) SPDU[source]

Create a new SPDU and append it to this TSDU.

Parameters:
  • code (int) – The SPDU code (see SPDU_Codes).

  • category (SPDU_Category, optional) – The SPDU category, defaults to False

Returns:

The newly created SPDU object.

Return type:

SPDU

property spdus: list[SPDU]

List of SPDUs contained in this TSDU.

This property returns a direct reference to the internal list, so it can be iterated over or modified directly.

static from_octets(octets: bytes)[source]

Decode a raw TSDU from its octet representation.

Parameters:

octets (bytes) – The raw TSDU data as received from the transport layer.

Raises:

ValueError – If a Category 0 SPDU has a non-zero length, or or if any SPDU length is invalid (extends beyond buffer).

Returns:

A fully parsed TSDU object containing one or more SPDUs.

Return type:

TSDU

build() bytes[source]

Assemble the TSDU into its raw octet representation.

Returns:

The encoded TSDU, produced by concatenating each SPDU’s octet representation.

Return type:

bytes