ZyGene
ZyGene

Reputation: 21

How to read data in Java from a Python Struck.pack

I am using Java UDP datagrampacket to receive a python packet which contains a Struct.pack string. How could I unpack it in Java?

Upvotes: 0

Views: 207

Answers (1)

Michael Butscher
Michael Butscher

Reputation: 10959

If you have the packet as byte[] array in Java, you can use java.io.java.io.ByteArrayInputStream to create an InputStream from it which can be wrapped by java.io.DataInputStream which provides methods to read several simple datatypes.

Be aware that DataInputStream works with big endian. If you use little endian some byte juggling will be necessary for multi-byte integer types.

Upvotes: 1

Related Questions