-
Notifications
You must be signed in to change notification settings - Fork 408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Encoder support for TimestampedLwM2mNodes #1246
Encoder support for TimestampedLwM2mNodes #1246
Conversation
To contribute to Eclipse foundation project, you need to sign an Eclipse Contributor Agreement using the email used in your commit. I just check for adam*****ski@****.com and it seems there is no valid ECA. See How to contribute code§Legal stuff for more details. Do not hesitate to ask if you have any issue. |
The solution for #1228 |
I just quickly check and there is formatting issue. (not a big deal this happens often with new contributor) Are you using eclipse as IDE ? About this, I tried to add a formatting check at maven level but for now this is not a success : #1107 |
I used Eclipse to format, should be fine now. |
leshan-core/src/main/java/org/eclipse/leshan/core/node/codec/DefaultLwM2mEncoder.java
Outdated
Show resolved
Hide resolved
...ation-tests/src/test/java/org/eclipse/leshan/integration/tests/send/SendTimestampedTest.java
Outdated
Show resolved
Hide resolved
internalEncoder.records.get(0).setBaseTime(timestamp); | ||
pack.addRecords(internalEncoder.records); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very cosmetic but maybe cleaner/easier to read to put internalEncoder result in a variable, then change the base time then use this variable to put in in pack
?
leshan-core/src/main/java/org/eclipse/leshan/core/node/codec/senml/LwM2mNodeSenMLEncoder.java
Outdated
Show resolved
Hide resolved
leshan-core/src/main/java/org/eclipse/leshan/core/node/codec/senml/LwM2mNodeSenMLEncoder.java
Outdated
Show resolved
Hide resolved
I fixed some cosmetics issue :
I also fixed something which looks like a bug introduced with your last commit : if (node != null) {
node.accept(internalEncoder);
- SenMLRecord record = internalEncoder.records.get(0);
- record.setBaseTime(timestamp);
- pack.addRecord(record);
+ List<SenMLRecord> records = internalEncoder.records;
+ if (!records.isEmpty()) {
+ records.get(0).setBaseTime(timestamp);
+ pack.addRecords(records);
+ }
} I also adapted the test case to detect this issue ☝️ : @Test
public void senml_json_encode_timestamped_nodes() throws CodecException {
TimestampedLwM2mNodes timestampedLwM2mNodes = TimestampedLwM2mNodes.builder()
.put(500_000_001L, new LwM2mPath(0, 0, 0), LwM2mSingleResource.newStringResource(0, "TestString"))
.put(500_000_002L, new LwM2mPath(0, 1),
new LwM2mObjectInstance(1, Arrays.asList(LwM2mSingleResource.newBooleanResource(1, true),
LwM2mSingleResource.newIntegerResource(2, 123))))
.build();
byte[] encoded = encoder.encodeTimestampedNodes(timestampedLwM2mNodes, ContentFormat.SENML_JSON, model);
String expectedString = new StringBuilder()
.append("[{\"bn\":\"/0/0/0\",\"bt\":500000001,\"vs\":\"TestString\"},") //
.append("{\"bn\":\"/0/1/\",\"bt\":500000002,\"n\":\"1\",\"vb\":true},") //
.append("{\"n\":\"2\",\"v\":123}]") //
.toString();
Assert.assertEquals(expectedString, new String(encoded));
} |
This is now integrated in |
No description provided.