Class: CZTop::Z85
- Inherits:
-
Object
- Object
- CZTop::Z85
- Extended by:
- HasFFIDelegate::ClassMethods
- Includes:
- HasFFIDelegate
- Defined in:
- lib/cztop/z85.rb
Overview
Represents a CZMQ::FFI::Zarmour in Z85 mode.
Use this class to encode to and from the Z85 encoding scheme.
Direct Known Subclasses
Defined Under Namespace
Instance Attribute Summary
Attributes included from HasFFIDelegate
Class Method Summary collapse
-
.decode(input) ⇒ String
Same as #decode, but without the need to create an instance first.
-
.encode(input) ⇒ String
Same as #encode, but without the need to create an instance first.
Instance Method Summary collapse
-
#decode(input) ⇒ String
Decodes from Z85.
-
#encode(input) ⇒ String
Encodes to Z85.
-
#initialize ⇒ Z85
constructor
A new instance of Z85.
Methods included from HasFFIDelegate::ClassMethods
ffi_delegate, from_ffi_delegate
Methods included from HasFFIDelegate
#attach_ffi_delegate, #from_ffi_delegate, raise_zmq_err, #to_ptr
Constructor Details
#initialize ⇒ Z85
Returns a new instance of Z85.
50 51 52 53 |
# File 'lib/cztop/z85.rb', line 50 def initialize attach_ffi_delegate(CZMQ::FFI::Zarmour.new) ffi_delegate.set_mode(CZMQ::FFI::Zarmour::MODE_Z85) end |
Class Method Details
.decode(input) ⇒ String
Same as #decode, but without the need to create an instance first.
36 37 38 |
# File 'lib/cztop/z85.rb', line 36 def decode(input) default.decode(input) end |
.encode(input) ⇒ String
Same as #encode, but without the need to create an instance first.
23 24 25 |
# File 'lib/cztop/z85.rb', line 23 def encode(input) default.encode(input) end |
Instance Method Details
#decode(input) ⇒ String
Decodes from Z85.
80 81 82 83 84 85 86 87 |
# File 'lib/cztop/z85.rb', line 80 def decode(input) return '' if input.empty? raise ArgumentError, 'wrong input length' if (input.bytesize % 5).positive? zchunk = ffi_delegate.decode(input) raise_zmq_err if zchunk.null? zchunk.data.read_string(zchunk.size - 1) end |
#encode(input) ⇒ String
Encodes to Z85.
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/cztop/z85.rb', line 62 def encode(input) raise ArgumentError, 'wrong input length' if (input.bytesize % 4).positive? input = input.dup.force_encoding(Encoding::BINARY) ptr = ffi_delegate.encode(input, input.bytesize) raise_zmq_err if ptr.null? z85 = ptr.read_string z85.encode!(Encoding::ASCII) z85 end |