Question
Rochdi Badis · Nov 19

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
0
0 289
Discussion (4)3
Log in or sign up to continue
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.