Comments (4)
@PFnord, @mgdlkundera, @jvermillard, @JaroslawLegierski any opinion about it ?
from leshan.
Is there a way where, if the number is received as an integer, to store it and use it as an integer, and if it's a float number, decode it as double?
I think if you try to use only double for those parameters you will have errors in strict equality with a lot of integer values
from leshan.
As I understand it those attributes are "Float" explained in an older spec (2018_OMA_SPEC in Data Types appendix):
Represented as a binary floating point value [IEEE 754-2008] [FLOAT]. The value may use the binary32 (4 byte length) or
binary64 (8 byte length) format as indicated by the Length field. When transmitted over network, the data is represented in
network byte order (big endian)
I would assume, treating a float attribute as double seems ok to me.
Spec specify we can have 64bit integers resources, which I would assume means we can have 64 bit integer attributes (or close to it). I would agree with @jvermillard and treat them as integer/long when possible?
from leshan.
As I understand it those attributes are "Float" explained in an older spec (2018_OMA_SPEC in Data Types appendix):
I understand the data type appendix is about LWM2M Resource typing, I don't think this is about attributes typing.
Spec specify we can have 64bit integers resources, which I would assume means we can have 64 bit integer attributes (or close to it).
During comparison this should be OK but as I said if someone send me a st=9223372036854775807, it will be converted in 9223372036854776000. In that case we can eventually raise an error or log a warning or change the code to support it.
Is there a way where, if the number is received as an integer, to store it and use it as an integer, and if it's a float number, decode it as double?
Not really, currently the attribute is strongly typed.
We can eventually change the type to :
String
and create corresponding number only when needed but if want to make validation handling String will be painful. (and probably less efficient than BigDecimal anyway)BigDecimal
from a design point of view this is the simple and more elegant one. (but with probably some memory usage overhead : http://javamoods.blogspot.com/2009/03/how-big-is-bigdecimal.html)Number
and try to create the smaller possible type without data loss but this will lead to a painful code and a not so easy to use API (mainly because Number abstraction in java abstract almost nothing ...). I'm not sure this kind of optimization really worth it. 😬
For now, I feel acceptable solutions could be :
- use BigDecimal to fully support it
- keep the Double limitation but warn or raise exception when we get a string value which can not be store in double.
Maybe moving to BigDecimal, is not so Bad ?
from leshan.
Related Issues (20)
- 🛡 Find a better alternative to dependabot ! HOT 1
- Did leshan bootstrap server support BLOCKWISE in CoAP HOT 1
- Try to get OpenSFF Badge HOT 1
- How are Observations stored on client side? HOT 27
- ObserveCompositeTimeStampTest failed when running with java 17+ HOT 1
- How to test a leshan-spring server and parse objects in californium? HOT 3
- Leshan server demo throws null-pointer exception HOT 14
- Replace usage of `URI` class to identify endpoint.
- Including timestamped send option to SendService HOT 3
- Use Leshan library to simulate several clients HOT 3
- Remove Attachement(or Assignation Level) to Attribute Model HOT 1
- Cannot run multiple server demo instances HOT 2
- Moving from JLine2 to JLine3 for leshan-client-demo Interactive commands.
- External Risk which could affect Leshan Project HOT 9
- No consistent value ordering for composite requests HOT 7
- How to know if a cliente Lwm2m 1.0 is availble HOT 5
- Add CoAP over TLS (over TCP) transport layer HOT 1
- Should Leshan client port be configurable? HOT 2
- Client is not registering on Server for Leshan version "2.0.0-M14" HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from leshan.