examples/tcp_ip.rb in bindata-2.3.3 vs examples/tcp_ip.rb in bindata-2.3.4

- old
+ new

@@ -9,29 +9,27 @@ # # Present MAC addresses in a human readable way class MacAddr < BinData::Primitive - array :octets, :type => :uint8, :initial_length => 6 + array :octets, type: :uint8, initial_length: 6 def set(val) - ints = val.split(/\./).collect { |int| int.to_i } - self.octets = ints + self.octets = val.split(/\./).collect(&:to_i) end def get self.octets.collect { |octet| "%02x" % octet }.join(":") end end # Present IP addresses in a human readable way class IPAddr < BinData::Primitive - array :octets, :type => :uint8, :initial_length => 4 + array :octets, type: :uint8, initial_length: 4 def set(val) - ints = val.split(/\./).collect { |int| int.to_i } - self.octets = ints + self.octets = val.split(/\./).collect(&:to_i) end def get self.octets.collect { |octet| "%d" % octet }.join(".") end @@ -55,11 +53,11 @@ bit1 :syn bit1 :fin uint16 :window uint16 :checksum uint16 :urg_ptr - string :options, :read_length => :options_length_in_bytes + string :options, read_length: :options_length_in_bytes rest :payload def options_length_in_bytes (doff - 5 ) * 4 end @@ -78,11 +76,11 @@ # IP Protocol Data Unit class IP_PDU < BinData::Record endian :big - bit4 :version, :asserted_value => 4 + bit4 :version, asserted_value: 4 bit4 :header_length uint8 :tos uint16 :total_length uint16 :ident bit3 :flags @@ -90,13 +88,13 @@ uint8 :ttl uint8 :protocol uint16 :checksum ip_addr :src_addr ip_addr :dest_addr - string :options, :read_length => :options_length_in_bytes - buffer :payload, :length => :payload_length_in_bytes do - choice :payload, :selection => :protocol do + string :options, read_length: :options_length_in_bytes + buffer :payload, length: :payload_length_in_bytes do + choice :payload, selection: :protocol do tcp_pdu 6 udp_pdu 17 rest :default end end @@ -120,11 +118,11 @@ endian :big mac_addr :dst mac_addr :src uint16 :ether_type - choice :payload, :selection => :ether_type do + choice :payload, selection: :ether_type do ip_pdu IPV4 rest :default end end @@ -153,15 +151,15 @@ uint32 :sig_figs uint32 :snaplen uint32 :linktype end - array :records, :read_until => :eof do + array :records, read_until: :eof do uint32 :ts_sec uint32 :ts_usec uint32 :incl_len uint32 :orig_len - string :data, :length => :incl_len + string :data, length: :incl_len end end end require 'pp'