Search in sources :

Example 11 with CodecException

use of org.eclipse.leshan.core.node.codec.CodecException in project leshan by eclipse.

the class LwM2mNodeTlvDecoder method parseTlvValues.

private static Map<Integer, Object> parseTlvValues(Tlv[] tlvs, Type expectedType, LwM2mPath path) throws CodecException {
    Map<Integer, Object> values = new HashMap<>();
    for (Tlv tlvChild : tlvs) {
        if (tlvChild.getType() != TlvType.RESOURCE_INSTANCE)
            throw new CodecException("Expected TLV of type RESOURCE_INSTANCE but was %s for path %s", tlvChild.getType().name(), path);
        Object resourceInstance = parseTlvValue(tlvChild.getValue(), expectedType, path);
        Object previousResourceInstance = values.put(tlvChild.getIdentifier(), resourceInstance);
        if (previousResourceInstance != null) {
            throw new CodecException("2 RESOURCE_INSTANCE (%s,%s) with the same identifier %d for path %s", previousResourceInstance, resourceInstance, tlvChild.getIdentifier(), path);
        }
    }
    return values;
}
Also used : HashMap(java.util.HashMap) LwM2mObject(org.eclipse.leshan.core.node.LwM2mObject) CodecException(org.eclipse.leshan.core.node.codec.CodecException) Tlv(org.eclipse.leshan.tlv.Tlv)

Aggregations

CodecException (org.eclipse.leshan.core.node.codec.CodecException)11 LwM2mPath (org.eclipse.leshan.core.node.LwM2mPath)6 HashMap (java.util.HashMap)4 LwM2mObject (org.eclipse.leshan.core.node.LwM2mObject)4 ResourceModel (org.eclipse.leshan.core.model.ResourceModel)3 Type (org.eclipse.leshan.core.model.ResourceModel.Type)3 LwM2mNode (org.eclipse.leshan.core.node.LwM2mNode)3 LwM2mObjectInstance (org.eclipse.leshan.core.node.LwM2mObjectInstance)3 JsonArrayEntry (org.eclipse.leshan.json.JsonArrayEntry)3 JsonRootObject (org.eclipse.leshan.json.JsonRootObject)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Map (java.util.Map)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 ResourceUtil.extractServerIdentity (org.eclipse.leshan.client.californium.impl.ResourceUtil.extractServerIdentity)2 ServerIdentity (org.eclipse.leshan.client.request.ServerIdentity)2 LwM2mModel (org.eclipse.leshan.core.model.LwM2mModel)2 LwM2mResource (org.eclipse.leshan.core.node.LwM2mResource)2 TimestampedLwM2mNode (org.eclipse.leshan.core.node.TimestampedLwM2mNode)2