Class: Casper::Entity::ModuleBytes
- Inherits:
-
DeployExecutableItemInternal
- Object
- DeployExecutableItemInternal
- Casper::Entity::ModuleBytes
- 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
Instance Method Summary collapse
-
#get_args ⇒ Array<DeployNamedArgument>
An array of DeployNamedArgument objects.
-
#get_module_bytes ⇒ String
The module bytes.
-
#get_tag ⇒ Integer
The tag value.
-
#initialize(module_bytes, args = []) ⇒ ModuleBytes
constructor
A new instance of ModuleBytes.
-
#set_arg(deploy_named_arg) ⇒ Array<DeployNamedArgument>
An array of DeployNamedArgument objects.
-
#to_bytes ⇒ Array<Integer>
The byte serialization of ModuleByte object.
Methods inherited from DeployExecutableItemInternal
Constructor Details
#initialize(module_bytes, args = []) ⇒ ModuleBytes
Returns a new instance of ModuleBytes.
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_args ⇒ Array<DeployNamedArgument>
Returns an array of DeployNamedArgument objects.
27 28 29 |
# File 'lib/entity/module_bytes.rb', line 27 def get_args @args end |
#get_module_bytes ⇒ String
Returns the module bytes.
22 23 24 |
# File 'lib/entity/module_bytes.rb', line 22 def get_module_bytes @module_bytes end |
#get_tag ⇒ Integer
Returns 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.
33 34 35 |
# File 'lib/entity/module_bytes.rb', line 33 def set_arg(deploy_named_arg) @args << [deploy_named_arg] end |
#to_bytes ⇒ Array<Integer>
Returns 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 |