| Crates.io | dtp |
| lib.rs | dtp |
| version | 0.0.1 |
| created_at | 2025-09-09 05:50:15.776886+00 |
| updated_at | 2025-09-09 05:50:15.776886+00 |
| description | A lightweight, foundational crate for building layered data transfer protocols |
| homepage | |
| repository | https://github.com/Yrrrrrf/dtp |
| max_upload_size | |
| id | 1830309 |
| size | 21,108 |
DTP is a lightweight, foundational Rust crate for building simple, layered communication protocols. It provides a set of generic, reusable data structures that represent the different layers of a network stack, allowing developers to focus on the application logic rather than the boilerplate of data encapsulation.
The core of DTP is a set of structs—Frame, Packet, and Segment—that allow you to neatly package your data for transmission, inspired by the OSI model. It is designed to be transport-agnostic, meaning you can use it as the data-structuring backbone for any transmission medium, including serial interfaces or custom network transports.
This project is currently in an active prototyping and development phase. The API is designed to be simple and extensible but is subject to change.
Frame), Network (Packet), and Transport (Segment) layers.MacAddress, Ipv4Address) using the provided macros.bytes::Bytes for zero-copy payload handling.Add DTP to your project's Cargo.toml:
cargo add dtp
DTP provides the building blocks to structure your data. Here is a conceptual example of how you would encapsulate a piece of data for transmission.
use dtp::{Frame, Packet, Segment, Header};
use bytes::Bytes;
fn main() {
// 1. Your application data (payload)
let payload_data = Bytes::from("Hello, World!");
// 2. Encapsulate data in a Transport Layer Segment with Port addresses
let segment = Segment {
header: Header::new(8080, 80), // Source Port, Destination Port
payload: payload_data,
};
// 3. Encapsulate the Segment in a Network Layer Packet with IP addresses
let packet = Packet {
header: Header::new(0xC0A80001, 0x08080808), // 192.168.0.1 -> 8.8.8.8
pdu: vec![segment],
};
// 4. Encapsulate the Packet in a Data Link Layer Frame with MAC addresses
let frame = Frame {
header: Header::new([0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF], [0x11, 0x22, 0x33, 0x44, 0x55, 0x66]),
network_pdu: vec![packet],
};
println!("Constructed a DTP Frame!");
println!("{}", frame);
// Now, this 'frame' is ready to be serialized and sent over any medium
// of your choice (e.g., audio, serial, TCP, etc.).
}
This project is licensed under the MIT License - see the LICENSE file for details.