Skip to content

Commit

Permalink
Use upokecenter CBOR-JAVA as default encoder/decoder for SenML CBOR
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Dec 2, 2020
1 parent 294200a commit fad5a4c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.eclipse.leshan.core.node.codec.tlv.LwM2mNodeTlvDecoder;
import org.eclipse.leshan.core.request.ContentFormat;
import org.eclipse.leshan.core.util.Validate;
import org.eclipse.leshan.senml.cbor.jackson.SenMLCborJacksonEncoderDecoder;
import org.eclipse.leshan.senml.cbor.upokecenter.SenMLCborUpokecenterEncoderDecoder;
import org.eclipse.leshan.senml.json.jackson.SenMLJsonJacksonEncoderDecoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -60,7 +60,7 @@ public static Map<ContentFormat, NodeDecoder> getDefaultDecoders(boolean support
decoders.put(ContentFormat.TEXT, new LwM2mNodeTextDecoder());
decoders.put(ContentFormat.OPAQUE, new LwM2mNodeOpaqueDecoder());
decoders.put(ContentFormat.SENML_JSON, new LwM2mNodeSenMLDecoder(new SenMLJsonJacksonEncoderDecoder()));
decoders.put(ContentFormat.SENML_CBOR, new LwM2mNodeSenMLDecoder(new SenMLCborJacksonEncoderDecoder()));
decoders.put(ContentFormat.SENML_CBOR, new LwM2mNodeSenMLDecoder(new SenMLCborUpokecenterEncoderDecoder()));

// tlv
LwM2mNodeTlvDecoder tlvDecoder = new LwM2mNodeTlvDecoder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.eclipse.leshan.core.node.codec.tlv.LwM2mNodeTlvEncoder;
import org.eclipse.leshan.core.request.ContentFormat;
import org.eclipse.leshan.core.util.Validate;
import org.eclipse.leshan.senml.cbor.jackson.SenMLCborJacksonEncoderDecoder;
import org.eclipse.leshan.senml.cbor.upokecenter.SenMLCborUpokecenterEncoderDecoder;
import org.eclipse.leshan.senml.json.jackson.SenMLJsonJacksonEncoderDecoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -54,7 +54,7 @@ public static Map<ContentFormat, NodeEncoder> getDefaultEncoders(boolean support
encoders.put(ContentFormat.TEXT, new LwM2mNodeTextEncoder());
encoders.put(ContentFormat.OPAQUE, new LwM2mNodeOpaqueEncoder());
encoders.put(ContentFormat.SENML_JSON, new LwM2mNodeSenMLEncoder(new SenMLJsonJacksonEncoderDecoder()));
encoders.put(ContentFormat.SENML_CBOR, new LwM2mNodeSenMLEncoder(new SenMLCborJacksonEncoderDecoder()));
encoders.put(ContentFormat.SENML_CBOR, new LwM2mNodeSenMLEncoder(new SenMLCborUpokecenterEncoderDecoder()));

// tlv
LwM2mNodeTlvEncoder tlvDecoder = new LwM2mNodeTlvEncoder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public SenMLPack deserializeFromCbor(Collection<CBORObject> objects) throws SenM
if (eInteger.CanFitInInt64()) {
record.setFloatValue(eInteger.ToInt64Unchecked());
} else {
// There is maybe a better way to do that.
record.setFloatValue(ULong.valueOf(v.AsEInteger().toString()));
}
}
Expand Down Expand Up @@ -154,6 +155,7 @@ public byte[] serializeToCbor(SenMLPack pack) throws SenMLException {
}
// unsigned integer
else if (value instanceof ULong) {
// There is maybe a better way to do that.
cborRecord.Add(2, EInteger.FromString(value.toString()));
}
// floating-point
Expand Down

0 comments on commit fad5a4c

Please sign in to comment.