forked from auracaster/bumble_mirror
Add support for extended advertising via Rust-only API
* Extended functionality is gated on an "unstable" feature * Designed for very simple use and minimal interferance with existing legacy implementation * Intended to be temporary, until bumble can integrate extended advertising into its core functionality * Dropped `HciCommandWrapper` in favor of using bumble's `HCI_Command.from_bytes` for converting from PDL into bumble implementation * Refactored Address and Device constructors to better match what the python constructors expect
This commit is contained in:
@@ -94,7 +94,7 @@ impl From<Error> for PacketTypeParseError {
|
||||
|
||||
impl WithPacketType<Self> for Command {
|
||||
fn to_vec_with_packet_type(self) -> Vec<u8> {
|
||||
prepend_packet_type(PacketType::Command, self.to_vec())
|
||||
prepend_packet_type(PacketType::Command, self)
|
||||
}
|
||||
|
||||
fn parse_with_packet_type(bytes: &[u8]) -> Result<Self, PacketTypeParseError> {
|
||||
@@ -104,7 +104,7 @@ impl WithPacketType<Self> for Command {
|
||||
|
||||
impl WithPacketType<Self> for Acl {
|
||||
fn to_vec_with_packet_type(self) -> Vec<u8> {
|
||||
prepend_packet_type(PacketType::Acl, self.to_vec())
|
||||
prepend_packet_type(PacketType::Acl, self)
|
||||
}
|
||||
|
||||
fn parse_with_packet_type(bytes: &[u8]) -> Result<Self, PacketTypeParseError> {
|
||||
@@ -114,7 +114,7 @@ impl WithPacketType<Self> for Acl {
|
||||
|
||||
impl WithPacketType<Self> for Sco {
|
||||
fn to_vec_with_packet_type(self) -> Vec<u8> {
|
||||
prepend_packet_type(PacketType::Sco, self.to_vec())
|
||||
prepend_packet_type(PacketType::Sco, self)
|
||||
}
|
||||
|
||||
fn parse_with_packet_type(bytes: &[u8]) -> Result<Self, PacketTypeParseError> {
|
||||
@@ -124,7 +124,7 @@ impl WithPacketType<Self> for Sco {
|
||||
|
||||
impl WithPacketType<Self> for Event {
|
||||
fn to_vec_with_packet_type(self) -> Vec<u8> {
|
||||
prepend_packet_type(PacketType::Event, self.to_vec())
|
||||
prepend_packet_type(PacketType::Event, self)
|
||||
}
|
||||
|
||||
fn parse_with_packet_type(bytes: &[u8]) -> Result<Self, PacketTypeParseError> {
|
||||
@@ -132,7 +132,9 @@ impl WithPacketType<Self> for Event {
|
||||
}
|
||||
}
|
||||
|
||||
fn prepend_packet_type(packet_type: PacketType, mut packet_bytes: Vec<u8>) -> Vec<u8> {
|
||||
fn prepend_packet_type<T: Packet>(packet_type: PacketType, packet: T) -> Vec<u8> {
|
||||
// TODO: refactor if `pdl` crate adds API for writing into buffer (github.com/google/pdl/issues/74)
|
||||
let mut packet_bytes = packet.to_vec();
|
||||
packet_bytes.insert(0, packet_type.into());
|
||||
packet_bytes
|
||||
}
|
||||
|
||||
@@ -22,9 +22,8 @@ use bytes::Bytes;
|
||||
#[test]
|
||||
fn prepends_packet_type() {
|
||||
let packet_type = PacketType::Event;
|
||||
let packet_bytes = vec![0x00, 0x00, 0x00, 0x00];
|
||||
let actual = prepend_packet_type(packet_type, packet_bytes);
|
||||
assert_eq!(vec![0x04, 0x00, 0x00, 0x00, 0x00], actual);
|
||||
let actual = prepend_packet_type(packet_type, FakePacket { bytes: vec![0xFF] });
|
||||
assert_eq!(vec![0x04, 0xFF], actual);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -75,11 +74,15 @@ fn test_packet_roundtrip_with_type() {
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
struct FakePacket;
|
||||
struct FakePacket {
|
||||
bytes: Vec<u8>,
|
||||
}
|
||||
|
||||
impl FakePacket {
|
||||
fn parse(_bytes: &[u8]) -> Result<Self, Error> {
|
||||
Ok(Self)
|
||||
fn parse(bytes: &[u8]) -> Result<Self, Error> {
|
||||
Ok(Self {
|
||||
bytes: bytes.to_vec(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,6 +92,6 @@ impl Packet for FakePacket {
|
||||
}
|
||||
|
||||
fn to_vec(self) -> Vec<u8> {
|
||||
Vec::new()
|
||||
self.bytes
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user