Class: Casper::Entity::ModuleBytes

Inherits:
DeployExecutableItemInternal show all
Defined in:
lib/entity/module_bytes.rb

Overview

Executable specified as raw bytes that represent Wasm code and an instance of RuntimeArgs.

Instance Attribute Summary

Attributes inherited from DeployExecutableItemInternal

#args

Instance Method Summary collapse

Methods inherited from DeployExecutableItemInternal

#get_arg_by_name

Constructor Details

#initialize(module_bytes, args = []) ⇒ ModuleBytes

Returns a new instance of ModuleBytes.

Parameters:



10
11
12
13
14
# File 'lib/entity/module_bytes.rb', line 10

def initialize(module_bytes, args = [])
  @tag = 0
  @module_bytes = module_bytes
  @args = args
end

Instance Method Details

#get_argsArray<DeployNamedArgument>

Returns an array of DeployNamedArgument objects.

Returns:



27
28
29
# File 'lib/entity/module_bytes.rb', line 27

def get_args
  @args
end

#get_module_bytesString

Returns the module bytes.

Returns:

  • (String)

    the module bytes



22
23
24
# File 'lib/entity/module_bytes.rb', line 22

def get_module_bytes
  @module_bytes
end

#get_tagInteger

Returns the tag value.

Returns:

  • (Integer)

    the tag value



17
18
19
# File 'lib/entity/module_bytes.rb', line 17

def get_tag
  @tag
end

#set_arg(deploy_named_arg) ⇒ Array<DeployNamedArgument>

Returns an array of DeployNamedArgument objects.

Parameters:

Returns:



33
34
35
# File 'lib/entity/module_bytes.rb', line 33

def set_arg(deploy_named_arg)
  @args << [deploy_named_arg]
end

#to_bytesArray<Integer>

Returns the byte serialization of ModuleByte object.

Returns:

  • (Array<Integer>)

    the byte serialization of ModuleByte object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/entity/module_bytes.rb', line 38

def to_bytes
  bytes = ""
  serializer = DeployNamedArgSerializer.new
  num_of_args = @args.length
  bytes += Utils::ByteUtils.to_u8(@tag)
  if @module_bytes == ""
    bytes += Utils::ByteUtils.to_u32(0)
  end
  bytes += Utils::ByteUtils.to_u32(num_of_args)
  @args.each do |arg|
    arg.each do |item|
      bytes += serializer.to_bytes(item)
    end
  end
  Utils::ByteUtils.hex_to_byte_array(bytes)
  # bytes
end