airmash_protocol/
lib.rs

1//! Protocol definitions for AIRMASH. This crate provides a strongly typed
2//! interface for communicating with an airmash server. It also provides an
3//! implementation of the airmash v5 protocol along with serde definitions for
4//! all interface structs. This is enough to communicate with any existing
5//! airmash server over a websocket connection.
6//!
7//! # Library Usage
8//! The library is designed to be straightforward to use. First construct the
9//! appropriate packet from either [server packets](crate::ServerPacket) or
10//! [client packets](crate::ClientPacket). From there you can serialize it to
11//! bytes via [`v5::serialize`](crate::v5::serialize).
12//!
13//! ```
14//! # use airmash_protocol::{ClientPacket, KeyCode, v5, client::Key};
15//! # fn main() -> Result<(), v5::Error> {
16//! let packet = ClientPacket::from(Key {
17//!   seq: 0,
18//!   key: KeyCode::Fire,
19//!   state: true
20//! });
21//!
22//! let bytes = airmash_protocol::v5::serialize(&packet)?;
23//! // ... send bytes to server
24//! # Ok(())
25//! # }
26//! ```
27//!
28//! Note that while the individual packet types are serializable individually
29//! the only types expected to be passed between clients and servers are
30//! [`ServerPacket`] and [`ClientPacket`].
31//!
32//! For deserialization you can use [`v5::deserialize`] on any byte slice.
33//! ```
34//! # use airmash_protocol::{ClientPacket, v5};
35//! # fn get_some_bytes() -> Vec<u8> { return vec![5]; }
36//! # fn main() -> Result<(), v5::Error> {
37//! let bytes: Vec<u8> = get_some_bytes();
38//! let packet: ClientPacket = airmash_protocol::v5::deserialize(&bytes)?;
39//! // ... do stuff with packet
40//! # Ok(())
41//! # }
42//! ```
43
44#[cfg(feature = "serde")]
45#[cfg_attr(feature = "serde", macro_use)]
46extern crate serde;
47
48#[macro_use]
49mod detail;
50
51mod enums;
52mod error;
53mod packets;
54mod types;
55mod util;
56
57mod client_packet;
58mod server_packet;
59
60#[cfg(feature = "serde")]
61pub mod custom;
62
63pub mod v5;
64
65pub use self::client_packet::ClientPacket;
66pub use self::enums::*;
67pub use self::packets::*;
68pub use self::server_packet::ServerPacket;
69pub use self::types::*;
70pub use crate::error::EnumValueOutOfRangeError;