Skip to content
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

Implement Address #149

Closed
HaukeRa opened this issue Feb 1, 2019 · 3 comments
Closed

Implement Address #149

HaukeRa opened this issue Feb 1, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@HaukeRa
Copy link

HaukeRa commented Feb 1, 2019

Is your feature request related to a problem? Please describe.
All Addresses are represented as byte[] arrays. They are converted to int, whenever a comparision is needed. This can get a little anoying, especially when using the address as a key in a map, as byte[] can't be used as a key.

Describe the solution you'd like
A new type for addresses that implements equals() and hashCode() correctly.
Having a type not only makes handling of addresses easier, one can also add beneficial helper methods (e.g. isGroupAddress, isBroadcastAddress (0xFFFF), toString(--> AB CD), Parcelable, Database table for used group addresses)

@roshanrajaratnam roshanrajaratnam added the enhancement New feature or request label Feb 5, 2019
roshanrajaratnam added a commit that referenced this issue Feb 20, 2019
* Added helper class for mesh addresses

* Use int instead of byte[] for Address

* Refactoring all addresses to use a 16-bit int instead of byte[]. This will allow to use the address as a key in as it might be useful when dealing with a list of nodes. Some of the api has been marked deprecated to be removed in the upcoming versions.

* Fixes serialization/deserialization issues relating to data migration.

* Remove unused classes

* Fixes some bugs related to serialization and deserialization.
@HaukeRa
Copy link
Author

HaukeRa commented Mar 1, 2019

Great to see progress here!

Two comments:

  1. While a single Integer is definitely more usable than a byte array, it still is prone to errors. An int is easily mistaken for something else and basically needs a consistency check (i.e. valid ranges, reserved values group vs unicast etc.) in every place where it is finally used. When converting it to an own type you only have to check in one place (during construction) and get fail-fast behaviour (also during construction and not when actually using the address, probably somewhere else in the code with no direct execution path between declaration and use). Also it increases readability, compare: Map<Int, MeshModel> vs. Map<MeshAddress, MeshModel>

  2. Your practice of deprecating the functions implies that they are still usable. But here most of the methods using an byte array are not used anymore. Simply deprecating the methods could lead a developer into thinking they are still supported. The generated warning is easy to miss. I think in such a case it would be more helpful to actually delete them, as the use of them is effectively broken code. A compile error would be the right hint instead of "silently" compile.

@roshanrajaratnam
Copy link
Member

Thanks

  1. This was my initial plan, I defined types for each address types etc, however I ended up reverting because it was quite a big change and also considering the data migration required for this. Right now, all the checking is done (Hoping i haven't missed any) within the library just to make easier for the ones using the lib as a whole. I do not disagree with you on this.

  2. Well the idea to deprecate things over time is not to break anything overnight for the users whose upgrading and providing time to switch to the non-deprecated functions and as a practice using deprecated functions are never recommended (Although trying to keep things backward compatible). Also all deprecated functions will be removed pretty soon from the lib

@HaukeRa
Copy link
Author

HaukeRa commented Mar 4, 2019

  1. The changes needed spread through the whole code, true. Maybe its something that can be done in the future nonetheless. Still, not having to deal with byte arrays is a big win already.

  2. First I thought you did not implement any compatibility for Deprecated methods, but I figured out for some (most) of them you did. I need to check if I still find the methods that had no compatibility built in to still support the usage of them.

Anyhow: Data migration & deprecation is always tricky ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants