Class: Sigma::BlockIds

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

Overview

An ordered collection of BlockId

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pointerObject

Returns the value of attribute pointer.



186
187
188
# File 'lib/sigma/block_header.rb', line 186

def pointer
  @pointer
end

Class Method Details

.createBlockIds

Create an empty collection

Returns:



198
199
200
201
202
203
# File 'lib/sigma/block_header.rb', line 198

def self.create
  pointer = FFI::MemoryPointer.new(:pointer)
  ergo_lib_block_ids_new(pointer)

  init(pointer)
end

.with_raw_pointer(unread_pointer) ⇒ BlockIds

Note:

A user of sigma_rb generally does not need to call this function

Takes ownership of an existing BlockIds Pointer.

Parameters:

  • pointer (FFI::MemoryPointer)

Returns:



192
193
194
# File 'lib/sigma/block_header.rb', line 192

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

Instance Method Details

#add(block_id) ⇒ Object

Add to collection

Parameters:



213
214
215
# File 'lib/sigma/block_header.rb', line 213

def add(block_id)
  ergo_lib_block_ids_add(block_id.pointer, self.pointer)
end

#get(index) ⇒ BlockId?

Get item at specified index or return nil if no item exists

Parameters:

  • index (Integer)

Returns:



220
221
222
223
224
225
226
227
228
229
# File 'lib/sigma/block_header.rb', line 220

def get(index)
  pointer = FFI::MemoryPointer.new(:pointer)
  res = ergo_lib_block_ids_get(self.pointer, index, pointer)
  Util.check_error!(res[:error])
  if res[:is_some]
    Sigma::BlockId.with_raw_pointer(pointer)
  else
    nil
  end
end

#lenInteger

Get length of collection

Returns:

  • (Integer)


207
208
209
# File 'lib/sigma/block_header.rb', line 207

def len
  ergo_lib_block_ids_len(self.pointer)
end