Skip to content

Commit

Permalink
Remove usage of deprecated API of Californium 3.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Feb 22, 2023
1 parent 3c4668b commit d7ed1cf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@
import org.eclipse.californium.core.coap.EmptyMessage;
import org.eclipse.californium.core.coap.Message;
import org.eclipse.californium.core.coap.Option;
import org.eclipse.californium.core.coap.OptionNumberRegistry;
import org.eclipse.californium.core.coap.Request;
import org.eclipse.californium.core.coap.Response;
import org.eclipse.californium.core.coap.Token;
import org.eclipse.californium.core.coap.option.OptionDefinition;
import org.eclipse.californium.core.coap.option.StandardOptionRegistry;
import org.eclipse.californium.core.network.serialization.DataParser;
import org.eclipse.californium.core.network.serialization.DataSerializer;
import org.eclipse.californium.core.network.serialization.UdpDataParser;
Expand Down Expand Up @@ -718,13 +719,23 @@ public String toString() {
final int end = numbers.length - 1;
int index = 0;
for (; index < end; ++index) {
result.append(OptionNumberRegistry.toString(numbers[index])).append(",");
result.append(getOption(numbers[index])).append(",");
}
result.append(OptionNumberRegistry.toString(numbers[index]));
result.append(getOption(numbers[index]));
}
result.append(']');
return result.toString();
}

private String getOption(int optionNumber) {
OptionDefinition definition = StandardOptionRegistry.getDefaultOptionRegistry()
.getDefinitionByNumber(optionNumber);
if (definition != null) {
return definition.toString();
} else {
return String.format("Unknown (%d)", optionNumber);
}
}
});
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
import org.eclipse.californium.core.coap.CoAP.Type;
import org.eclipse.californium.core.coap.EmptyMessage;
import org.eclipse.californium.core.coap.Option;
import org.eclipse.californium.core.coap.OptionNumberRegistry;
import org.eclipse.californium.core.coap.OptionSet;
import org.eclipse.californium.core.coap.Request;
import org.eclipse.californium.core.coap.Response;
import org.eclipse.californium.core.coap.option.OptionDefinition;
import org.eclipse.californium.core.coap.option.StandardOptionRegistry;
import org.eclipse.leshan.core.util.Hex;

public class CoapMessage {
Expand Down Expand Up @@ -82,7 +83,7 @@ private CoapMessage(boolean incoming, Type type, int mId, String token, OptionSe
if (!opts.isEmpty()) {
Map<String, List<String>> optMap = new HashMap<>();
for (Option opt : opts) {
String strOption = OptionNumberRegistry.toString(opt.getNumber());
String strOption = getOption(opt.getNumber());
List<String> values = optMap.get(strOption);
if (values == null) {
values = new ArrayList<>();
Expand Down Expand Up @@ -111,4 +112,14 @@ private CoapMessage(boolean incoming, Type type, int mId, String token, OptionSe
}
}
}

private String getOption(int optionNumber) {
OptionDefinition definition = StandardOptionRegistry.getDefaultOptionRegistry()
.getDefinitionByNumber(optionNumber);
if (definition != null) {
return definition.toString();
} else {
return String.format("Unknown (%d)", optionNumber);
}
}
}

0 comments on commit d7ed1cf

Please sign in to comment.