/** * Decodes a byte array into a objlnk value. */ public static ObjectLink decodeObjlnk(byte[] value) throws TlvException { ByteBuffer bff = ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN); bff.put(value); int val1 = bff.getShort(0) & 0xFFFF; int val2 = bff.getShort(2) & 0xFFFF; return new ObjectLink(val1, val2); }
/** * Encodes a Objlnk value. */ public static byte[] encodeObjlnk(ObjectLink value) { ByteBuffer objlnkBuffer = ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN); objlnkBuffer.putShort(0, (short) value.getObjectId()); objlnkBuffer.putShort(2, (short) value.getObjectInstanceId()); return objlnkBuffer.array(); }
case OBJLNK: ObjectLink objlnk = (ObjectLink) val; strValue = String.valueOf(objlnk.getObjectId() + ":" + objlnk.getObjectInstanceId()); break; default:
/** * Create a Object Link referencing an object instance with the given path. */ public static ObjectLink fromPath(String path) { LwM2mPath lwM2mPath = new LwM2mPath(path); if (lwM2mPath.isRoot()) { return new ObjectLink(); // create null link } else if (lwM2mPath.isObjectInstance()) { return new ObjectLink(lwM2mPath.getObjectId(), lwM2mPath.getObjectInstanceId()); } else { throw new IllegalArgumentException("Invalid path: ObjectLink should reference an object instance"); } }
path); try { return new ObjectLink(Integer.parseInt(intArr[0]), Integer.parseInt(intArr[1])); } catch (NumberFormatException e) { throw new CodecException("Invalid value %s for objectLink resource [%s] ", Arrays.toString(intArr),