Class: Sigma::BoxId
- Inherits:
-
Object
- Object
- Sigma::BoxId
- Extended by:
- FFI::Library
- Defined in:
- lib/sigma/ergo_box.rb
Overview
BoxId (32-byte digest)
Instance Attribute Summary collapse
-
#pointer ⇒ Object
Returns the value of attribute pointer.
Class Method Summary collapse
-
.with_raw_pointer(bid_ptr) ⇒ BoxId
Takes ownership of an existing BoxId Pointer.
-
.with_string(str) ⇒ BoxId
Parse box id (32 byte digest) from base16-encoded string.
Instance Method Summary collapse
-
#==(box_id_two) ⇒ bool
Equality check of two BoxId.
-
#to_bytes ⇒ Array<uint8, 32>
Returns byte array (32-bytes) representation.
-
#to_s ⇒ String
Returns base16 encoded string representation.
Instance Attribute Details
#pointer ⇒ Object
Returns the value of attribute pointer.
18 19 20 |
# File 'lib/sigma/ergo_box.rb', line 18 def pointer @pointer end |
Class Method Details
.with_raw_pointer(bid_ptr) ⇒ BoxId
Note:
A user of sigma_rb generally does not need to call this function
Takes ownership of an existing BoxId Pointer.
24 25 26 |
# File 'lib/sigma/ergo_box.rb', line 24 def self.with_raw_pointer(bid_ptr) init(bid_ptr) end |
.with_string(str) ⇒ BoxId
Parse box id (32 byte digest) from base16-encoded string
31 32 33 34 35 36 37 |
# File 'lib/sigma/ergo_box.rb', line 31 def self.with_string(str) bid_ptr = FFI::MemoryPointer.new(:pointer) error = ergo_lib_box_id_from_str(str, bid_ptr) Util.check_error!(error) init(bid_ptr) end |
Instance Method Details
#==(box_id_two) ⇒ bool
Equality check of two BoxId
61 62 63 |
# File 'lib/sigma/ergo_box.rb', line 61 def ==(box_id_two) ergo_lib_box_id_eq(self.pointer, box_id_two.pointer) end |
#to_bytes ⇒ Array<uint8, 32>
Returns byte array (32-bytes) representation
41 42 43 44 45 |
# File 'lib/sigma/ergo_box.rb', line 41 def to_bytes b_ptr = FFI::MemoryPointer.new(:uint8, 32) ergo_lib_box_id_to_bytes(self.pointer, b_ptr) b_ptr.get_array_of_uint8(0, 32) end |
#to_s ⇒ String
Returns base16 encoded string representation
49 50 51 52 53 54 55 56 |
# File 'lib/sigma/ergo_box.rb', line 49 def to_s s_ptr = FFI::MemoryPointer.new(:pointer, 1) ergo_lib_box_id_to_str(self.pointer, s_ptr) s_ptr = s_ptr.read_pointer() str = s_ptr.read_string().force_encoding('UTF-8') Util.ergo_lib_delete_string(s_ptr) str end |