pso2packetlib/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![deny(unsafe_code)]
3#![warn(clippy::future_not_send)]
4
5pub mod asciistring;
6#[cfg(feature = "connection")]
7pub mod connection;
8#[cfg(feature = "connection")]
9pub(crate) mod encryption;
10pub mod fixed_types;
11#[cfg(feature = "ppac")]
12#[cfg_attr(docsrs, doc(cfg(feature = "ppac")))]
13pub mod ppac;
14pub mod protocol;
15
16#[doc(hidden)]
17pub mod derive_reexports;
18
19#[cfg(feature = "connection")]
20#[cfg_attr(docsrs, doc(cfg(feature = "connection")))]
21pub use connection::{Connection, PrivateKey, PublicKey};
22
23pub use asciistring::AsciiString;
24
25/// Derive macro for [`protocol::ProtocolRW`].
26///
27/// # Note
28/// This macro makes few assumtions about the protocol enum:
29/// - All packet must either have no fields or only one with a type that implements
30///   [`protocol::PacketReadWrite`].
31/// - Raw packet must either have no fields or only one with a [`Vec<u8>`] inside.
32/// - Unknown packet must either have no fields or only one with a tuple of
33///   ([`protocol::PacketHeader`], [`Vec<u8>`]) inside.
34///
35/// # Attribute explanation
36/// - `#[Id(_id_, _subid_)]` sets the ID and subID of the packet variant.
37/// - `#[Empty]` marks the variant as empty, i.e. it will always return an empty vec.
38/// - `#[Raw]` marks the variant that will receive raw data if requested.
39/// - `#[Unknown]` marks the variant that will receive unknown packets.
40/// - `#[NGS]` marks the packet as NGS-only.
41/// - `#[Classic]` marks the packet as classic only, i.e. non-NGS packet (Vita, JP, NA).
42/// - `#[NA]` marks the packet as NA classic only.
43/// - `#[JP]` marks the packet as JP classic only.
44/// - `#[Vita]` marks the packet as Vita only.
45/// - `#[Category(_category_)]` sets the category of all the packets following this attribute.
46#[cfg(feature = "derive")]
47#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
48pub use pso2packetlib_impl::ProtocolRW;
49
50/// Derive macro for [`protocol::PacketReadWrite`].
51///
52/// # Note
53/// This macro makes few assumtions about the packet struct:
54/// - The only container type currently allowed is [`Vec<T>`].
55/// - Any type that is not hardcoded (i.e integers, floats, [`half::f16`], [`std::net::Ipv4Addr`],
56///   [`std::time::Duration`], [`String`], [`AsciiString`]) must implement
57///   [`protocol::HelperReadWrite`] or have the `read`, `write` functions with the same prototype.
58///
59/// # Attribute explanation
60/// ## Container attributes
61/// - `#[Id(_id_, _subid_)]` sets the ID and subID of the packet.
62/// - `#[Flags(_`[`protocol::Flags`]`_)]` sets the flags of the packet.
63/// - `#[Magic(_xor_, _sub_)]`. If the `packed` flag is set, then this attribute sets the
64///   deciphering xor and sub for variable length types.
65/// ## Field attributes
66/// - `#[Seek(_seek-amount_)]` sets the padding before the field data.
67/// - `#[SeekAfter(_seek-amount_)]` sets the padding after the field data.
68/// - `#[Const_u16(_const-int_)]` sets the constant u16 before the field data.
69/// - `#[OnlyOn(_`[`protocol::PacketType`]`_)]`. If set then the field will only be read/written if
70///   the reader packet type matches the specified packet type.
71/// - `#[NotOn(_`[`protocol::PacketType`]`_)]`. If set then the field will only be read/written if
72///   the reader packet type differs from the specified packet type.
73#[cfg(feature = "derive")]
74#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
75pub use pso2packetlib_impl::PacketRW;
76
77/// Derive macro for [`protocol::HelperReadWrite`].
78///
79/// # Note
80/// This macro makes few assumtions about
81/// 1) the packet struct:
82/// - Any type must implement [`protocol::HelperReadWrite`].
83/// 2) the flags struct:
84/// - All fields must be of type [`bool`]
85/// 3) the variant enum:
86/// - None of the fields must contain any data.
87/// - `#[repr(_)]` must be set to an integer.
88/// - Enum must implement [`Copy`].
89///
90/// # Attribute explanation
91/// ## Container attributes
92/// - `#[Flags(u*)]` makes the struct into a flags struct with the specified length.
93/// - `#[BitFlags(u*)]` adds read/write support for [`bitflags`] flags containers.
94/// ## Field attributes
95/// - `#[Seek(_seek-amount_)]` sets the padding before the field data.
96/// - `#[SeekAfter(_seek-amount_)]` sets the padding after the field data.
97/// - `#[Const_u16(_const-int_)]` sets the constant u16 before the field data.
98/// - `#[Read_default]` sets the default enum variant for reading.
99/// - `#[Skip]`. If applied to a field struct field, then this attribute will skip one bit of the
100///   flags.
101/// - `#[ManualRW(_readfn_, _writefn_)]` sets the read/write functions for the variant. Specified
102///   functions must have the same prototype as the [`protocol::HelperReadWrite`] functions.
103/// - `#[OnlyOn(_`[`protocol::PacketType`]`_)]`. If set then the field will only be read/written if
104///   the reader packet type matches the specified packet type.
105/// - `#[NotOn(_`[`protocol::PacketType`]`_)]`. If set then the field will only be read/written if
106///   the reader packet type differs from the specified packet type.
107#[cfg(feature = "derive")]
108#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
109pub use pso2packetlib_impl::HelperRW;
110
111#[cfg(docsrs)]
112pub mod protocol_docs;