Class: SolanaRuby::DataTypes::Sequence

Inherits:
Object
  • Object
show all
Defined in:
lib/solana_ruby/data_types/sequence.rb

Instance Method Summary collapse

Constructor Details

#initialize(count, type) ⇒ Sequence

Returns a new instance of Sequence.



4
5
6
7
# File 'lib/solana_ruby/data_types/sequence.rb', line 4

def initialize count, type
  @count = count
  @type = type
end

Instance Method Details

#deserialize(bytes) ⇒ Object



15
16
17
18
19
20
# File 'lib/solana_ruby/data_types/sequence.rb', line 15

def deserialize bytes
  @count.times.map do
    current_bytes = bytes.shift(@type.size)
    @type.deserialize(current_bytes)
  end
end

#serialize(items) ⇒ Object



9
10
11
12
13
# File 'lib/solana_ruby/data_types/sequence.rb', line 9

def serialize items
  items.map do |item|
    @type.serialize(item)
  end.flatten
end