Cache data types conversion
Hi Guys,
I've this :
- NodeJS example,
let buf = Buffer.from('02010605166E2A0923100950205450524F424520303030323730', 'hex')
let temper = buf.readInt16BE(7) / 100
- Python example,
import binascii
buf = binascii.a2b_hex('02010605166E2A0923100950205450524F424520303030323730')
temper = int.from_bytes(x[7:9],byteorder='big') / 100
what would be the equivalent of this using Cache scripts?
Thanks Guys
Product version: Caché 2014.1
Hi @Rochdi Badis
With COS I don't know if is possible to do what you need. If you are using Ensemble, you can try to to achieve your needs using JavaGateway.
Some useful links:
https://www.baeldung.com/java-byte-arrays-hex-strings
https://stackoverflow.com/questions/7619058/convert-a-byte-array-to-integer-in-java-and-vice-versa
Let we know how you resolved this.
Regards.
set bufHex = "02010605166E2A0923100950205450524F424520303030323730" set buf = "" for i=1:2:$l(bufHex) set buf = buf _ $char($zhex($extract(bufHex, i, i+1))) write $sconvert(buf, "U2", /*big*/ 1, /*pos*/ 8) / 100
set buf = ##class(%xsd.hexBinary).JSONToLogical("02010605166E2A0923100950205450524F424520303030323730") write $sconvert(buf, "U2", /*big*/1, /*pos*/8) / 100
Well, if it was me, I'd keep that and the rest of my logic in JavaScript/Node.js and access the Cache database using the mg-dbx interface.