mirror of
https://github.com/lbl8603/vnts.git
synced 2025-12-24 12:47:51 +08:00
和vnt保持一致
This commit is contained in:
@@ -30,14 +30,15 @@ pub mod service_packet;
|
||||
|
||||
#[derive(Eq, PartialEq, Copy, Clone, Debug)]
|
||||
pub enum Version {
|
||||
V1,
|
||||
V2,
|
||||
Unknown(u8),
|
||||
}
|
||||
|
||||
impl From<u8> for Version {
|
||||
fn from(value: u8) -> Self {
|
||||
match value {
|
||||
1 => Version::V1,
|
||||
// 版本从2开始,用于和stun协议的binging响应区分开
|
||||
2 => Version::V2,
|
||||
val => Version::Unknown(val),
|
||||
}
|
||||
}
|
||||
@@ -46,7 +47,7 @@ impl From<u8> for Version {
|
||||
impl From<Version> for u8 {
|
||||
fn from(val: Version) -> Self {
|
||||
match val {
|
||||
Version::V1 => 1,
|
||||
Version::V2 => 2,
|
||||
Version::Unknown(val) => val,
|
||||
}
|
||||
}
|
||||
@@ -210,8 +211,8 @@ impl<B: AsRef<[u8]> + AsMut<[u8]>> NetPacket<B> {
|
||||
self.buffer.as_mut()[0] = self.buffer.as_ref()[0] & 0xBF
|
||||
};
|
||||
}
|
||||
pub fn set_version(&mut self, version: Version) {
|
||||
let v: u8 = version.into();
|
||||
pub fn set_default_version(&mut self) {
|
||||
let v: u8 = Version::V2.into();
|
||||
self.buffer.as_mut()[0] = (self.buffer.as_ref()[0] & 0xF0) | (0x0F & v);
|
||||
}
|
||||
pub fn set_protocol(&mut self, protocol: Protocol) {
|
||||
|
||||
@@ -5,7 +5,7 @@ pub enum Protocol {
|
||||
/// 注册响应
|
||||
RegistrationResponse,
|
||||
/// 拉取设备列表
|
||||
PollDeviceList,
|
||||
PullDeviceList,
|
||||
/// 推送设备列表
|
||||
PushDeviceList,
|
||||
/// 和服务端握手
|
||||
@@ -23,7 +23,7 @@ impl From<u8> for Protocol {
|
||||
match value {
|
||||
1 => Self::RegistrationRequest,
|
||||
2 => Self::RegistrationResponse,
|
||||
3 => Self::PollDeviceList,
|
||||
3 => Self::PullDeviceList,
|
||||
4 => Self::PushDeviceList,
|
||||
5 => Self::HandshakeRequest,
|
||||
6 => Self::HandshakeResponse,
|
||||
@@ -40,7 +40,7 @@ impl From<Protocol> for u8 {
|
||||
match val {
|
||||
Protocol::RegistrationRequest => 1,
|
||||
Protocol::RegistrationResponse => 2,
|
||||
Protocol::PollDeviceList => 3,
|
||||
Protocol::PullDeviceList => 3,
|
||||
Protocol::PushDeviceList => 4,
|
||||
Protocol::HandshakeRequest => 5,
|
||||
Protocol::HandshakeResponse => 6,
|
||||
|
||||
Reference in New Issue
Block a user