mirror of
https://github.com/cccb/servicepoint.git
synced 2025-01-18 18:10: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 bitvec::prelude::BitVec;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
command_code::CommandCode, compression::into_decompressed, Brightness,
|
command_code::CommandCode,
|
||||||
BrightnessGrid, CompressionCode, Header, Origin, Packet, PixelGrid, Pixels,
|
compression::into_decompressed,
|
||||||
|
packet::{Header, Packet},
|
||||||
|
Brightness, BrightnessGrid, CompressionCode, Origin, PixelGrid, Pixels,
|
||||||
PrimitiveGrid, SpBitVec, Tiles, TILE_SIZE,
|
PrimitiveGrid, SpBitVec, Tiles, TILE_SIZE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -46,7 +48,7 @@ pub type Cp437Grid = PrimitiveGrid<u8>;
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use servicepoint::{Brightness, Command, Connection, Packet};
|
/// # use servicepoint::{Brightness, Command, Connection, packet::Packet};
|
||||||
/// #
|
/// #
|
||||||
/// // create command
|
/// // create command
|
||||||
/// let command = Command::Brightness(Brightness::MAX);
|
/// let command = Command::Brightness(Brightness::MAX);
|
||||||
|
|
|
@ -8,7 +8,7 @@ use flate2::{FlushCompress, FlushDecompress, Status};
|
||||||
#[cfg(feature = "compression_zstd")]
|
#[cfg(feature = "compression_zstd")]
|
||||||
use zstd::{Decoder as ZstdDecoder, Encoder as ZstdEncoder};
|
use zstd::{Decoder as ZstdDecoder, Encoder as ZstdEncoder};
|
||||||
|
|
||||||
use crate::{CompressionCode, Payload};
|
use crate::{packet::Payload, CompressionCode};
|
||||||
|
|
||||||
pub(crate) fn into_decompressed(
|
pub(crate) fn into_decompressed(
|
||||||
kind: CompressionCode,
|
kind: CompressionCode,
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::net::{ToSocketAddrs, UdpSocket};
|
||||||
|
|
||||||
use log::{debug, info};
|
use log::{debug, info};
|
||||||
|
|
||||||
use crate::Packet;
|
use crate::packet::Packet;
|
||||||
|
|
||||||
/// A connection to the display.
|
/// A connection to the display.
|
||||||
///
|
///
|
||||||
|
@ -19,7 +19,7 @@ use crate::Packet;
|
||||||
pub enum Connection {
|
pub enum Connection {
|
||||||
/// A real connection using the UDP protocol
|
/// A real connection using the UDP protocol
|
||||||
Udp(UdpSocket),
|
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,
|
Fake,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,6 @@ pub use crate::connection::Connection;
|
||||||
pub use crate::data_ref::DataRef;
|
pub use crate::data_ref::DataRef;
|
||||||
pub use crate::grid::Grid;
|
pub use crate::grid::Grid;
|
||||||
pub use crate::origin::{Origin, Pixels, Tiles};
|
pub use crate::origin::{Origin, Pixels, Tiles};
|
||||||
pub use crate::packet::{Header, Packet, Payload};
|
|
||||||
pub use crate::pixel_grid::PixelGrid;
|
pub use crate::pixel_grid::PixelGrid;
|
||||||
pub use crate::primitive_grid::PrimitiveGrid;
|
pub use crate::primitive_grid::PrimitiveGrid;
|
||||||
|
|
||||||
|
@ -62,7 +61,7 @@ mod connection;
|
||||||
mod data_ref;
|
mod data_ref;
|
||||||
mod grid;
|
mod grid;
|
||||||
mod origin;
|
mod origin;
|
||||||
mod packet;
|
pub mod packet;
|
||||||
mod pixel_grid;
|
mod pixel_grid;
|
||||||
mod primitive_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 std::mem::size_of;
|
||||||
|
|
||||||
use crate::command_code::CommandCode;
|
|
||||||
use crate::compression::into_compressed;
|
use crate::compression::into_compressed;
|
||||||
use crate::{
|
use crate::{
|
||||||
Command, CompressionCode, Grid, Offset, Origin, PixelGrid, Pixels, Tiles,
|
command_code::CommandCode, Command, CompressionCode, Grid, Offset, Origin,
|
||||||
TILE_SIZE,
|
PixelGrid, Pixels, Tiles, TILE_SIZE,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A raw header.
|
/// A raw header.
|
||||||
|
@ -13,8 +37,6 @@ use crate::{
|
||||||
/// payload, where applicable.
|
/// payload, where applicable.
|
||||||
///
|
///
|
||||||
/// Because the meaning of most fields depend on the command, there are no speaking names for them.
|
/// 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)]
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||||
pub struct Header {
|
pub struct Header {
|
||||||
/// The first two bytes specify which command this packet represents.
|
/// 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.
|
/// 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)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct Packet {
|
pub struct Packet {
|
||||||
|
|
|
@ -7,7 +7,7 @@ use std::ptr::null_mut;
|
||||||
use crate::SPCommand;
|
use crate::SPCommand;
|
||||||
|
|
||||||
/// The raw packet
|
/// The raw packet
|
||||||
pub struct SPPacket(pub(crate) servicepoint::Packet);
|
pub struct SPPacket(pub(crate) servicepoint::packet::Packet);
|
||||||
|
|
||||||
/// Turns a `SPCommand` into a `SPPacket`.
|
/// Turns a `SPCommand` into a `SPPacket`.
|
||||||
/// The `SPCommand` gets consumed.
|
/// The `SPCommand` gets consumed.
|
||||||
|
@ -49,7 +49,7 @@ pub unsafe extern "C" fn sp_packet_try_load(
|
||||||
length: usize,
|
length: usize,
|
||||||
) -> *mut SPPacket {
|
) -> *mut SPPacket {
|
||||||
let data = std::slice::from_raw_parts(data, length);
|
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(),
|
Err(_) => null_mut(),
|
||||||
Ok(packet) => Box::into_raw(Box::new(SPPacket(packet))),
|
Ok(packet) => Box::into_raw(Box::new(SPPacket(packet))),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue