java object members to bytearray
1 posts in topic
Flat View  Flat View

Posted By:   Anonymous
Posted On:   Monday, August 22, 2005 10:15 PM

Hi, say, we have a class like this:

class A {
byte b1[5];
byte b2[10];
byte b3[5][5];
class B {
byte b1[3];
byte b2[4];
B b4[5];

byte[] toByteArray() {

How can I implement the function toByteArray() for this class, that will return all the class members put together in the correct sequence. It should be a generic implementation so that I can use it for other similar classes also.
Can we use reflection somehow?

Re: java object members to bytearray

Posted By:   Almagest_FUTT  
Posted On:   Wednesday, August 24, 2005 09:57 AM

Sure, reflection would be an issue. However, i doubt you will have the fields in a "correct order" (if, as you imply, your order relies on variable name) automatically.

Furthermore, you can't really merge a byte[] and a byte[][] (or even a byte[][][]) together ...
About | Sitemap | Contact