class CZTop::Z85
Represents a CZMQ::FFI::Zarmour in Z85
mode.
Use this class to encode to and from the Z85
encoding scheme. @see rfc.zeromq.org/spec:32
Public Class Methods
Same as {Z85#decode}, but without the need to create an instance first.
@param input [String] Z85
encoded data @return [String] original data as binary string @raise [ArgumentError] if input length isn’t divisible by 5 with no
remainder
@raise [SystemCallError] if this fails
# File lib/cztop/z85.rb, line 36 def decode(input) default.decode(input) end
Same as {Z85#encode}, but without the need to create an instance first.
@param input [String] possibly binary input data @return [String] Z85
encoded data as ASCII string @raise [ArgumentError] if input length isn’t divisible by 4 with no
remainder
@raise [SystemCallError] if this fails
# File lib/cztop/z85.rb, line 23 def encode(input) default.encode(input) end
# 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
Private Class Methods
Default instance of {Z85}. @return [Z85] memoized default instance
# File lib/cztop/z85.rb, line 44 def default @default ||= Z85.new end
Public Instance Methods
Decodes from Z85
. @param input [String] Z85
encoded data @return [String] original data as binary string @raise [ArgumentError] if input length isn’t divisible by 5 with no
remainder
@raise [SystemCallError] if this fails
# 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
Encodes to Z85
. @param input [String] possibly binary input data @return [String] Z85
encoded data as ASCII string @raise [ArgumentError] if input length isn’t divisible by 4 with no
remainder
@raise [SystemCallError] if this fails
# 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