I've written a bit-struct in Ruby:
class UnitHeader < BitStruct
default_options :endian => :little
unsigned :len, 16, "Length including header and all payload messages"
unsigned :msgCount, 8, "Number of messages in payload"
unsigned :group, 8, "group the payload messages relate to"
unsigned :seqNumStart, 32, "Sequence number of the first payload message"
end
I'd like to write this to a socket:
uh = UnitHeader.new
...
s = TCPSocket.new("127.0.0.1", 3000)
s.write(uh)
The s.write call doesn't seem to write any data. I've been unable to find anything on this issue in the documentation, is there a ruby operator or similar for this purpose?
The code you've presented should work properly. Your problem is probably located elsewhere. Here's how you can debug it to be sure:
nc -l 1234 > output, where 1234 is the port to listen on.hexdump output to look at the result, and compare it to your expected resultIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With