aboutsummaryrefslogtreecommitdiff
path: root/ouroboros/_qosspec.py
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2026-06-30 18:56:00 +0200
committerDimitri Staessens <dimitri@ouroboros.rocks>2026-06-30 19:05:31 +0200
commita6c2bf9cbfcd3e13569d3a7d915c27d42fb7bbec (patch)
treefe14d51fd2c9b0b1b34420c5bf12683030e2fa38 /ouroboros/_qosspec.py
parent5f2bc27eacafb2b714317dd9cc0f286c774bdb64 (diff)
downloadpyouroboros-a6c2bf9cbfcd3e13569d3a7d915c27d42fb7bbec.tar.gz
pyouroboros-a6c2bf9cbfcd3e13569d3a7d915c27d42fb7bbec.zip
ouroboros: Use QoSService in QoSSpec
Match the use of service instead of the in_order field in Ouroboros.
Diffstat (limited to 'ouroboros/_qosspec.py')
-rw-r--r--ouroboros/_qosspec.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/ouroboros/_qosspec.py b/ouroboros/_qosspec.py
new file mode 100644
index 0000000..6031c42
--- /dev/null
+++ b/ouroboros/_qosspec.py
@@ -0,0 +1,70 @@
+#
+# Ouroboros - Copyright (C) 2016 - 2026
+#
+# Internal helpers for translating QoSSpec <-> CFFI qosspec_t.
+#
+# Dimitri Staessens <dimitri@ouroboros.rocks>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public License
+# version 2.1 as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., http://www.fsf.org/about/contact/.
+#
+
+"""Shared QoSSpec <-> qosspec_t conversion helpers.
+
+dev.py and irm.py each link against their own CFFI extension module
+(``_ouroboros_dev_cffi`` and ``_ouroboros_irm_cffi``), so they each
+have their own ``ffi`` instance and their own ``qosspec_t`` type.
+CFFI types are not interchangeable across modules, so these helpers
+take the caller's ``ffi`` instance as a parameter.
+"""
+
+from __future__ import annotations
+
+from typing import Optional
+
+from ouroboros.qos import QoSSpec
+
+
+def qos_to_qosspec(ffi, qos: Optional[QoSSpec]):
+ """Convert a :class:`QoSSpec` to a freshly-allocated ``qosspec_t *``.
+
+ Returns ``ffi.NULL`` when *qos* is ``None``.
+ """
+ if qos is None:
+ return ffi.NULL
+ return ffi.new("qosspec_t *",
+ [qos.service,
+ qos.delay,
+ qos.bandwidth,
+ qos.availability,
+ qos.loss,
+ qos.ber,
+ qos.max_gap,
+ qos.timeout])
+
+
+def qosspec_to_qos(ffi, _qos) -> Optional[QoSSpec]:
+ """Convert a ``qosspec_t *`` back to a :class:`QoSSpec`.
+
+ Returns ``None`` when *_qos* is ``ffi.NULL``.
+ """
+ if _qos == ffi.NULL:
+ return None
+ return QoSSpec(service=_qos.service,
+ delay=_qos.delay,
+ bandwidth=_qos.bandwidth,
+ availability=_qos.availability,
+ loss=_qos.loss,
+ ber=_qos.ber,
+ max_gap=_qos.max_gap,
+ timeout=_qos.timeout)