Let us rewrite that APDU example from the API because it is clearly broken. It will generate a separate request to receiveBytes when it is not required.
public boolean receiveIncomingFNEL(APDU apdu) {
byte[] buf = apdu.getBuffer();
short bytesRead = apdu.setIncomingAndReceive();
// NOTE: we must always call setIncomingAndReceive() first
short offsetCdata = apdu.getOffsetCdata();
short bytesLeft = apdu.getIncomingLength() - bytesRead;
boolean receiveBytesRequired = true;
while (true) {
// --- do something with the bytes in buf, offsetCdata and bytesRead here
if (bytesLeft <= 0) {
receiveBytesRequired = false;
break;
}
bytesRead = apdu.receiveBytes(offsetCdata);
bytesLeft -= bytesRead;
}
// --- do other stuff
return receiveBytesRequired;
}
The if & break statements in the while() loop are a bit weird, but that's the only way that I could think of to have one place handling the data in the APDU buffer and one part where receiveBytes() is called. This is because setIncomingAndReceive() includes a receiveBytes() within the call (ideas to create a normal while loop welcome).
Let us rewrite that APDU example from the API because it is clearly broken. It will generate a separate request to
receiveByteswhen it is not required.The
if&breakstatements in thewhile()loop are a bit weird, but that's the only way that I could think of to have one place handling the data in the APDU buffer and one part wherereceiveBytes()is called. This is becausesetIncomingAndReceive()includes areceiveBytes()within the call (ideas to create a normalwhileloop welcome).