I've been working on a minecraft server implementation in zig for a bit and I wanted to make a better packet parsing and handling system. I understand that sounds high level and not really help appropriate but I need help with understanding how something like this can be laid out in zig:
interface Packet
impl HandshakePacket {
field1: []const u8
field2: i32
}
fn readPacket(reader: std.net.Stream.Reader) Packet {
// return the interface but still retain ability to access the implementation and sort of "cast" it
}
I originally thought of using packed structs and using readStruct in std.net.Stream.Reader but because of how terrible the minecraft network protocol is ,they use different varints than the reader can read and I dont think its possible to implement it using a packed struct. Even if it was id still not know how to "cast" it and keep an abstracted type to return