Skip to content

Commit

Permalink
apply rustfmt formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
rkusa committed Jan 6, 2021
1 parent c6039ed commit 8540945
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 30 deletions.
2 changes: 1 addition & 1 deletion crates/datis-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use futures::future::FutureExt;
use futures::select;
use futures::sink::SinkExt;
use futures::stream::{SplitSink, StreamExt};
use srs::{Client, VoiceStream, message::Coalition};
use srs::{message::Coalition, Client, VoiceStream};
use tokio::runtime::{self, Runtime};
use tokio::sync::{oneshot, RwLock};
use tokio::time::delay_for;
Expand Down
6 changes: 3 additions & 3 deletions crates/srs/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::net::SocketAddr;
use std::sync::Arc;

use crate::message::{create_sguid, GameMessage, LatLngPosition, Coalition};
use crate::message::{create_sguid, Coalition, GameMessage, LatLngPosition};
use crate::voice_stream::{VoiceStream, VoiceStreamError};

use futures::channel::mpsc;
Expand All @@ -21,7 +21,7 @@ pub struct Client {
freq: u64,
pos: Arc<RwLock<LatLngPosition>>,
unit: Option<UnitInfo>,
pub coalition: Coalition
pub coalition: Coalition,
}

impl Client {
Expand All @@ -32,7 +32,7 @@ impl Client {
freq,
pos: Arc::new(RwLock::new(LatLngPosition::default())),
unit: None,
coalition
coalition,
}
}

Expand Down
45 changes: 22 additions & 23 deletions crates/srs/src/voice_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,25 +165,25 @@ impl Encoder<Packet> for VoiceCodec {
// Packet format as specified in
// https://github.com/ciribob/DCS-SimpleRadioStandalone/blob/1.9.3.0/DCS-SR-Common/Network/UDPVoicePacket.cs#L9
/*
* UDP PACKET LAYOUT
*
* - HEADER SEGMENT
* UInt16 Packet Length - 2 bytes
* UInt16 AudioPart1 Length - 2 bytes
* UInt16 FrequencyPart Length - 2 bytes
* - AUDIO SEGMENT
* Bytes AudioPart1 - variable bytes
* - FREQUENCY SEGMENT (one or multiple)
* double Frequency - 8 bytes
* byte Modulation - 1 byte
* byte Encryption - 1 byte
* - FIXED SEGMENT
* UInt UnitId - 4 bytes
* UInt64 PacketId - 8 bytes
* byte Retransmit / node / hop count - 1 byte
* Bytes / ASCII String TRANSMISSION GUID - 22 bytes used for transmission relay
* Bytes / ASCII String CLIENT GUID - 22 bytes
*/
* UDP PACKET LAYOUT
*
* - HEADER SEGMENT
* UInt16 Packet Length - 2 bytes
* UInt16 AudioPart1 Length - 2 bytes
* UInt16 FrequencyPart Length - 2 bytes
* - AUDIO SEGMENT
* Bytes AudioPart1 - variable bytes
* - FREQUENCY SEGMENT (one or multiple)
* double Frequency - 8 bytes
* byte Modulation - 1 byte
* byte Encryption - 1 byte
* - FIXED SEGMENT
* UInt UnitId - 4 bytes
* UInt64 PacketId - 8 bytes
* byte Retransmit / node / hop count - 1 byte
* Bytes / ASCII String TRANSMISSION GUID - 22 bytes used for transmission relay
* Bytes / ASCII String CLIENT GUID - 22 bytes
*/

// NOTE: the final packet will start with the total packet length, but this will be added
// by the inner fixed codec
Expand All @@ -192,10 +192,9 @@ impl Encoder<Packet> for VoiceCodec {
let audio_length = packet.audio_part.len();
let fixed_segment_length = 4 + 8 + 1 + 22 + 22;

let capacity =
header_length +
audio_length +
frequency_length * packet.frequencies.len()
let capacity = header_length
+ audio_length
+ frequency_length * packet.frequencies.len()
+ fixed_segment_length;
let mut wd = Cursor::new(Vec::with_capacity(capacity));

Expand Down
5 changes: 2 additions & 3 deletions crates/srs/src/voice_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use std::time::Duration;

use crate::client::Client;
use crate::message::{
Client as MsgClient, GameMessage, Message, MsgType, Radio, RadioInfo,
RadioSwitchControls,
Client as MsgClient, GameMessage, Message, MsgType, Radio, RadioInfo, RadioSwitchControls,
};
use crate::messages_codec::{self, MessagesCodec};
use crate::voice_codec::*;
Expand All @@ -26,7 +25,6 @@ use tokio::time;
use tokio_util::codec::{FramedRead, FramedWrite};
use tokio_util::udp::UdpFramed;

use std::default::Default;
const SRS_VERSION: &str = "1.9.0.0";

pub struct VoiceStream {
Expand Down Expand Up @@ -300,6 +298,7 @@ impl Sink<Vec<u8>> for VoiceStream {

impl Sink<VoicePacket> for VoiceStream {
type Error = mpsc::SendError;

fn poll_ready(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
let s = self.get_mut();
Pin::new(&mut s.voice_sink).poll_ready(cx)
Expand Down

0 comments on commit 8540945

Please sign in to comment.