Class: Casper::Entity::ModuleBytes

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

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 = nil, args = []) ⇒ ModuleBytes

Returns a new instance of ModuleBytes.

Parameters:

  • module_bytes (String) (defaults to: nil)
  • args (Array<Array<DeployNamedArgument>>) (defaults to: [])


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

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

Instance Method Details

#get_argsObject



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

def get_args
  @args
end

#get_module_bytesObject



19
20
21
# File 'lib/entity/module_bytes.rb', line 19

def get_module_bytes
  @module_bytes
end

#get_tagObject



15
16
17
# File 'lib/entity/module_bytes.rb', line 15

def get_tag
  @tag
end

#set_arg(deploy_named_arg) ⇒ Object



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

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

#to_bytesObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/entity/module_bytes.rb', line 31

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)
end