Class: Sigma::Constant

Inherits:
Object
  • Object
show all
Extended by:
FFI::Library
Defined in:
lib/sigma/constant.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pointerObject

Returns the value of attribute pointer.



21
22
23
# File 'lib/sigma/constant.rb', line 21

def pointer
  @pointer
end

Class Method Details

.with_base_16(str) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/sigma/constant.rb', line 80

def self.with_base_16(str)
  c_ptr = FFI::MemoryPointer.new(:pointer)
  error = ergo_lib_constant_from_base16(str, c_ptr)
  Util.check_error!(error)

  init(c_ptr)
end

.with_bytes(bytes) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/sigma/constant.rb', line 30

def self.with_bytes(bytes)
  c_ptr = FFI::MemoryPointer.new(:pointer)
  b_ptr = FFI::MemoryPointer.new(:uint8, bytes.size)
  b_ptr.write_array_of_uint8(bytes)
  error = ergo_lib_constant_from_bytes(b_ptr, bytes.size, c_ptr)
  Util.check_error!(error)

  init(c_ptr)
end

.with_ecpoint_bytes(bytes) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/sigma/constant.rb', line 40

def self.with_ecpoint_bytes(bytes)
  c_ptr = FFI::MemoryPointer.new(:pointer)
  b_ptr = FFI::MemoryPointer.new(:uint8, bytes.size)
  b_ptr.write_array_of_uint8(bytes)
  error = ergo_lib_constant_from_ecpoint_bytes(b_ptr, bytes.size, c_ptr)
  Util.check_error!(error)

  init(c_ptr)
end

.with_ergo_box(ergo_box) ⇒ Object



23
24
25
26
27
28
# File 'lib/sigma/constant.rb', line 23

def self.with_ergo_box(ergo_box)
  c_ptr = FFI::MemoryPointer.new(:pointer)
  ergo_lib_constant_from_ergo_box(ergo_box.pointer, c_ptr)
  
  init(c_ptr)
end

.with_i32(int) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/sigma/constant.rb', line 64

def self.with_i32(int)
  pointer = FFI::MemoryPointer.new(:pointer)
  error = ergo_lib_constant_from_i32(int, pointer)
  # TODO: This raises error even with valid output
  #Util.check_error!(error)
  init(pointer)
end

.with_i64(int) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/sigma/constant.rb', line 72

def self.with_i64(int)
  pointer = FFI::MemoryPointer.new(:pointer)
  error = ergo_lib_constant_from_i64(int, pointer)
  # TODO: This raises error even with valid output
  #Util.check_error!(error)
  init(pointer)
end

.with_raw_pointer(constant_pointer) ⇒ Object



50
51
52
# File 'lib/sigma/constant.rb', line 50

def self.with_raw_pointer(constant_pointer)
  init(constant_pointer)
end

Instance Method Details

#==(constant_two) ⇒ Object



100
101
102
# File 'lib/sigma/constant.rb', line 100

def ==(constant_two)
  ergo_lib_constant_eq(self.pointer, constant_two.pointer)
end

#to_base16_stringObject



54
55
56
57
58
59
60
61
62
# File 'lib/sigma/constant.rb', line 54

def to_base16_string
  s_ptr = FFI::MemoryPointer.new(:pointer, 1)
  error = ergo_lib_constant_to_base16(self.pointer, s_ptr)
  Util.check_error!(error)
  s_ptr = s_ptr.read_pointer()
  str = s_ptr.read_string().force_encoding('UTF-8')
  Util.ergo_lib_delete_string(s_ptr)
  str
end

#to_i32Object



88
89
90
91
92
# File 'lib/sigma/constant.rb', line 88

def to_i32
  res = ergo_lib_constant_to_i32(self.pointer)
  Util.check_error!(res[:error])
  res[:value]
end

#to_i64Object



94
95
96
97
98
# File 'lib/sigma/constant.rb', line 94

def to_i64
  res = ergo_lib_constant_to_i64(self.pointer)
  Util.check_error!(res[:error])
  res[:value]
end