Hey,
I'm building a proxy that must deserialize and serialize external packets.
Previously, each packet had its own deserialization method which was insanely inefficient so I wanted to migrate to Serde + Bincode but I have an issue decoding some encoded values and especially varints.
I want to be able to do this :
#[derive(Packet, Deserialize)]
struct ExamplePacket {
some_string: String,
#[serde(deserialize_with = "deserialize_varint")]
some_int: i32,
}
From what I understand, I need to create a custom deserializer to support this encoding but Serde expects the length to be known before deserialization, which is impossible in this case since the only length indication is a bit in each byte telling if the next byte is a part of the value.
I've tried :
- Using deserialize_seq but it assumes the first byte is the length which in this case is wrong and we end up losing the first byte.
- Using deserialize_tuple but it requires the length, which is unknown.
- Using deserialize_bytes but I get an Unexpected EOF error, which might be due to length once again.
I've reached the point where I don't really know where to search anymore, so any help is gladly appreciated. Thanks!