CodeSOD: Once You Eliminate the Impossible… |
&Whatever remains, no matter how improbable, must be XML.
Developers have many weaknesses, among them this: they dont like to say that something cant be done. Thats why when Glenn Ms client, TelCo, asked if their request was really impossible, instead of apologizing and vigorously nodding his head, Glenn said, Well, technically&
And thats how he ended up writing this.
(?:0x)?([0-9a-fA-F][0-9a-fA-F])\s*([0-9a-fA-F][0-9a-fA-F])\s*([0-9a-fA-F][0-9a-fA-F])\s*([0-9a-fA-F][0-9a-fA-F])
.1.3.6.1.4.1.2011.2.217.1.4.1.1.6
%4$s%3$s%2$s%1$s
8388607
8388608
1
1
(?:0x)?([0-9a-fA-F][0-9a-fA-F])\s*([0-9a-fA-F][0-9a-fA-F])\s*([0-9a-fA-F][0-9a-fA-F])\s*([0-9a-fA-F][0-9a-fA-F])
.1.3.6.1.4.1.2011.2.217.1.4.1.1.6
%4$s%3$s%2$s%1$s
23
255
127
(?:0x)?([0-9a-fA-F][0-9a-fA-F])\s*([0-9a-fA-F][0-9a-fA-F])\s*([0-9a-fA-F][0-9a-fA-F])\s*([0-9a-fA-F][0-9a-fA-F])
.1.3.6.1.4.1.2011.2.217.1.4.1.1.6
%4$s%3$s%2$s%1$s
31
1
1
-1
1
Thats an XML DDF, a Data-Definition File for the systems-monitoring application Glenn supports. See, the system can read data from any device that supports the Modbus/TCP or SNMP protocols, as long as it has a DDF file that defines the data points and how theyre to be displayed. The DDF schema includes the arithmetic, boolean, regex, and conditional operators you see above, to let the system know how the data should be cleaned up.
Logic via XML? Thats a WTF all by itself, sure. But TRWTF is what that snippet above is actually doing. TelCo was monitoring a device that spat out temperature values (simple enough), but it presented them as an eight-character string representing the hexadecimal value of an IEEE754 32-bit floating-point number. The task that Glenn probably should have said was impossible was to cast that bizarre value back into its numeric equivalent. DDF, for all its awesome expressive power, lacked a typecast operator.
Thats why Glenn wrote the DDF shown above, which does this:
to put them back in an order we can work with
to convert from octetString to uint_32
and
to isolate the sign bit, exponent and mantissa
1 by that many
and other operators only accept 2 operands, these need to be nestedNext time, Glenn plans to stick to his guns, because he just heard that TelCo will be modifying their device to present temperature using integers.
http://thedailywtf.com/articles/once-you-eliminate-the-impossible-
Комментировать | « Пред. запись — К дневнику — След. запись » | Страницы: [1] [Новые] |