I’m new to Java and writing a program with its own network protocol via UDP/TCP. There’s such a packet in C:
struct test_package {
u32 cmd;
u32 args;
u32 flags;
};
Taking UDP as example, what I get from the DatagramPacket is byte data[]. How can I convert it to a package struct?
If in C, it’s just (struct test_package *)data if there’s no alignment restriction.
Thanks
Java does not provide direct memory access, so you cannot cast it to a structure as you can in C. You have to parse the byte array yourself, for example: