我想通过一个渠道传递一条消息.由于通道的实现,消息类型为bytes::Bytes
.
我要发送的消息是关于浮点数(Vec<{float}>
)的向量,我将其转换为如下形式:
let flatten_array: Vec<u8> = correct_centroids
.clone()
.into_iter()
.flat_map(|x| f32::to_le_bytes(x).to_vec().into_iter())
.collect();
let data = Bytes::from(flatten_array);
我的问题是,我如何才能将我得到的Vec<u8>
重新兑换成
又是Vec<{float}>
.
有没有其他更好的方法来序列化消息?