resonator 0.3.2

This crate allows 2 devices to send live PCM audio data to each other through a server
Documentation
use crate::common::parsable::Parsable;
use crate::config::HANDSHAKE_BUFFER_SIZE;

#[derive(Debug)]
pub struct HandshakeData {
    pub id: i32,
    pub receive_port: u16,
    pub send_port: u16
}

impl HandshakeData {
    pub fn to_bytes(self) -> [u8; HANDSHAKE_BUFFER_SIZE] {
        let mut bytes: [u8; 8] = [0; 8];
        bytes[0..4].copy_from_slice(&self.id.to_le_bytes());
        bytes[4..6].copy_from_slice(&self.receive_port.to_le_bytes());
        bytes[6..8].copy_from_slice(&self.send_port.to_le_bytes());
        bytes
    }
}

impl Parsable<HandshakeData> for HandshakeData {
    /**

     * Parses a new HandshakeData using the provided byte data
     * Will ignore any bytes after the ones needed (8)
     */
    fn from_bytes(bytes: &[u8]) -> HandshakeData {
        HandshakeData {
            id: i32::from_le_bytes(bytes[0..4].try_into().unwrap()),
            receive_port: u16::from_le_bytes(bytes[4..6].try_into().unwrap()),
            send_port: u16::from_le_bytes(bytes[6..8].try_into().unwrap())
        }
    }
}