Skip to content

Commit c4ed3de

Browse files
feat: Create new module net in lib_ccxr
feat: Create new module `net` in lib_ccxr
1 parent b579c3f commit c4ed3de

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/rust/lib_ccxr/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pub mod common;
2+
pub mod net;
23
pub mod time;
34
pub mod util;

src/rust/lib_ccxr/src/net/mod.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//! A module for sending and receiving subtitle data across the network.
2+
//!
3+
//! The [`SendTarget`] struct provides methods to send data to the network. It can be constructed
4+
//! from [`SendTargetConfig`].
5+
//!
6+
//! The [`RecvSource`] struct provides methods to receive data from the network. It can be
7+
//! constructed from [`RecvSourceConfig`].
8+
//!
9+
//! Any data to be sent across the network in the stored in the form of a [`Block`]. The
10+
//! [`BlockStream`] can encode a [`Block`] as a byte sequence using a custom byte format which can
11+
//! then be sent or received using standard networking primitives. See [`BlockStream`] to know more
12+
//! about the custom byte format.
13+
//!
14+
//! # Conversion Guide
15+
//!
16+
//! | From | To |
17+
//! |--------------------------------|-----------------------------------|
18+
//! | `connect_to_srv` | [`SendTarget::new`] |
19+
//! | `net_send_header` | [`SendTarget::send_header`] |
20+
//! | `net_send_cc` | [`SendTarget::send_cc`] |
21+
//! | `net_send_epg` | [`SendTarget::send_epg_data`] |
22+
//! | `net_check_conn` | [`SendTarget::check_connection`] |
23+
//! | `start_tcp_srv` | [`RecvSource::new`] |
24+
//! | `start_udp_srv` | [`RecvSource::new`] |
25+
//! | `net_tcp_read` | [`RecvSource::recv_header_or_cc`] |
26+
//! | `net_udp_read` | [`RecvSource::send`] |
27+
//! | `read_block` | [`BlockStream::recv_block`] |
28+
//! | `write_block` | [`BlockStream::send_block`] |
29+
//! | Commands in Protocol Constants | [`Command`] |
30+
//! | `DFT_PORT` | [`DEFAULT_TCP_PORT`] |
31+
//! | `NO_RESPONCE_INTERVAL` | [`NO_RESPONSE_INTERVAL`] |
32+
//! | `PING_INTERVAL` | [`PING_INTERVAL`] |
33+
34+
/// A collective [`Error`](std::error::Error) type that encompasses all the possible error cases
35+
/// when sending, receiving or parsing data during networking operations.
36+
#[derive(thiserror::Error, Debug)]
37+
pub enum NetError {
38+
/// An Error ocurred within std giving a [`io::Error`]
39+
#[error(transparent)]
40+
IoError(#[from] std::io::Error),
41+
42+
/// The received bytes do not follow a [`Block`]'s byte format.
43+
///
44+
/// See [`BlockStream`] for more information.
45+
#[error("invalid bytes while parsing {location}")]
46+
InvalidBytes { location: &'static str },
47+
}

0 commit comments

Comments
 (0)