Class: FFI::Encoding
- Inherits:
-
Object
- Object
- FFI::Encoding
- Includes:
- DataConverter
- Defined in:
- lib/ffi/encoding.rb
Overview
DataConverter for reading/writing encoded strings
Instance Attribute Summary collapse
-
#encoding ⇒ Object
readonly
Returns the value of attribute encoding.
Class Method Summary collapse
-
.for(encoding) ⇒ Object
Create a dataconverter for the specified encoding.
Instance Method Summary collapse
- #from_native(value, _ctx) ⇒ Object
-
#initialize(encoding) ⇒ Encoding
constructor
A new instance of Encoding.
- #native_type(_type = nil) ⇒ Object
- #to_native(value, _ctx) ⇒ Object
Constructor Details
#initialize(encoding) ⇒ Encoding
Returns a new instance of Encoding.
34 35 36 |
# File 'lib/ffi/encoding.rb', line 34 def initialize(encoding) @encoding = encoding end |
Instance Attribute Details
#encoding ⇒ Object (readonly)
Returns the value of attribute encoding.
10 11 12 |
# File 'lib/ffi/encoding.rb', line 10 def encoding @encoding end |
Class Method Details
.for(encoding) ⇒ Object
Create a dataconverter for the specified encoding
18 19 20 |
# File 'lib/ffi/encoding.rb', line 18 def self.for(encoding) new(encoding) end |
Instance Method Details
#from_native(value, _ctx) ⇒ Object
22 23 24 |
# File 'lib/ffi/encoding.rb', line 22 def from_native(value, _ctx) value.force_encoding(encoding) end |
#native_type(_type = nil) ⇒ Object
30 31 32 |
# File 'lib/ffi/encoding.rb', line 30 def native_type(_type = nil) FFI::Type::STRING end |
#to_native(value, _ctx) ⇒ Object
26 27 28 |
# File 'lib/ffi/encoding.rb', line 26 def to_native(value, _ctx) value.encode(encoding) end |