开发者

Is there something like C's struct in Java?

开发者 https://www.devze.com 2023-03-27 02:22 出处:网络
struct is necessary when you try to parse some file format like ELF, etc... Is there something like C\'s struct in Java?

struct is necessary when you try to parse some file format like ELF, etc...

Is there something like C's struct in Java?

Or can Java be开发者_运维技巧 used to parse ELF/binary format directly in the first place?


If you need a struct for grouping different data of the same type, Java has a class, and a class is better in logically grouping data than a struct because it includes operations on the data as well.

If you want to format ELF, then you may have to look at the "The ELF Parser" section in http://www.icsa.inf.ed.ac.uk/research/groups/hase/manuals/design/javahase.html. See also LibElf and GElf - A Library to Manipulate ELf Files (an old article)


Unfortunatly there is no decent support to read binary structured data in java.

This example reads image header into a byte array and assembles the required information.


There's ByteBuffer.

Edit

This is just to answer how you might parse the ELF format, which seemed to be what the OP was actually asking for.

For example (I assume this is the same format, apologies if it's a completely different ELF format, either way, it shows the same process):

http://jumdbrowser.googlecode.com/svn-history/r3/trunk/UmdBrowser/src/jpcsp/format/Elf32.java


Edit: answer to the first question

Java classes

0

精彩评论

暂无评论...
验证码 换一张
取 消