JsonObject values = new JsonObject(); for (Entry<Integer, ?> entry : rsc.getValues().entrySet()) { if (rsc.getType() == org.eclipse.leshan.core.model.ResourceModel.Type.OPAQUE) { values.add(entry.getKey().toString(), context.serialize(Hex.encodeHex((byte[]) entry.getValue()))); if (rsc.getType() == org.eclipse.leshan.core.model.ResourceModel.Type.OPAQUE) { element.add("value", context.serialize(Hex.encodeHex((byte[]) rsc.getValue()))); } else {
if (value.getType() != Type.STRING) { return WriteResponse.badRequest("invalid type"); if (value.getType() != Type.BOOLEAN) { return WriteResponse.badRequest("invalid type"); if (value.getType() != Type.INTEGER) { return WriteResponse.badRequest("invalid type"); if (value.getType() != Type.OPAQUE) { return WriteResponse.badRequest("invalid type"); return WriteResponse.success(); case SEC_SERVER_PUBKEY: // server public key if (value.getType() != Type.OPAQUE) { return WriteResponse.badRequest("invalid type"); return WriteResponse.success(); case SEC_SECRET_KEY: // Secret Key if (value.getType() != Type.OPAQUE) { return WriteResponse.badRequest("invalid type"); return WriteResponse.success(); case SEC_SERVER_ID: // short server id if (value.getType() != Type.INTEGER) { return WriteResponse.badRequest("invalid type");
Type expectedType = rSpec != null ? rSpec.type : resource.getType(); ArrayList<JsonArrayEntry> resourcesList = new ArrayList<>(); Object convertedValue = converter.convertValue(entry.getValue(), resource.getType(), expectedType, lwM2mResourceInstancePath); this.setResourceValue(convertedValue, expectedType, jsonResourceElt, lwM2mResourceInstancePath); this.setResourceValue(converter.convertValue(resource.getValue(), resource.getType(), expectedType, lwM2mResourcePath), expectedType, jsonResourceElt, lwM2mResourcePath);
private Tlv encodeResource(LwM2mResource resource, LwM2mPath resourcePath) { ResourceModel rSpec = model.getResourceModel(path.getObjectId(), resource.getId()); Type expectedType = rSpec != null ? rSpec.type : resource.getType(); Tlv rTlv; if (resource.isMultiInstances()) { Tlv[] instances = new Tlv[resource.getValues().size()]; int i = 0; for (Entry<Integer, ?> entry : resource.getValues().entrySet()) { LwM2mPath resourceInstancePath = resourcePath.append(entry.getKey()); Object convertedValue = converter.convertValue(entry.getValue(), resource.getType(), expectedType, resourceInstancePath); instances[i] = new Tlv(TlvType.RESOURCE_INSTANCE, null, this.encodeTlvValue(convertedValue, expectedType, resourceInstancePath), entry.getKey()); i++; } rTlv = new Tlv(TlvType.MULTIPLE_RESOURCE, instances, null, resource.getId()); } else { Object convertedValue = converter.convertValue(resource.getValue(), resource.getType(), expectedType, resourcePath); rTlv = new Tlv(TlvType.RESOURCE_VALUE, null, this.encodeTlvValue(convertedValue, expectedType, resourcePath), resource.getId()); } return rTlv; }
@Override public void visit(LwM2mResource resource) { if (resource.isMultiInstances()) { throw new CodecException("Multiple instances resource %s cannot be encoded in opaque format", path); } ResourceModel rSpec = model.getResourceModel(path.getObjectId(), resource.getId()); if (rSpec != null && rSpec.type != Type.OPAQUE) { throw new CodecException("Only single opaque resource can be encoded in opaque format. [%s]", path); } LOG.trace("Encoding resource {} into text", resource); Object value = converter.convertValue(resource.getValue(), resource.getType(), Type.OPAQUE, path); encoded = (byte[]) value; } }
if (value.getType() != Type.INTEGER) { return WriteResponse.badRequest("invalid type"); if (value.getType() != Type.INTEGER) { return WriteResponse.badRequest("invalid type"); if (value.getType() != Type.INTEGER) { return WriteResponse.badRequest("invalid type"); if (value.getType() != Type.INTEGER) { return WriteResponse.badRequest("invalid type"); if (value.getType() != Type.BOOLEAN) { return WriteResponse.badRequest("invalid type"); if (value.getType() != Type.STRING) { return WriteResponse.badRequest("invalid type");
} else if (n instanceof LwM2mResource) { LwM2mResource r = (LwM2mResource) n; o.add("type", r.getType().toString()); if (r.isMultiInstances()) { o.add("kind", "multipleResource"); JsonObject values = Json.object(); for (Entry<Integer, ?> value : r.getValues().entrySet()) { values.add(value.getKey().toString(), ValueSerDes.jSerialize(value.getValue(), r.getType())); o.add("value", ValueSerDes.jSerialize(r.getValue(), r.getType()));
} else if (n instanceof LwM2mResource) { LwM2mResource r = (LwM2mResource) n; o.add("type", r.getType().toString()); if (r.isMultiInstances()) { o.add("kind", "multipleResource"); JsonObject values = Json.object(); for (Entry<Integer, ?> value : r.getValues().entrySet()) { values.add(value.getKey().toString(), ValueSerDes.jSerialize(value.getValue(), r.getType())); o.add("value", ValueSerDes.jSerialize(r.getValue(), r.getType()));
format); } else { if (resource.getType() == Type.OPAQUE && format == ContentFormat.TEXT) { throw new InvalidRequestException( "Invalid format for path %s: TEXT format must not be used for byte array single resources", target); } else if (resource.getType() != Type.OPAQUE && format == ContentFormat.OPAQUE) { throw new InvalidRequestException( "Invalid format for path %s: OPAQUE format must be used only for byte array single resources",
format); } else { if (resource.getType() == Type.OPAQUE && format == ContentFormat.TEXT) { throw new InvalidRequestException( "Invalid format for %s: TEXT format must not be used for byte array single resources", target); } else if (resource.getType() != Type.OPAQUE && format == ContentFormat.OPAQUE) { throw new InvalidRequestException( "Invalid format for %s: OPAQUE format must be used only for byte array single resources",