Module: Cel::Extensions::Encoders::Base64

Defined in:
lib/cel/extensions/encoders.rb

Class Method Summary collapse

Class Method Details

.__check(funcall, checker:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cel/extensions/encoders.rb', line 9

def __check(funcall, checker:)
  func = funcall.func
  args = funcall.args

  case func
  when :encode
    checker.check_arity(func, args, 1)
    arg = checker.call(args.first)
    return TYPES[:string] if checker.find_match_all_types(i[bytes], arg)
  when :decode
    checker.check_arity(func, args, 1)
    arg = checker.call(args.first)
    return TYPES[:bytes] if checker.find_match_all_types(i[string], arg)
  end

  checker.unsupported_operation(funcall)
end

.decode(str, program:) ⇒ Object



33
34
35
36
37
# File 'lib/cel/extensions/encoders.rb', line 33

def decode(str, program:)
  value = program.call(str).value

  Cel::Bytes.new(value.unpack1("m").unpack("C*"))
end

.encode(str, program:) ⇒ Object



27
28
29
30
31
# File 'lib/cel/extensions/encoders.rb', line 27

def encode(str, program:)
  value = program.call(str).value

  Cel::String.new([value.pack("C*")].pack("m0"))
end