class CZMQ::FFI::Zdigest

provides hashing functions (SHA-1 at present) @note This class is 100% generated using zproject.

Public Class Methods

__new()
Alias for: new
create_finalizer_for(ptr) click to toggle source

@param ptr [::FFI::Pointer] @return [Proc]

# File lib/czmq-ffi-gen/czmq/ffi/zdigest.rb, line 35
def self.create_finalizer_for(ptr)
  Proc.new do
    ptr_ptr = ::FFI::MemoryPointer.new :pointer
    ptr_ptr.write_pointer ptr
    ::CZMQ::FFI.zdigest_destroy ptr_ptr
  end
end
new(ptr, finalize = true) click to toggle source

Attaches the pointer ptr to this instance and defines a finalizer for it if necessary. @param ptr [::FFI::Pointer] @param finalize [Boolean]

# File lib/czmq-ffi-gen/czmq/ffi/zdigest.rb, line 24
def initialize(ptr, finalize = true)
  @ptr = ptr
  if @ptr.null?
    @ptr = nil # Remove null pointers so we don't have to test for them.
  elsif finalize
    @finalizer = self.class.create_finalizer_for @ptr
    ObjectSpace.define_finalizer self, @finalizer
  end
end
new() click to toggle source

Constructor - creates new digest object, which you use to build up a digest by repeatedly calling zdigest_update() on chunks of data. @return [CZMQ::Zdigest]

# File lib/czmq-ffi-gen/czmq/ffi/zdigest.rb, line 79
def self.new()
  ptr = ::CZMQ::FFI.zdigest_new()
  __new ptr
end
Also aliased as: __new
test(verbose) click to toggle source

Self test of this class.

@param verbose [Boolean] @return [void]

# File lib/czmq-ffi-gen/czmq/ffi/zdigest.rb, line 144
def self.test(verbose)
  verbose = !(0==verbose||!verbose) # boolean
  result = ::CZMQ::FFI.zdigest_test(verbose)
  result
end

Public Instance Methods

__ptr() click to toggle source

Return internal pointer @return [::FFI::Pointer]

# File lib/czmq-ffi-gen/czmq/ffi/zdigest.rb, line 48
def __ptr
  raise DestroyedError unless @ptr
  @ptr
end
Also aliased as: to_ptr
__ptr_give_ref() click to toggle source

Nullify internal pointer and return pointer pointer. @note This detaches the current instance from the native object

and thus makes it unusable.

@return [::FFI::MemoryPointer] the pointer pointing to a pointer

pointing to the native object
# File lib/czmq-ffi-gen/czmq/ffi/zdigest.rb, line 59
def __ptr_give_ref
  raise DestroyedError unless @ptr
  ptr_ptr = ::FFI::MemoryPointer.new :pointer
  ptr_ptr.write_pointer @ptr
  __undef_finalizer if @finalizer
  @ptr = nil
  ptr_ptr
end
__undef_finalizer() click to toggle source

Undefines the finalizer for this object. @note Only use this if you need to and can guarantee that the native

object will be freed by other means.

@return [void]

# File lib/czmq-ffi-gen/czmq/ffi/zdigest.rb, line 71
def __undef_finalizer
  ObjectSpace.undefine_finalizer self
  @finalizer = nil
end
data() click to toggle source

Return final digest hash data. If built without crypto support, returns NULL.

@return [::FFI::Pointer]

# File lib/czmq-ffi-gen/czmq/ffi/zdigest.rb, line 111
def data()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zdigest_data(self_p)
  result
end
destroy() click to toggle source

Destroy a digest object

@return [void]

# File lib/czmq-ffi-gen/czmq/ffi/zdigest.rb, line 87
def destroy()
  return unless @ptr
  self_p = __ptr_give_ref
  result = ::CZMQ::FFI.zdigest_destroy(self_p)
  result
end
null?() click to toggle source

@return [Boolean]

# File lib/czmq-ffi-gen/czmq/ffi/zdigest.rb, line 43
def null?
  !@ptr or @ptr.null?
end
size() click to toggle source

Return final digest hash size

@return [Integer]

# File lib/czmq-ffi-gen/czmq/ffi/zdigest.rb, line 121
def size()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zdigest_size(self_p)
  result
end
string() click to toggle source

Return digest as printable hex string; caller should not modify nor free this string. After calling this, you may not use zdigest_update() on the same digest. If built without crypto support, returns NULL.

@return [::FFI::Pointer]

# File lib/czmq-ffi-gen/czmq/ffi/zdigest.rb, line 133
def string()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zdigest_string(self_p)
  result
end
to_ptr()

So external Libraries can just pass the Object to a FFI function which expects a :pointer

Alias for: __ptr
update(buffer, length) click to toggle source

Add buffer into digest calculation

@param buffer [::FFI::Pointer, to_ptr] @param length [Integer, to_int, to_i] @return [void]

# File lib/czmq-ffi-gen/czmq/ffi/zdigest.rb, line 99
def update(buffer, length)
  raise DestroyedError unless @ptr
  self_p = @ptr
  length = Integer(length)
  result = ::CZMQ::FFI.zdigest_update(self_p, buffer, length)
  result
end