org.eclipse.californium.core.coap.OptionSet.getBlock2()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(81)

本文整理了Java中org.eclipse.californium.core.coap.OptionSet.getBlock2()方法的一些代码示例,展示了OptionSet.getBlock2()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OptionSet.getBlock2()方法的具体详情如下:
包路径:org.eclipse.californium.core.coap.OptionSet
类名称:OptionSet
方法名:getBlock2

OptionSet.getBlock2介绍

[英]Returns the Block2 option as encoded object.
[中]将Block2选项作为编码对象返回。

代码示例

代码示例来源:origin: eclipse/californium

private static void earlyBlock2Negotiation(final Exchange exchange, final Request request) {
  // Call this method when a request has completely arrived (might have
  // been sent in one piece without blockwise).
  BlockOption block2 = request.getOptions().getBlock2();
  if (block2 != null) {
    BlockwiseStatus status2 = new BlockwiseStatus(request.getOptions().getContentFormat(), block2.getNum(), block2.getSzx());
    LOGGER.log(Level.FINE, "Request with early block negotiation {0}. Create and set new Block2 status: {1}", new Object[]{block2, status2});
    exchange.setResponseBlockStatus(status2);
  }
}

代码示例来源:origin: org.eclipse.californium/californium-core

private void earlyBlock2Negotiation(final Exchange exchange, final Request request) {
  // Call this method when a request has completely arrived (might have
  // been sent in one piece without blockwise).
  if (request.getOptions().hasBlock2()) {
    BlockOption block2 = request.getOptions().getBlock2();
    BlockwiseStatus status2 = new BlockwiseStatus(request.getOptions().getContentFormat(), block2.getNum(), block2.getSzx());
    LOGGER.fine("Request with early block negotiation "+block2+". Create and set new Block2 status: "+status2);
    exchange.setResponseBlockStatus(status2);
  }
}

代码示例来源:origin: eclipse/californium

@Override
  protected boolean checkResponse(Request request, Response response) {
    boolean success = response.getOptions().hasBlock2();

    if (!success) {
      System.out.println("FAIL: no Block2 option");
    } else {
      int maxNUM = response.getOptions().getBlock2().getNum();
      success &= checkType(Type.ACK, response.getType());
      success &= checkInt(EXPECTED_RESPONSE_CODE.value,
          response.getCode().value, "code");
      success &= checkOption(new BlockOption(PlugtestChecker.PLUGTEST_BLOCK_SZX,
          false, maxNUM), response.getOptions().getBlock2(),
          "Block2");
      success &= hasNonEmptyPalyoad(response);
      success &= hasContentType(response);
    }
    return success;
  }
}

代码示例来源:origin: eclipse/californium

@Override
  protected boolean checkResponse(Request request, Response response) {
    boolean success = response.getOptions().hasBlock2();

    if (!success) {
      System.out.println("FAIL: no Block2 option");
    } else {
      int maxNUM = response.getOptions().getBlock2().getNum();
      success &= checkType(Type.ACK, response.getType());
      success &= checkInt(EXPECTED_RESPONSE_CODE.value,
          response.getCode().value, "code");
      success &= checkOption(new BlockOption(EXPECTED_BLOCK_SIZE,
          false, maxNUM), response.getOptions().getBlock2(),
          "Block2");
      success &= hasNonEmptyPalyoad(response);
      success &= hasContentType(response);
    }
    return success;
  }
}

代码示例来源:origin: eclipse/californium

options.add(new Option(OptionNumberRegistry.BLOCK1, getBlock1().getValue()));
if (hasBlock2())
  options.add(new Option(OptionNumberRegistry.BLOCK2, getBlock2().getValue()));
if (hasSize1())
  options.add(new Option(OptionNumberRegistry.SIZE1, getSize1()));

代码示例来源:origin: org.eclipse.californium/californium-core

options.add(new Option(OptionNumberRegistry.BLOCK1, getBlock1().getValue()));
if (hasBlock2())
  options.add(new Option(OptionNumberRegistry.BLOCK2, getBlock2().getValue()));
if (hasSize1())
  options.add(new Option(OptionNumberRegistry.SIZE1, getSize1()));

代码示例来源:origin: eclipse/californium

protected final void appendRequestDetails(final Request request) {
  if (request.isCanceled()) {
    buffer.append("CANCELED ");
  }
  buffer.append(request.getType()).append(" [MID=").append(request.getMID())
    .append(", T=").append(request.getTokenString()).append("], ")
    .append(request.getCode()).append(", /").append(request.getOptions().getUriPathString());
  appendBlockOption(1, request.getOptions().getBlock1());
  appendBlockOption(2, request.getOptions().getBlock2());
  appendObserveOption(request.getOptions());
  appendSize1(request.getOptions());
  appendEtags(request.getOptions());
}

代码示例来源:origin: eclipse/californium

protected final void appendResponseDetails(final Response response) {
  if (response.isCanceled()) {
    buffer.append("CANCELED ");
  }
  buffer.append(response.getType()).append(" [MID=").append(response.getMID())
    .append(", T=").append(response.getTokenString()).append("], ")
    .append(response.getCode());
  appendBlockOption(1, response.getOptions().getBlock1());
  appendBlockOption(2, response.getOptions().getBlock2());
  appendObserveOption(response.getOptions());
  appendSize1(response.getOptions());
  appendSize2(response.getOptions());
  appendEtags(response.getOptions());
}

代码示例来源:origin: org.eclipse.californium/californium-core

@Override
public void sendRequest(final Exchange exchange, final Request request) {
  if (request.getOptions().hasBlock2() && request.getOptions().getBlock2().getNum() > 0) {
    // This is the case if the user has explicitly added a block option
    // for random access.
    // Note: We do not regard it as random access when the block num is
    // 0. This is because the user might just want to do early block
    // size negotiation but actually wants to receive all blocks.
    LOGGER.fine("Request carries explicit defined block2 option: create random access blockwise status");
    BlockwiseStatus status = new BlockwiseStatus(request.getOptions().getContentFormat());
    BlockOption block2 = request.getOptions().getBlock2();
    status.setCurrentSzx(block2.getSzx());
    status.setCurrentNum(block2.getNum());
    status.setRandomAccess(true);
    exchange.setResponseBlockStatus(status);
    super.sendRequest(exchange, request);
  } else if (requiresBlockwise(request)) {
    // This must be a large POST or PUT request
    LOGGER.fine("Request payload "+request.getPayloadSize()+"/"+max_message_size+" requires Blockwise");
    BlockwiseStatus status = findRequestBlockStatus(exchange, request);
    Request block = getNextRequestBlock(request, status);
    exchange.setRequestBlockStatus(status);
    exchange.setCurrentRequest(block);
    super.sendRequest(exchange, block);
  } else {
    exchange.setCurrentRequest(request);
    super.sendRequest(exchange, request);
  }
}

代码示例来源:origin: eclipse/californium

block = response.getOptions().getBlock2();
if (block != null) {
  handleBlock2Response(exchange, response, block);

代码示例来源:origin: eclipse/californium

BlockOption block2 = request.getOptions().getBlock2();
Response response = exchange.getResponse();
BlockwiseStatus status = findResponseBlockStatus(exchange, response);

代码示例来源:origin: eclipse/californium

@Override
public void sendRequest(final Exchange exchange, final Request request) {
  BlockOption block2 = request.getOptions().getBlock2();
  if (block2 != null && block2.getNum() > 0) {
    // This is the case if the user has explicitly added a block option
    // for random access.
    // Note: We do not regard it as random access when the block num is
    // 0. This is because the user might just want to do early block
    // size negotiation but actually wants to receive all blocks.
    LOGGER.fine("request contains block2 option, creating random-access blockwise status");
    BlockwiseStatus status = new BlockwiseStatus(getSizeForSzx(block2.getSzx()), request.getOptions().getContentFormat());
    status.setCurrentSzx(block2.getSzx());
    status.setCurrentNum(block2.getNum());
    status.setRandomAccess(true);
    exchange.setResponseBlockStatus(status);
    lower().sendRequest(exchange, request);
  } else if (requiresBlockwise(request)) {
    // This must be a large POST or PUT request
    startBlockwiseUpload(exchange, request);
  } else {
    // no blockwise transfer required
    exchange.setCurrentRequest(request);
    lower().sendRequest(exchange, request);
  }
}

代码示例来源:origin: eclipse/californium

Assert.assertEquals(expectations[i], response.getPayloadString());
Assert.assertTrue(response.getOptions().hasBlock2());
Assert.assertEquals(num, response.getOptions().getBlock2().getNum());
Assert.assertEquals(szx, response.getOptions().getBlock2().getSzx());

代码示例来源:origin: eclipse/californium

public void check(Message message) {
  assertTrue("No Block2 option:", message.getOptions().hasBlock2());
  BlockOption block2 = message.getOptions().getBlock2();
  assertEquals("Wrong Block2 num:", num, block2.getNum());
  assertEquals("Wrong Block2 m:", m, block2.isM());
  assertEquals("Wrong Block2 size:", size, block2.getSize());
  print("Correct Block2 option: " + block2);
}

代码示例来源:origin: org.eclipse.californium/californium-core

BlockOption block2 = request.getOptions().getBlock2();
Response response = exchange.getResponse();
BlockwiseStatus status = findResponseBlockStatus(exchange, response);

代码示例来源:origin: org.eclipse.californium/californium-core

BlockOption block2 = response.getOptions().getBlock2();
BlockwiseStatus status = findResponseBlockStatus(exchange, response);

相关文章

微信公众号

最新文章

更多