Class: Sigma::ErgoTree
- Inherits:
-
Object
- Object
- Sigma::ErgoTree
- Extended by:
- FFI::Library
- Defined in:
- lib/sigma/ergo_tree.rb
Instance Attribute Summary collapse
-
#pointer ⇒ Object
Returns the value of attribute pointer.
Class Method Summary collapse
Instance Method Summary collapse
- #==(ergo_tree_two) ⇒ Object
- #constants_length ⇒ Object
- #get_constant(index) ⇒ Object
- #replace_constant(index:, constant:) ⇒ Object
- #to_base16_encoded_string ⇒ Object
- #to_bytes ⇒ Object
- #to_template_bytes ⇒ Object
Instance Attribute Details
#pointer ⇒ Object
Returns the value of attribute pointer.
21 22 23 |
# File 'lib/sigma/ergo_tree.rb', line 21 def pointer @pointer end |
Class Method Details
.from_base16_encoded_string(encoded_str) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/sigma/ergo_tree.rb', line 27 def self.from_base16_encoded_string(encoded_str) pointer = FFI::MemoryPointer.new(:pointer) error = ergo_lib_ergo_tree_from_base16_bytes(encoded_str, pointer) Util.check_error!(error) init(pointer) end |
.with_raw_pointer(unread_pointer) ⇒ Object
23 24 25 |
# File 'lib/sigma/ergo_tree.rb', line 23 def self.with_raw_pointer(unread_pointer) init(unread_pointer) end |
Instance Method Details
#==(ergo_tree_two) ⇒ Object
92 93 94 |
# File 'lib/sigma/ergo_tree.rb', line 92 def ==(ergo_tree_two) ergo_lib_ergo_tree_eq(self.pointer, ergo_tree_two.pointer) end |
#constants_length ⇒ Object
65 66 67 68 69 |
# File 'lib/sigma/ergo_tree.rb', line 65 def constants_length res = ergo_lib_ergo_tree_constants_len(self.pointer) Util.check_error!(res[:error]) res[:value] end |
#get_constant(index) ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/sigma/ergo_tree.rb', line 71 def get_constant(index) pointer = FFI::MemoryPointer.new(:pointer) res = ergo_lib_ergo_tree_get_constant(self.pointer, index, pointer) Util.check_error!(res[:error]) if res[:is_some] Sigma::Constant.with_raw_pointer(pointer) else nil end end |
#replace_constant(index:, constant:) ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/sigma/ergo_tree.rb', line 82 def replace_constant(index:, constant:) pointer = FFI::MemoryPointer.new(:pointer) error = ergo_lib_ergo_tree_with_constant(self.pointer, index, constant.pointer, pointer) Util.check_error!(error) # Replace self.pointer with new ergo_tree pointer # Old pointer will be deleted when out of scope by GC self.class.init(pointer, obj: self) end |
#to_base16_encoded_string ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/sigma/ergo_tree.rb', line 35 def to_base16_encoded_string s_ptr = FFI::MemoryPointer.new(:pointer, 1) error = ergo_lib_ergo_tree_to_base16_bytes(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_bytes ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/sigma/ergo_tree.rb', line 45 def to_bytes res = ergo_lib_ergo_tree_bytes_len(self.pointer) Util.check_error!(res[:error]) bytes_length = res[:value] bytes_ptr = FFI::MemoryPointer.new(:uint8, bytes_length) error = ergo_lib_ergo_tree_to_bytes(self.pointer, bytes_ptr) Util.check_error!(error) bytes_ptr.read_array_of_uint8(bytes_length) end |
#to_template_bytes ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/sigma/ergo_tree.rb', line 55 def to_template_bytes res = ergo_lib_ergo_tree_template_bytes_len(self.pointer) Util.check_error!(res[:error]) bytes_length = res[:value] bytes_ptr = FFI::MemoryPointer.new(:uint8, bytes_length) error = ergo_lib_ergo_tree_template_bytes(self.pointer, bytes_ptr) Util.check_error!(error) bytes_ptr.read_array_of_uint8(bytes_length) end |