我有一个带有 UUID(16 字节)、一个 1 字节类型字段和 4 个包含浮点值的字节的二进制数据包。
如何用 nom 解析并得到一个元组(Uuid,u8,f32)?
use nom::{
combinator::map_res, number::complete::le_f32, number::complete::le_u128,
number::complete::le_u8, sequence::tuple, IResult,
};
use uuid;
fn detect(data: &[u8]) -> IResult<&[u8], (uuid::Uuid, u8, f32)> {
???
/* my attempt so far:
map_res(tuple((le_u128, le_u8, le_f32)), |tup| {
Ok((uuid::Uuid::from_u128(tup.0), tup.1, tup.2))
})(data)
*/
}
fn main() {
let pdu = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 200, 65,
];
let result = detect(&pdu);
println!("{:?}", result);
}
[dependencies]
nom = "5"
uuid = "0.8"