diff --git a/crates/servicepoint/src/command.rs b/crates/servicepoint/src/command.rs index 24cf84c..537b017 100644 --- a/crates/servicepoint/src/command.rs +++ b/crates/servicepoint/src/command.rs @@ -1,8 +1,10 @@ use bitvec::prelude::BitVec; use crate::{ - command_code::CommandCode, compression::into_decompressed, Brightness, - BrightnessGrid, CompressionCode, Header, Origin, Packet, PixelGrid, Pixels, + command_code::CommandCode, + compression::into_decompressed, + packet::{Header, Packet}, + Brightness, BrightnessGrid, CompressionCode, Origin, PixelGrid, Pixels, PrimitiveGrid, SpBitVec, Tiles, TILE_SIZE, }; @@ -46,7 +48,7 @@ pub type Cp437Grid = PrimitiveGrid; /// # Examples /// /// ```rust -/// # use servicepoint::{Brightness, Command, Connection, Packet}; +/// # use servicepoint::{Brightness, Command, Connection, packet::Packet}; /// # /// // create command /// let command = Command::Brightness(Brightness::MAX); diff --git a/crates/servicepoint/src/compression.rs b/crates/servicepoint/src/compression.rs index 2e78073..12c79d5 100644 --- a/crates/servicepoint/src/compression.rs +++ b/crates/servicepoint/src/compression.rs @@ -8,7 +8,7 @@ use flate2::{FlushCompress, FlushDecompress, Status}; #[cfg(feature = "compression_zstd")] use zstd::{Decoder as ZstdDecoder, Encoder as ZstdEncoder}; -use crate::{CompressionCode, Payload}; +use crate::{packet::Payload, CompressionCode}; pub(crate) fn into_decompressed( kind: CompressionCode, diff --git a/crates/servicepoint/src/connection.rs b/crates/servicepoint/src/connection.rs index 40c9a5c..255c15a 100644 --- a/crates/servicepoint/src/connection.rs +++ b/crates/servicepoint/src/connection.rs @@ -3,7 +3,7 @@ use std::net::{ToSocketAddrs, UdpSocket}; use log::{debug, info}; -use crate::Packet; +use crate::packet::Packet; /// A connection to the display. /// @@ -19,7 +19,7 @@ use crate::Packet; pub enum Connection { /// A real connection using the UDP protocol Udp(UdpSocket), - /// A fake connection for testing that does not actually send anything + /// A fake connection for testing that does not actually send anything. Fake, } diff --git a/crates/servicepoint/src/lib.rs b/crates/servicepoint/src/lib.rs index e646e24..4cceea8 100644 --- a/crates/servicepoint/src/lib.rs +++ b/crates/servicepoint/src/lib.rs @@ -47,7 +47,6 @@ pub use crate::connection::Connection; pub use crate::data_ref::DataRef; pub use crate::grid::Grid; pub use crate::origin::{Origin, Pixels, Tiles}; -pub use crate::packet::{Header, Packet, Payload}; pub use crate::pixel_grid::PixelGrid; pub use crate::primitive_grid::PrimitiveGrid; @@ -62,7 +61,7 @@ mod connection; mod data_ref; mod grid; mod origin; -mod packet; +pub mod packet; mod pixel_grid; mod primitive_grid; diff --git a/crates/servicepoint/src/packet.rs b/crates/servicepoint/src/packet.rs index c09cb42..cf0fa82 100644 --- a/crates/servicepoint/src/packet.rs +++ b/crates/servicepoint/src/packet.rs @@ -1,10 +1,34 @@ +//! Raw packet manipulation. +//! +//! Should probably only be used directly to use features not exposed by the library. +//! +//! # Examples +//! +//! Converting a packet to a command and back: +//! +//! ```rust +//! use servicepoint::{Command, packet::Packet}; +//! # let command = Command::Clear; +//! let packet: Packet = command.into(); +//! let command: Command = Command::try_from(packet).expect("could not read command from packet"); +//! ``` +//! +//! Converting a packet to bytes and back: +//! +//! ```rust +//! use servicepoint::{Command, packet::Packet}; +//! # let command = Command::Clear; +//! # let packet: Packet = command.into(); +//! let bytes: Vec = packet.into(); +//! let packet = Packet::try_from(bytes).expect("could not read packet from bytes"); +//! ``` + use std::mem::size_of; -use crate::command_code::CommandCode; use crate::compression::into_compressed; use crate::{ - Command, CompressionCode, Grid, Offset, Origin, PixelGrid, Pixels, Tiles, - TILE_SIZE, + command_code::CommandCode, Command, CompressionCode, Grid, Offset, Origin, + PixelGrid, Pixels, Tiles, TILE_SIZE, }; /// A raw header. @@ -13,8 +37,6 @@ use crate::{ /// payload, where applicable. /// /// Because the meaning of most fields depend on the command, there are no speaking names for them. -/// -/// Should probably only be used directly to use features not exposed by the library. #[derive(Copy, Clone, Debug, PartialEq)] pub struct Header { /// The first two bytes specify which command this packet represents. @@ -38,28 +60,8 @@ pub type Payload = Vec; /// /// Contents should probably only be used directly to use features not exposed by the library. /// -/// You may want to use [Command][crate::Command] instead. +/// You may want to use [Command] instead. /// -/// # Examples -/// -/// Converting a packet to a command and back: -/// -/// ```rust -/// # use servicepoint::{Command, Packet}; -/// # let command = Command::Clear; -/// let packet: Packet = command.into(); -/// let command: Command = Command::try_from(packet).expect("could not read command from packet"); -/// ``` -/// -/// Converting a packet to bytes and back: -/// -/// ```rust -/// # use servicepoint::{Command, Packet}; -/// # let command = Command::Clear; -/// # let packet: Packet = command.into(); -/// let bytes: Vec = packet.into(); -/// let packet = Packet::try_from(bytes).expect("could not read packet from bytes"); -/// ``` /// #[derive(Clone, Debug, PartialEq)] pub struct Packet { diff --git a/crates/servicepoint_binding_c/src/packet.rs b/crates/servicepoint_binding_c/src/packet.rs index eac41b8..5dc5820 100644 --- a/crates/servicepoint_binding_c/src/packet.rs +++ b/crates/servicepoint_binding_c/src/packet.rs @@ -7,7 +7,7 @@ use std::ptr::null_mut; use crate::SPCommand; /// The raw packet -pub struct SPPacket(pub(crate) servicepoint::Packet); +pub struct SPPacket(pub(crate) servicepoint::packet::Packet); /// Turns a `SPCommand` into a `SPPacket`. /// The `SPCommand` gets consumed. @@ -49,7 +49,7 @@ pub unsafe extern "C" fn sp_packet_try_load( length: usize, ) -> *mut SPPacket { let data = std::slice::from_raw_parts(data, length); - match servicepoint::Packet::try_from(data) { + match servicepoint::packet::Packet::try_from(data) { Err(_) => null_mut(), Ok(packet) => Box::into_raw(Box::new(SPPacket(packet))), }