1

I'm trying to build a little GUI with max/msp for a ruby project I can't find a way to properly convert the data i receive form max.

here is several examples of message that i've received from max in ruby (i've send 2 first then 1 0 -1 -2):

["int\x00,i\x00\x00\x00\x00\x00\x02", ["AF_INET", 53802, "127.0.0.1", "127.0.0.1"]]
["int\x00,i\x00\x00\x00\x00\x00\x01", ["AF_INET", 53802, "127.0.0.1", "127.0.0.1"]]
["int\x00,i\x00\x00\x00\x00\x00\x00", ["AF_INET", 53802, "127.0.0.1", "127.0.0.1"]]
["int\x00,i\x00\x00\xFF\xFF\xFF\xFF", ["AF_INET", 53802, "127.0.0.1", "127.0.0.1"]]
["int\x00,i\x00\x00\xFF\xFF\xFF\xFE", ["AF_INET", 53802, "127.0.0.1", "127.0.0.1"]]

so far i've been able to convert positive values to integer via String#ord or String#unpack but with those methods negative integers gives me 0 value

szymanowski
  • 1,359
  • 1
  • 14
  • 25

1 Answers1

2

You can easily do it with #unpack, using offset ('@8'), and 32-bit signed bigendian int ('l>')

str.unpack('@8l>')

I'm not sure what initial part of string means ("int\x00,i\x00\x00") and I have just ignored it with offset. It might need additional fiddling, if there is any important data.

samuil
  • 5,001
  • 1
  • 37
  • 44