[refactor](trx-protocol): move transport dto out of core

Phase 5: relocate ClientCommand/Envelope/Response into trx-protocol and update call sites so trx-core remains domain-focused.

Co-authored-by: Codex <codex@openai.com>
Signed-off-by: Stanislaw Grams <stanislawgrams@gmail.com>
This commit is contained in:
2026-02-12 21:19:42 +01:00
parent 0d8314cab6
commit 0aa2fcbbbb
10 changed files with 26 additions and 41 deletions
+1 -1
View File
@@ -10,11 +10,11 @@ use tokio::sync::{mpsc, watch};
use tokio::time::{self, Instant};
use tracing::{info, warn};
use trx_core::client::{ClientCommand, ClientEnvelope, ClientResponse};
use trx_core::rig::request::RigRequest;
use trx_core::rig::state::RigState;
use trx_core::{RigError, RigResult};
use trx_protocol::rig_command_to_client;
use trx_protocol::{ClientCommand, ClientEnvelope, ClientResponse};
pub struct RemoteClientConfig {
pub addr: String,
@@ -10,6 +10,7 @@ edition = "2021"
[dependencies]
trx-core = { path = "../../../trx-core" }
trx-frontend = { path = ".." }
trx-protocol = { path = "../../../../src/trx-protocol" }
tokio = { workspace = true, features = ["full"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
@@ -12,3 +12,4 @@ tokio = { workspace = true, features = ["full"] }
tracing = { workspace = true }
trx-core = { path = "../../../trx-core" }
trx-frontend = { path = ".." }
trx-protocol = { path = "../../../../src/trx-protocol" }
@@ -11,6 +11,7 @@ use tokio::sync::{mpsc, oneshot, watch};
use tokio::task::JoinHandle;
use tokio::time::timeout;
use tracing::{debug, error, info, warn};
use trx_protocol::{mode_to_string, parse_mode};
use trx_core::radio::freq::Freq;
use trx_core::rig::state::RigSnapshot;
@@ -252,26 +253,8 @@ fn current_snapshot(state_rx: &watch::Receiver<RigState>) -> Option<RigSnapshot>
state_rx.borrow().snapshot()
}
fn parse_mode(s: &str) -> RigMode {
match s.to_ascii_uppercase().as_str() {
"LSB" => RigMode::LSB,
"USB" => RigMode::USB,
"CW" => RigMode::CW,
"CWR" => RigMode::CWR,
"AM" => RigMode::AM,
"FM" => RigMode::FM,
"WFM" => RigMode::WFM,
"DIG" | "DIGI" => RigMode::DIG,
"PKT" | "PACKET" => RigMode::PKT,
other => RigMode::Other(other.to_string()),
}
}
fn rig_mode_to_str(mode: &RigMode) -> String {
match mode {
RigMode::Other(other) => other.clone(),
other => format!("{:?}", other),
}
mode_to_string(mode)
}
fn dump_state_lines(_snapshot: &RigSnapshot) -> Vec<String> {
-2
View File
@@ -3,7 +3,6 @@
// SPDX-License-Identifier: BSD-2-Clause
pub mod audio;
pub mod client;
pub mod decode;
pub mod math;
pub mod radio;
@@ -11,7 +10,6 @@ pub mod rig;
pub type DynResult<T> = Result<T, Box<dyn std::error::Error + Send + Sync>>;
pub use client::{ClientCommand, ClientResponse};
pub use rig::command::RigCommand;
pub use rig::request::RigRequest;
pub use rig::response::{RigError, RigResult};
+1 -1
View File
@@ -6,8 +6,8 @@
use serde_json;
use trx_core::client::{ClientCommand, ClientEnvelope};
use trx_core::rig::state::RigMode;
use crate::types::{ClientCommand, ClientEnvelope};
/// Parse a mode string into a RigMode.
///
+2
View File
@@ -10,8 +10,10 @@
pub mod auth;
pub mod codec;
pub mod mapping;
pub mod types;
// Re-export commonly used items
pub use auth::{NoAuthValidator, SimpleTokenValidator, TokenValidator};
pub use codec::{mode_to_string, parse_envelope, parse_mode};
pub use mapping::{client_command_to_rig, rig_command_to_client};
pub use types::{ClientCommand, ClientEnvelope, ClientResponse};
+12 -12
View File
@@ -6,9 +6,9 @@
use trx_core::radio::freq::Freq;
use trx_core::rig::command::RigCommand;
use trx_core::ClientCommand;
use crate::codec::{mode_to_string, parse_mode};
use crate::types::ClientCommand;
/// Convert a ClientCommand to a RigCommand.
///
@@ -123,7 +123,7 @@ mod tests {
fn test_client_command_to_rig_set_ptt() {
let cmd = ClientCommand::SetPtt { ptt: true };
if let RigCommand::SetPtt(ptt) = client_command_to_rig(cmd) {
assert_eq!(ptt, true);
assert!(ptt);
} else {
panic!("Expected SetPtt");
}
@@ -203,7 +203,7 @@ mod tests {
fn test_client_command_to_rig_set_aprs_decode_enabled() {
let cmd = ClientCommand::SetAprsDecodeEnabled { enabled: true };
if let RigCommand::SetAprsDecodeEnabled(enabled) = client_command_to_rig(cmd) {
assert_eq!(enabled, true);
assert!(enabled);
} else {
panic!("Expected SetAprsDecodeEnabled");
}
@@ -213,7 +213,7 @@ mod tests {
fn test_client_command_to_rig_set_cw_decode_enabled() {
let cmd = ClientCommand::SetCwDecodeEnabled { enabled: false };
if let RigCommand::SetCwDecodeEnabled(enabled) = client_command_to_rig(cmd) {
assert_eq!(enabled, false);
assert!(!enabled);
} else {
panic!("Expected SetCwDecodeEnabled");
}
@@ -223,7 +223,7 @@ mod tests {
fn test_client_command_to_rig_set_cw_auto() {
let cmd = ClientCommand::SetCwAuto { enabled: true };
if let RigCommand::SetCwAuto(enabled) = client_command_to_rig(cmd) {
assert_eq!(enabled, true);
assert!(enabled);
} else {
panic!("Expected SetCwAuto");
}
@@ -253,7 +253,7 @@ mod tests {
fn test_client_command_to_rig_set_ft8_decode_enabled() {
let cmd = ClientCommand::SetFt8DecodeEnabled { enabled: true };
if let RigCommand::SetFt8DecodeEnabled(enabled) = client_command_to_rig(cmd) {
assert_eq!(enabled, true);
assert!(enabled);
} else {
panic!("Expected SetFt8DecodeEnabled");
}
@@ -333,7 +333,7 @@ mod tests {
fn test_rig_command_to_client_set_ptt() {
let cmd = RigCommand::SetPtt(true);
if let ClientCommand::SetPtt { ptt } = rig_command_to_client(cmd) {
assert_eq!(ptt, true);
assert!(ptt);
} else {
panic!("Expected SetPtt");
}
@@ -413,7 +413,7 @@ mod tests {
fn test_rig_command_to_client_set_aprs_decode_enabled() {
let cmd = RigCommand::SetAprsDecodeEnabled(true);
if let ClientCommand::SetAprsDecodeEnabled { enabled } = rig_command_to_client(cmd) {
assert_eq!(enabled, true);
assert!(enabled);
} else {
panic!("Expected SetAprsDecodeEnabled");
}
@@ -423,7 +423,7 @@ mod tests {
fn test_rig_command_to_client_set_cw_decode_enabled() {
let cmd = RigCommand::SetCwDecodeEnabled(false);
if let ClientCommand::SetCwDecodeEnabled { enabled } = rig_command_to_client(cmd) {
assert_eq!(enabled, false);
assert!(!enabled);
} else {
panic!("Expected SetCwDecodeEnabled");
}
@@ -433,7 +433,7 @@ mod tests {
fn test_rig_command_to_client_set_cw_auto() {
let cmd = RigCommand::SetCwAuto(true);
if let ClientCommand::SetCwAuto { enabled } = rig_command_to_client(cmd) {
assert_eq!(enabled, true);
assert!(enabled);
} else {
panic!("Expected SetCwAuto");
}
@@ -463,7 +463,7 @@ mod tests {
fn test_rig_command_to_client_set_ft8_decode_enabled() {
let cmd = RigCommand::SetFt8DecodeEnabled(true);
if let ClientCommand::SetFt8DecodeEnabled { enabled } = rig_command_to_client(cmd) {
assert_eq!(enabled, true);
assert!(enabled);
} else {
panic!("Expected SetFt8DecodeEnabled");
}
@@ -534,7 +534,7 @@ mod tests {
let client_cmd = rig_command_to_client(rig_cmd);
if let ClientCommand::SetPtt { ptt } = client_cmd {
assert_eq!(ptt, false);
assert!(!ptt);
} else {
panic!("Round trip failed");
}
@@ -2,9 +2,11 @@
//
// SPDX-License-Identifier: BSD-2-Clause
//! Transport DTOs for the JSON line protocol.
use serde::{Deserialize, Serialize};
use crate::rig::state::RigSnapshot;
use trx_core::rig::state::RigSnapshot;
/// Command received from network clients (JSON).
#[derive(Debug, Serialize, Deserialize)]
+3 -5
View File
@@ -5,7 +5,7 @@
//! JSON-over-TCP listener for trx-server.
//!
//! Accepts client connections speaking the `ClientEnvelope`/`ClientResponse`
//! protocol defined in `trx-core::client`.
//! protocol defined in `trx-protocol`.
use std::collections::HashSet;
use std::net::SocketAddr;
@@ -19,11 +19,10 @@ use tracing::{error, info};
use trx_core::rig::command::RigCommand;
use trx_core::rig::request::RigRequest;
use trx_core::rig::state::RigState;
use trx_core::ClientResponse;
use trx_protocol::codec::parse_envelope;
use trx_protocol::auth::{SimpleTokenValidator, TokenValidator};
use trx_protocol::codec::parse_envelope;
use trx_protocol::mapping;
use trx_protocol::ClientResponse;
/// Run the JSON TCP listener, accepting client connections.
pub async fn run_listener(
@@ -179,4 +178,3 @@ async fn handle_client(
Ok(())
}