lib/bitcoin/protocol.rb in bitcoin-ruby-0.0.4 vs lib/bitcoin/protocol.rb in bitcoin-ruby-0.0.5

- old
+ new

@@ -81,9 +81,18 @@ size, payload = unpack_var_int(payload) return [nil, payload] if size == 0 [(0...size).map{ i, payload = unpack_var_int(payload); i }, payload] end + def self.unpack_boolean(payload) + bdata, payload = payload.unpack("Ca*") + [ (bdata == 0 ? false : true), payload ] + end + + def self.pack_boolean(b) + (b == true) ? [0xFF].pack("C") : [0x00].pack("C") + end + BINARY = Encoding.find('ASCII-8BIT') def self.pkt(command, payload) cmd = command.ljust(12, "\x00")[0...12] length = [payload.bytesize].pack("V")