Sha256: 03476bcf7fd17b0897eee7cef9f0b0db161a79a9a42c4ef63ba8c62ff3e190a4

Contents?: true

Size: 666 Bytes

Versions: 4

Compression:

Stored size: 666 Bytes

Contents

module SolanaRuby
  module DataTypes
    class Layout
      attr_reader :fields

      def initialize(fields)
        @fields = fields
      end

      def serialize(params)
        fields.flat_map do |field, type|
          data_type = type.is_a?(Symbol) ? SolanaRuby::DataTypes.send(type) : type
          data_type.serialize(params[field])
        end
      end

      def deserialize(bytes)
        result = {}
        fields.map do |field, type|
          data_type = type.is_a?(Symbol) ? SolanaRuby::DataTypes.send(type) : type
          result[field] = data_type.deserialize(bytes.shift(data_type.size))
        end
        result
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
solana-ruby-web3js-2.0.1 lib/solana_ruby/data_types/layout.rb
solana-ruby-web3js-2.0.0beta2 lib/solana_ruby/data_types/layout.rb
solana-ruby-web3js-2.0.0beta1 lib/solana_ruby/data_types/layout.rb
solana-ruby-web3js-2.0.0 lib/solana_ruby/data_types/layout.rb