Hi Chris, you are right with what I want to do, let me explain my motivation. Your example is right but I think there are many situations where this is not sufficient, especially with regards to the new Address Syntax for S7. Basically the new syntax allows me to state something like this:
"I know that the value is 2 byte unsigned integer in little Endian Order and I want it back as Long". So the first idea was that I wanted to avoid having many methods for all combinations of Endianness, bit-length, Signed / Unsigned and Decimal / Float. And the second idea to also provide narrowing or widening or even conversion out of the box. I came across this issue when thinking about the migration of the current conversion in the S7 driver which is like a large if (XXX.class.isInstance(...)) else... and thought it would be better for the drive to just say something like parse(Class<?> target, byte[] in, Representation repr) to avoid the m times n problem for Java Types and byte Representation. But if you (and the other driver implementors) do not see this concern that much I can also shift my effort to something else. Best Julian Am 17.08.18, 14:41 schrieb "Christofer Dutz" <[email protected]>: Hi Julian, please let me repeat how I understood your proposal: You observed that in multiple drivers the conversion between byte-array data to the actual Java type is pretty similar and would like to wrap that mapping code in some commonly shared code base? I agree ... if a float is transformed as IEEE 754 Floating Point, it doesn't matter what driver this belongs to. But on the other side the code for doing this conversion too isn't that complex. I think in this case eventually even a class with static methods should be enough... sort of public static float parseIEEE754Float(byte[] in); public static int parseLE32BitInt(byte[] in); ... Maintaining a registry component that has to be injected into the drivers of type conversions where drivers can register custom converters sounds a little overkill to me. If a driver requires other conversions, it can implement them itself and if it makes sense to add them to the driver-base version, that code is simply moved there. What do you think? Chris Am 17.08.18, 14:14 schrieb "Julian Feinauer" <[email protected]>: Hey al, I like to open another discussion as I am currently working on another refactoring of the Drivers, namely the extraction of "binary" encoders and decoders as common concern. After our discussion about the addition of the binary representation to the S7 driver I observed that several drivers use very similar code to transform java types to byte representations of specific flavor (Big Endian, ...). Thus my aim is to provide a “library” of common encoders and decoders between Java Types and byte representations that every driver can use but also register custom Java Types and their representation (as it is e.g. needed for ADS, I think). Do you agree with this? Julian
