-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure that LwM2M node is created with valid ID
- Loading branch information
1 parent
6224546
commit 998873d
Showing
9 changed files
with
106 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
leshan-core/src/main/java/org/eclipse/leshan/core/node/LwM2mNodeUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 Sierra Wireless and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.html. | ||
* | ||
* Contributors: | ||
* Sierra Wireless - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.leshan.core.node; | ||
|
||
public class LwM2mNodeUtil { | ||
|
||
public static boolean isUnsignedInt(Integer id) { | ||
return id != null && 0 <= id && id <= 65535; | ||
} | ||
|
||
public static boolean isValidObjectId(Integer id) { | ||
return isUnsignedInt(id); | ||
} | ||
|
||
public static void validateObjectId(Integer id) { | ||
if (!isValidObjectId(id)) { | ||
throw new IllegalArgumentException(String.format("Invalid object id %d, It MUST be an unsigned int.", id)); | ||
} | ||
} | ||
|
||
public static boolean isValidObjectInstanceId(Integer id) { | ||
// MAX_ID 65535 is a reserved value and MUST NOT be used for identifying an Object Instance. | ||
return id != null && 0 <= id && id <= 65534; | ||
} | ||
|
||
public static void validateObjectInstanceId(Integer id) { | ||
if (!isValidObjectInstanceId(id)) { | ||
throw new IllegalArgumentException(String | ||
.format("Invalid object instance id %d, It MUST be an unsigned int. (65535 is reserved)", id)); | ||
} | ||
} | ||
|
||
public static boolean isValidResourceId(Integer id) { | ||
return isUnsignedInt(id); | ||
} | ||
|
||
public static void validateResourceId(Integer id) { | ||
if (!isValidResourceId(id)) { | ||
throw new IllegalArgumentException( | ||
String.format("Invalid resource id %d, It MUST be an unsigned int.", id)); | ||
} | ||
} | ||
|
||
public static boolean isValidResourceInstanceId(Integer id) { | ||
return isUnsignedInt(id); | ||
} | ||
|
||
public static void validateResourceInstanceId(Integer id) { | ||
if (!isValidResourceInstanceId(id)) { | ||
throw new IllegalArgumentException( | ||
String.format("Invalid resource instance id %d, It MUST be an unsigned int.", id)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters