11//! UUID types.
22
3- use bt_hci:: uuid:: { BluetoothUuid128 , BluetoothUuid16 } ;
3+ use bt_hci:: uuid:: { BluetoothUuid128 , BluetoothUuid16 , BluetoothUuid32 } ;
44
55use crate :: codec:: { Decode , Encode , Error , Type } ;
66
@@ -10,6 +10,8 @@ use crate::codec::{Decode, Encode, Error, Type};
1010pub enum Uuid {
1111 /// 16-bit UUID
1212 Uuid16 ( [ u8 ; 2 ] ) ,
13+ /// 32-bit UUID
14+ Uuid32 ( [ u8 ; 4 ] ) ,
1315 /// 128-bit UUID
1416 Uuid128 ( [ u8 ; 16 ] ) ,
1517}
@@ -20,6 +22,12 @@ impl From<BluetoothUuid16> for Uuid {
2022 }
2123}
2224
25+ impl From < BluetoothUuid32 > for Uuid {
26+ fn from ( data : bt_hci:: uuid:: BluetoothUuid32 ) -> Self {
27+ Uuid :: Uuid32 ( data. into ( ) )
28+ }
29+ }
30+
2331impl From < BluetoothUuid128 > for Uuid {
2432 fn from ( data : bt_hci:: uuid:: BluetoothUuid128 ) -> Self {
2533 Uuid :: Uuid128 ( data. into ( ) )
@@ -38,6 +46,18 @@ impl From<[u8; 16]> for Uuid {
3846 }
3947}
4048
49+ impl From < [ u8 ; 4 ] > for Uuid {
50+ fn from ( data : [ u8 ; 4 ] ) -> Self {
51+ Uuid :: Uuid32 ( data)
52+ }
53+ }
54+
55+ impl From < u32 > for Uuid {
56+ fn from ( data : u32 ) -> Self {
57+ Uuid :: Uuid32 ( data. to_le_bytes ( ) )
58+ }
59+ }
60+
4161impl From < [ u8 ; 2 ] > for Uuid {
4262 fn from ( data : [ u8 ; 2 ] ) -> Self {
4363 Uuid :: Uuid16 ( data)
@@ -65,6 +85,7 @@ impl Uuid {
6585 pub fn bytes ( & self , data : & mut [ u8 ] ) {
6686 match self {
6787 Uuid :: Uuid16 ( uuid) => data. copy_from_slice ( uuid) ,
88+ Uuid :: Uuid32 ( uuid) => data. copy_from_slice ( uuid) ,
6889 Uuid :: Uuid128 ( uuid) => data. copy_from_slice ( uuid) ,
6990 }
7091 }
@@ -73,13 +94,15 @@ impl Uuid {
7394 pub fn get_type ( & self ) -> u8 {
7495 match self {
7596 Uuid :: Uuid16 ( _) => 0x01 ,
76- Uuid :: Uuid128 ( _) => 0x02 ,
97+ Uuid :: Uuid32 ( _) => 0x02 ,
98+ Uuid :: Uuid128 ( _) => 0x03 ,
7799 }
78100 }
79101
80102 pub ( crate ) fn size ( & self ) -> usize {
81103 match self {
82104 Uuid :: Uuid16 ( _) => 6 ,
105+ Uuid :: Uuid32 ( _) => 8 ,
83106 Uuid :: Uuid128 ( _) => 20 ,
84107 }
85108 }
@@ -96,6 +119,7 @@ impl Uuid {
96119 pub fn as_raw ( & self ) -> & [ u8 ] {
97120 match self {
98121 Uuid :: Uuid16 ( uuid) => uuid,
122+ Uuid :: Uuid32 ( uuid) => uuid,
99123 Uuid :: Uuid128 ( uuid) => uuid,
100124 }
101125 }
@@ -108,6 +132,7 @@ impl TryFrom<&[u8]> for Uuid {
108132 match value. len ( ) {
109133 // Slice length has already been verified, so unwrap can be used
110134 2 => Ok ( Uuid :: Uuid16 ( value. try_into ( ) . unwrap ( ) ) ) ,
135+ 4 => Ok ( Uuid :: Uuid32 ( value. try_into ( ) . unwrap ( ) ) ) ,
111136 16 => {
112137 let mut bytes = [ 0 ; 16 ] ;
113138 bytes. copy_from_slice ( value) ;
0 commit comments