Skip to content

Commit

Permalink
#1140:RegistrationSerDes must support availableInstances of registration
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Nov 4, 2021
1 parent 3caf38f commit eaf1da7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.leshan.core.LwM2m.LwM2mVersion;
import org.eclipse.leshan.core.link.Link;
import org.eclipse.leshan.core.link.LinkParamValue;
import org.eclipse.leshan.core.node.LwM2mPath;
import org.eclipse.leshan.core.request.BindingMode;
import org.eclipse.leshan.core.request.ContentFormat;
import org.eclipse.leshan.server.registration.Registration;
Expand Down Expand Up @@ -97,6 +98,13 @@ public static JsonNode jSerialize(Registration r) {
}
o.set("suppObjs", so);

// handle available instances
ArrayNode ai = JsonNodeFactory.instance.arrayNode();
for (LwM2mPath instance : r.getAvailableInstances()) {
ai.add(instance.toString());
}
o.set("objInstances", ai);

// handle application data
ObjectNode ad = JsonNodeFactory.instance.objectNode();
for (Entry<String, String> appData : r.getApplicationData().entrySet()) {
Expand Down Expand Up @@ -161,7 +169,7 @@ public static Registration deserialize(JsonNode jObj) {
}
b.objectLinks(linkObjs);

// additional attributes
// parse additional attributes
Map<String, String> addAttr = new HashMap<>();
ObjectNode o = (ObjectNode) jObj.get("addAttr");
for (Iterator<String> it = o.fieldNames(); it.hasNext();) {
Expand All @@ -170,10 +178,10 @@ public static Registration deserialize(JsonNode jObj) {
}
b.additionalRegistrationAttributes(addAttr);

// add supported content format
// parse supported content format
JsonNode ct = jObj.get("ct");
if (ct == null) {
// Backward compatibility : if suppObjs doesn't exist we extract supported object from object link
// Backward compatibility : if ct doesn't exist we extract supported content format from object link
b.extractDataFromObjectLink(true);
} else {
Set<ContentFormat> supportedContentFormat = new HashSet<>();
Expand All @@ -196,7 +204,20 @@ public static Registration deserialize(JsonNode jObj) {
b.supportedObjects(supportedObject);
}

// app data
// parse available instances
JsonNode ai = jObj.get("objInstances");
if (ai == null) {
// Backward compatibility : if objInstances doesn't exist we extract available instances from object link
b.extractDataFromObjectLink(true);
} else {
Set<LwM2mPath> availableInstances = new HashSet<>();
for (JsonNode aiPath : ai) {
availableInstances.add(new LwM2mPath(aiPath.asText()));
}
b.availableInstances(availableInstances);
}

// parse app data
Map<String, String> appData = new HashMap<>();
ObjectNode oap = (ObjectNode) jObj.get("appdata");
for (Iterator<String> it = oap.fieldNames(); it.hasNext();) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public void ser_and_des_are_equals() {
.supportedContentFormats(ContentFormat.TLV, ContentFormat.TEXT);

builder.registrationDate(new Date(100L));
builder.extractDataFromObjectLink(true);
builder.lastUpdate(new Date(101L));
Registration r = builder.build();

Expand Down Expand Up @@ -75,6 +76,7 @@ public void ser_and_des_are_equals_with_app_data() {

builder.registrationDate(new Date(100L));
builder.lastUpdate(new Date(101L));
builder.extractDataFromObjectLink(true);
Registration r = builder.build();

byte[] ser = RegistrationSerDes.bSerialize(r);
Expand Down

0 comments on commit eaf1da7

Please sign in to comment.