Class: CF::Data

Inherits:
Base
  • Object
show all
Defined in:
lib/corefoundation/data.rb

Overview

Wrapper for CFData

Instance Attribute Summary

Attributes inherited from Base

#ptr

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

check_cftype, #eql?, #equals?, finalize, #hash, #initialize, #null?, #to_cf, typecast

Methods included from Memory

#inspect, #release, #retain, #to_ptr

Methods included from Register

included, #register_type

Constructor Details

This class inherits a constructor from CF::Base

Class Method Details

.from_string(s) ⇒ CF::Data

Creates a CFData from a ruby string

Parameters:

  • s (String)

    the string to use

Returns:



17
18
19
# File 'lib/corefoundation/data.rb', line 17

def self.from_string(s)
  new(CF.CFDataCreate(nil, s, s.bytesize))
end

Instance Method Details

#sizeInteger

The size in bytes of the CFData

Returns:

  • (Integer)


31
32
33
# File 'lib/corefoundation/data.rb', line 31

def size
  CF.CFDataGetLength(self)
end

#to_sString Also known as: to_ruby

Creates a ruby string from the wrapped data. The encoding will always be ASCII_8BIT

Returns:



24
25
26
27
# File 'lib/corefoundation/data.rb', line 24

def to_s
  ptr = CF.CFDataGetBytePtr(self)
  ptr.read_string(CF.CFDataGetLength(self)).force_encoding(Encoding::ASCII_8BIT)
end