简体   繁体   English

用 APDU 和 Boolean 重写函数

[英]Re writing Funcition with APDU & Boolean

I need some help我需要帮助

I need that this function return a boolean if while is executed or no.如果执行或不执行 while,我需要这个 function 返回 boolean。

Could you help me?你可以帮帮我吗?

Let us rewrite that APDU example from the API because it is clearly broken.让我们重写 API 中的 APDU 示例,因为它显然已损坏。 It will generate a separate request to receiveBytes when it is not required.它会在不需要时生成一个单独的receiveBytes请求。

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. while()循环中的if & break语句有点奇怪,但这是我能想到的唯一方法,一个地方处理 APDU 缓冲区中的数据,一个地方调用receiveBytes() This is because setIncomingAndReceive() includes a receiveBytes() within the call (ideas to create a normal while loop welcome).这是因为setIncomingAndReceive() receiveBytes() (欢迎创建普通while循环的想法)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM