Module: Bitcoin::Message::InventoriesParser

Included in:
GetData, GetData, Inv, Inv, NotFound, NotFound
Defined in:
lib/bitcoin/message/inventories_parser.rb

Overview

Common message parser which only handle multiple inventory as payload.

Instance Method Summary collapse

Instance Method Details

#parse_from_payload(payload) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/bitcoin/message/inventories_parser.rb', line 7

def parse_from_payload(payload)
  size, payload = Bitcoin.unpack_var_int(payload)
  buf = StringIO.new(payload)
  i = new
  size.times do
    i.inventories << Inventory.parse_from_payload(buf.read(36))
  end
  i
end

#to_payloadObject



17
18
19
# File 'lib/bitcoin/message/inventories_parser.rb', line 17

def to_payload
  Bitcoin.pack_var_int(inventories.length) << inventories.map(&:to_payload).join
end