takproto 0.4.2

Rust library for TAK (Team Awareness Kit) Protocol - send CoT messages to TAK servers with mTLS support
Documentation
//! # takproto
//!
//! A Rust library for sending TAK (Team Awareness Kit) Protocol messages to TAK servers
//! with full mTLS support.
//!
//! ## Features
//!
//! - **TAK Protocol Version 1** - Protocol Buffer-based messaging
//! - **mTLS Support** - Client certificate authentication
//! - **Protocol Negotiation** - Automatic handshake with TAK servers
//! - **XML Mode** - Legacy Protocol Version 0 support
//! - **Async/Await** - Built on Tokio
//! - **Type-Safe** - Generated protobuf types
//!
//! ## Feature Flags
//!
//! - **`openssl-p12`** - Enable full PKCS#12 support using OpenSSL for legacy TAK server certificates
//!
//! Enable in your `Cargo.toml`:
//! ```toml
//! [dependencies]
//! takproto = { version = "0.2", features = ["openssl-p12"] }
//! ```
//!
//! Without this feature, the library uses a pure Rust P12 parser which may not support
//! legacy formats. If you encounter P12 parsing errors, either enable this feature or
//! extract the P12 to PEM files.
//!
//! ## Quick Start
//!
//! ```no_run
//! use std::time::{SystemTime, UNIX_EPOCH};
//! use takproto::{TakClient, TlsConfig, proto::CotEvent};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//!     // Configure mTLS
//!     let tls_config = TlsConfig::new_with_client_cert(
//!         "ca.pem",
//!         "client.pem",
//!         "client-key.pem"
//!     )?;
//!
//!     // Connect to TAK server
//!     let mut client = TakClient::connect_tls(
//!         "takserver.example.com:8089",
//!         "takserver.example.com",
//!         tls_config
//!     ).await?;
//!
//!     // Negotiate protocol (optional)
//!     client.negotiate_protocol(1, 60).await?;
//!
//!     // Get current time
//!     let now_ms = SystemTime::now()
//!         .duration_since(UNIX_EPOCH)?
//!         .as_millis() as u64;
//!
//!     // Create a position report
//!     let event = CotEvent {
//!         r#type: "a-f-G-U-C".to_string(),
//!         uid: "RUST-TAK-1".to_string(),
//!         send_time: now_ms,
//!         start_time: now_ms,
//!         stale_time: now_ms + 60_000,
//!         how: "m-g".to_string(),
//!         lat: 37.7749,
//!         lon: -122.4194,
//!         hae: 10.0,
//!         ce: 9.9,
//!         le: 9.9,
//!         ..Default::default()
//!     };
//!
//!     // Send the event
//!     client.send_cot_event(event).await?;
//!
//!     Ok(())
//! }
//! ```
//!
//! ## Protocol Modes
//!
//! ### Protobuf Mode (for high-frequency updates)
//!
//! ```no_run
//! # use takproto::{TakClient, TlsConfig};
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # let tls_config = TlsConfig::new_with_client_cert("ca.pem", "c.pem", "k.pem")?;
//! # let mut client = TakClient::connect_tls("s:8089", "s", tls_config).await?;
//! // Negotiate protocol
//! client.negotiate_protocol(1, 60).await?;
//! # Ok(())
//! # }
//! ```
//!
//! ### XML Mode (for maximum compatibility)
//!
//! ```no_run
//! # use takproto::{TakClient, proto::CotEvent};
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # let mut client = TakClient::connect("127.0.0.1:8087").await?;
//! # let event = CotEvent::default();
//! // No negotiation needed - send directly as XML
//! client.send_cot_event_xml(event).await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Helper Functions
//!
//! ```rust
//! use takproto::helpers::{url_to_uid, remarks, color, colors};
//!
//! // Convert URL to clean UID
//! let uid = url_to_uid("https://status.example.com");  // "status.example.com"
//!
//! // Create colored marker details
//! let xml = format!("{}\n{}",
//!     remarks("System Status"),
//!     color(colors::GREEN)
//! );
//! ```

pub mod proto {
    //! Protocol Buffer generated types for TAK messages
    include!(concat!(env!("OUT_DIR"), "/atakmap.commoncommo.protobuf.v1.rs"));
}

mod client;
mod error;
mod framing;
mod tls;

pub mod xml;
pub mod helpers;
pub mod builder;

pub use client::TakClient;
pub use error::{TakError, Result};
pub use tls::{TlsConfig, TlsConfigBuilder};
pub use builder::CotEventBuilder;