Class: Sigma::ByteArrays

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

Overview

An ordered collection of ByteArray

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pointerObject

Returns the value of attribute pointer.



60
61
62
# File 'lib/sigma/byte_array.rb', line 60

def pointer
  @pointer
end

Class Method Details

.createByteArrays

Create an empty collection

Returns:



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

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

  init(pointer)
end

.with_raw_pointer(unread_pointer) ⇒ ByteArrays

Note:

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

Takes ownership of an existing ByteArrays Pointer.

Parameters:

  • pointer (FFI::MemoryPointer)

Returns:



66
67
68
# File 'lib/sigma/byte_array.rb', line 66

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

Instance Method Details

#add(byte_array) ⇒ Object

Add an item to collection

Parameters:



87
88
89
# File 'lib/sigma/byte_array.rb', line 87

def add(byte_array)
  ergo_lib_byte_arrays_add(byte_array.pointer, self.pointer)
end

#get(index) ⇒ ByteArray?

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

Returns:



94
95
96
97
98
99
100
101
102
103
# File 'lib/sigma/byte_array.rb', line 94

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

#lenInteger

Get length of collection

Returns:

  • (Integer)


81
82
83
# File 'lib/sigma/byte_array.rb', line 81

def len
  ergo_lib_byte_arrays_len(self.pointer)
end