[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
|
Re: [leshan-dev] Data type discrepancy: ResourceModel.Type vs Value.DataType
|
Hi Abel,
the reason for this is the fact that the LW M2M Spec considers integers of all sizes (8, 16, 32, 64 bit) just to be "Integer"s and all floats of all sizes (32, 64) and precision to be simply "Float"s whereas Java makes a difference according to the length/size of the numbers. The ResourceModel class reflects the spec's notion of how a resource has to be declared/defined whereas the Value class provides the mapping of a resource's type (according to the spec's type system) to and from the object's type used to hold the resource's value (according to Java's type system). In order to serialize a numeric Value instance to its minimal length binary representation (when using TLV), its type needs to be either discovered by means reflection or by keeping its data type as an explicit property (as currently implemented in the Value class). You might argue in favor of any of these approaches but this is the way it is implemented for now.
This is how the types are mapped to each other:
ResourceModel.Type Value.DataType Java Type
INTEGER (8, 16, 32 bit) INTEGER Integer
INTEGER (64 bit) LONG Long
FLOAT (32 bit) FLOAT Float
FLOAT (64 bit) DOUBLE Double
BOOLEAN BOOLEAN Boolean
STRING STRING String
TIME TIME Date
OPAQUE OPAQUE byte[]
Regards,
Kai
From: leshan-dev-bounces@xxxxxxxxxxx [mailto:leshan-dev-bounces@xxxxxxxxxxx] On Behalf Of Abel de Beer
Sent: Wednesday, October 14, 2015 4:54 PM
To: leshan-dev@xxxxxxxxxxx
Subject: [leshan-dev] Data type discrepancy: ResourceModel.Type vs Value.DataType
Hi all,
I've noticed a difference between data type support between org.eclipse.leshan.core.model.ResourceModel and org.eclipse.leshan.core.node.Value:
https://github.com/eclipse/leshan/blob/57e08f581f84b2dd6a9ffac64e12e08837050ea1/leshan-core/src/main/java/org/eclipse/leshan/core/model/ResourceModel.java#L39
Type enum contains: STRING, INTEGER, FLOAT, BOOLEAN, OPAQUE, TIME
https://github.com/eclipse/leshan/blob/57e08f581f84b2dd6a9ffac64e12e08837050ea1/leshan-core/src/main/java/org/eclipse/leshan/core/node/Value.java#L31
DataType enum contains: STRING, INTEGER, LONG, FLOAT, DOUBLE, BOOLEAN, OPAQUE, TIME
Is there a reason for this discrepancy? To me it makes the most sense for both objects to support the same types. If they do, maybe there should be one dedicated type enum to prevent confusion.
Thanks,
Abel de Beer
Cooking Fox
www.cookingfox.com