Answer the question
In order to leave comments, you need to log in
How to pass two parameters of different type to a method or how to cast int to byte?
Two variables of type Int and byte[]
int frame_len = init_frame().toByteArray().length;
byte [] frame_to_byte_array = init_frame().toByteArray();
...
public void write(byte[] message) {
try {
mmOutStream.write(message);
} catch (IOException e) {
}
}
...
...
sock.write(chr(len(data)) + data)
...
mConnectedThread.write(frame_len + frame_to_byte_array);
Answer the question
In order to leave comments, you need to log in
Я бы предложил сделать так:
public void write(byte[] message) {
try {
mmOutStream.write(message.length);
mmOutStream.write(message);
} catch (IOException e) {
}
}
byte[] frame_len = ByteBuffer.allocate(4).putInt(frame_to_byte_array.length).array();
int aLen = frame_len.length;
int bLen = frame_to_byte_array.length;
byte[] result = new byte[aLen+bLen];
System.arraycopy(frame_len, 0, result, 0, aLen);
System.arraycopy(frame_to_byte_array, 0, result, aLen, bLen);
mConnectedThread.write(result);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question