Answer the question
In order to leave comments, you need to log in
What is the most convenient way to emit a C (C ++) structure in java (under Android)?
Hello!
Data is transmitted to the android program via Bluetooth. Data represents large structures, which in C are described like this
struct
{
uint16_t data0;
uint32_t data1;
uint16_t data2;
.....
uint8_t dataN
}
Answer the question
In order to leave comments, you need to log in
In Java, it is common practice to read/write each variable separately from/to a DataInputStream/DataOutputStream. To read/write the whole structure, we create the methods writeTo(DataOutoutStream data), readFrom(DataInputStream data) and write all elements of the structure there, for example
public class SomeStruct {
public int i1;
public int i2;
public void writeTo(DataOutputStream data) {
data.writeInt(i1);
data.writeInt(i2);
}
public void readFrom(DataInputStream data) {
i1 = data.readInt();
i2 = data.readInt();
}
}
Integer.reverseBytes(i1);
it is not clear what you want to see on the android side, how you want to work with it in the future.
and what's the catch specifically?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question