[−][src]Struct facio::raw_packet::RawPacket
Gives the underlying structure of a packet of any type. There are serialization and deserialization functions defined. No application level consistency is checked, besides that the body cannot be larger then 4086 (which is 4096-10).
Within the spec, only ASCII is allowed where in this implementation
the body is of type String
so generally UTF-8 is possible which the
server-side might not support when sticking to the protocol.
Entities of this type are introduced through the new
functions; they
calculate a suitable psize
according to the spec. The field psize
is
kept private; this library treats it as an implementation detail provided
by the spec.
Example
use facio::raw_packet::*; // create an auth packet with id `0` and `"mypass"` as password. let auth_request_packet = RawPacket::new_auth(0, "mypass").unwrap(); assert_eq!(auth_request_packet.pbody, "mypass"); assert_eq!(auth_request_packet.ptype, PacketType::RequestAuth.as_i32());
Fields
pid: i32
ptype: i32
pbody: String
Methods
impl RawPacket
[src]
pub fn new<T: Into<String>>(
id: i32,
raw_type: i32,
body: T
) -> Result<RawPacket, RawPacketCreationError>
[src]
id: i32,
raw_type: i32,
body: T
) -> Result<RawPacket, RawPacketCreationError>
Creates a new raw packet, which is consistent with the spec, expect
for the type, which is allowed to be any number. In other words: this
creates a RawPacket
with a suitable psize
.
pub fn serialize<T: Write>(&self, w: &mut T) -> Result<()>
[src]
Serialization according to the spec. This means:
- Write
psize
as little endiani32
. - Write
pid
as little endiani32
. - Write
ptype
as little endiani32
. - Write the body as null-terminated string.
- Add another null to end the packet.
Since String
isn't null-terminated, this null is added manually
after writing the body.
pub fn deserialize<T: Read>(r: &mut T) -> Result<RawPacket>
[src]
Deserialization according to the spec. See serialize
.
pub fn new_from_type<T: Into<String>>(
id: i32,
raw_body: T,
ptype: &PacketType
) -> Result<RawPacket, RawPacketCreationError>
[src]
id: i32,
raw_body: T,
ptype: &PacketType
) -> Result<RawPacket, RawPacketCreationError>
Provides the base line for all convenience functions to create packets of a specific type
using PacketType
.
Example
use facio::raw_packet::*; // create with id as stated in spec let exec_packet_generic = RawPacket::new(0, 2, "/version").unwrap(); // create using the `PacketType` enum let exec_packet_ftype = RawPacket::new_from_type(0, "/version", &PacketType::RequestExecCommand).unwrap(); // create using the convenience function let exec_packet_conv = RawPacket::new_exec(0, "/version").unwrap(); assert_eq!(exec_packet_generic, exec_packet_ftype); assert_eq!(exec_packet_ftype, exec_packet_conv); // and hence by transitivity ...
pub fn new_auth<T: Into<String>>(
id: i32,
pass: T
) -> Result<RawPacket, RawPacketCreationError>
[src]
id: i32,
pass: T
) -> Result<RawPacket, RawPacketCreationError>
pub fn new_exec<T: Into<String>>(
id: i32,
command: T
) -> Result<RawPacket, RawPacketCreationError>
[src]
id: i32,
command: T
) -> Result<RawPacket, RawPacketCreationError>
pub fn new_response_auth<T: Into<String>>(
id: i32,
value: T
) -> Result<RawPacket, RawPacketCreationError>
[src]
id: i32,
value: T
) -> Result<RawPacket, RawPacketCreationError>
pub fn new_response_value<T: Into<String>>(
id: i32,
value: T
) -> Result<RawPacket, RawPacketCreationError>
[src]
id: i32,
value: T
) -> Result<RawPacket, RawPacketCreationError>
pub fn response_type(&self) -> Option<PacketType>
[src]
Retrieves the ptype
as a PacketType
, where the packet is
seen as a response. (See PacketType
for more
information.)
pub fn request_type(&self) -> Option<PacketType>
[src]
Retrieves the ptype
as a PacketType
, where the packet is seen as a
request.
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,