public ClientBlockContext(CoapBlockOption blockOption, CoapBlockSize maxBlocksize) {

      /* determine the right blocksize (min of remote and max)*/
      if (maxBlocksize == null) {
        blockSize = blockOption.getBlockSize();
      } else {
        int max = maxBlocksize.getSize();
        int remote = blockOption.getBlockSize().getSize();
        if (remote < max) {
          blockSize = blockOption.getBlockSize();
        } else {
          blockSize = maxBlocksize;
        }
      }
    }
    public boolean addBlock(CoapMessage msg, CoapBlockOption block) {
      int blockPos = block.getBytePosition();
      int blockLength = msg.getPayloadLength();
      int bufSize = payload.size();

      /*TODO: check if payload length = blocksize (except for the last block)*/
      if (blockPos > bufSize) {
        /* data is missing before this block */
        return false;
      } else if ((blockPos + blockLength) <= bufSize) {
        /* data already received */
        return false;
      }
      int offset = bufSize - blockPos;
      payload.write(msg.getPayload(), offset, blockLength - offset);

      if (block.isLast()) {
        /* was this the last block */
        finished = true;
      }

      return true;
    }