dtp

Crates.iodtp
lib.rsdtp
version0.0.1
created_at2025-09-09 05:50:15.776886+00
updated_at2025-09-09 05:50:15.776886+00
descriptionA lightweight, foundational crate for building layered data transfer protocols
homepage
repositoryhttps://github.com/Yrrrrrf/dtp
max_upload_size
id1830309
size21,108
Fernando Bryan Reza Campos (Yrrrrrf)

documentation

https://docs.rs/dtp

README

DTP (Digital Transfer Protocol)

Crates.io Docs.rs Crates.io Downloads License: MIT GitHub

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.

Features

  • Layered Architecture: Clearly defined structs for the Data Link (Frame), Network (Packet), and Transport (Segment) layers.
  • Generic by Design: Easily define your own address types (e.g., MacAddress, Ipv4Address) using the provided macros.
  • Efficient Payloads: Utilizes bytes::Bytes for zero-copy payload handling.
  • Extensible: A simple, composable design that's easy to build upon for more complex protocols.

Installation

Add DTP to your project's Cargo.toml:

cargo add dtp

Usage

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.).
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Commit count: 2

cargo fmt