mirror of
https://github.com/cccb/servicepoint.git
synced 2025-01-18 10:00:14 +01:00
hide packets to reduce api surface for new users
This commit is contained in:
parent
26bace8990
commit
78b5d1180b
|
@ -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<u8>;
|
|||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # use servicepoint::{Brightness, Command, Connection, Packet};
|
||||
/// # use servicepoint::{Brightness, Command, Connection, packet::Packet};
|
||||
/// #
|
||||
/// // create command
|
||||
/// let command = Command::Brightness(Brightness::MAX);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<u8> = 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<u8>;
|
|||
///
|
||||
/// 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<u8> = packet.into();
|
||||
/// let packet = Packet::try_from(bytes).expect("could not read packet from bytes");
|
||||
/// ```
|
||||
///
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Packet {
|
||||
|
|
|
@ -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))),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue