dtp 0.0.1

A lightweight, foundational crate for building layered data transfer protocols
Documentation
  • Coverage
  • 58.14%
    25 out of 43 items documented0 out of 18 items with examples
  • Size
  • Source code size: 20.61 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.58 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 20s Average build duration of successful builds.
  • all releases: 20s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Yrrrrrf/dtp
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Yrrrrrf

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.