Skip to content

Commit

Permalink
Expose LCT Header to python
Browse files Browse the repository at this point in the history
  • Loading branch information
ypo committed Feb 28, 2024
1 parent e6eae11 commit c3ed23e
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
29 changes: 29 additions & 0 deletions py_tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,34 @@ def test_remove_object(self):
assert(success == True)
assert(flute_sender.nb_objects() == 0)


def test_lct(self):
from flute import sender, receiver

print("------- test_lct--------")

tsi = 1234

sender_config = sender.Config()
oti = sender.Oti.new_no_code(1400, 64)
flute_sender = sender.Sender(tsi, oti, sender_config)

receiver_writer = receiver.ObjectWriterBuilder.new_buffer()
receiver_config = receiver.Config()
udp_endpoint = receiver.UDPEndpoint("224.0.0.1", 1234)
flute_receiver = receiver.Receiver(udp_endpoint, tsi, receiver_writer, receiver_config)

buf = bytes(b'hello world')
flute_sender.add_object_from_buffer(buf, "text", "file://hello.txt", None)
flute_sender.publish()

pkt = flute_sender.read()
lct = receiver.LCTHeader(bytes(pkt))
assert(lct.cci == 0)
assert(lct.tsi == 1234)
assert(lct.toi == 0)
assert(lct.sbn == 0)
assert(lct.esi == 0)

if __name__ == '__main__':
unittest.main()
51 changes: 51 additions & 0 deletions src/py/receiver/lct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use pyo3::{exceptions::PyTypeError, prelude::*};

use crate::common::alc;

#[pyclass(unsendable)]
#[derive(Debug)]
pub struct LCTHeader {
pub inner: crate::core::lct::LCTHeader,
pub payload_id: Option<crate::core::alc::PayloadID>,
}

#[pymethods]
impl LCTHeader {
#[new]
fn new(data: &[u8]) -> PyResult<Self> {
let alc = crate::core::alc::parse_alc_pkt(data)
.map_err(|e| PyTypeError::new_err(e.0.to_string()))?;

let payload_id = alc::get_fec_inline_payload_id(&alc).ok();

Ok(LCTHeader {
inner: alc.lct,
payload_id,
})
}

#[getter]
fn cci(&self) -> PyResult<u128> {
Ok(self.inner.cci)
}

#[getter]
fn toi(&self) -> PyResult<u128> {
Ok(self.inner.toi)
}

#[getter]
fn tsi(&self) -> PyResult<u64> {
Ok(self.inner.tsi)
}

#[getter]
fn sbn(&self) -> PyResult<Option<u32>> {
Ok(self.payload_id.as_ref().map(|p| p.sbn))
}

#[getter]
fn esi(&self) -> PyResult<Option<u32>> {
Ok(self.payload_id.as_ref().map(|p| p.esi))
}
}
2 changes: 2 additions & 0 deletions src/py/receiver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod objectwriterbuilder;
mod multireceiver;
mod receiverpy;
mod udpendpoint;
mod lct;

#[pymodule]
pub fn receiver(_py: Python, m: &PyModule) -> PyResult<()> {
Expand All @@ -13,5 +14,6 @@ pub fn receiver(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<receiverpy::Receiver>()?;
m.add_class::<multireceiver::MultiReceiver>()?;
m.add_class::<udpendpoint::UDPEndpoint>()?;
m.add_class::<lct::LCTHeader>()?;
Ok(())
}

0 comments on commit c3ed23e

Please sign in to comment.