node = LwM2mSingleResource.newResource(id, deserializeValue(val, expectedType), expectedType); } else if (object.has("values")) {
Type type = Enum.valueOf(Type.class, jType); Object value = ValueSerDes.deserialize(o.get("value"), type); return LwM2mSingleResource.newResource(id, value, type);
public static LwM2mNode decode(byte[] content, LwM2mPath path, LwM2mModel model) throws CodecException { if (!path.isResource()) throw new CodecException("Invalid path %s : TextDecoder decodes resource only", path); ResourceModel rDesc = model.getResourceModel(path.getObjectId(), path.getResourceId()); String strValue = content != null ? new String(content, StandardCharsets.UTF_8) : ""; if (rDesc != null && rDesc.type != null) { return LwM2mSingleResource.newResource(path.getResourceId(), parseTextValue(strValue, rDesc.type, path), rDesc.type); } else { // unknown resource, returning a default string value return LwM2mSingleResource.newStringResource(path.getResourceId(), strValue); } }
Type type = Enum.valueOf(Type.class, jType); Object value = ValueSerDes.deserialize(o.get("value"), type); return LwM2mSingleResource.newResource(id, value, type);
LwM2mResource res = LwM2mSingleResource.newResource(nodePath.getResourceId(), parseJsonValue(resourceElt.getResourceValue(), expectedType, nodePath), expectedType); LwM2mResource previousRes = lwM2mResourceMap.put(nodePath.getResourceId(), res);
private static LwM2mResource parseResourceTlv(Tlv tlv, LwM2mPath resourcePath, LwM2mModel model) throws CodecException { Type expectedType = getResourceType(resourcePath, model); Integer resourceId = tlv.getIdentifier(); switch (tlv.getType()) { case MULTIPLE_RESOURCE: return LwM2mMultipleResource.newResource(resourceId, parseTlvValues(tlv.getChildren(), expectedType, resourcePath), expectedType); case RESOURCE_VALUE: return LwM2mSingleResource.newResource(resourceId, parseTlvValue(tlv.getValue(), expectedType, resourcePath), expectedType); default: throw new CodecException("Invalid TLV type %s for resource %s", tlv.getType(), resourcePath); } }