Class: TJSON::DataType::Binary32
Overview
Base32-serialized binary data
Constant Summary
TAGS
Instance Method Summary
collapse
Methods inherited from Scalar
#inspect, #scalar?
[], generate, identify_type, parse
Instance Method Details
#convert(str) ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/tjson/datatype/binary.rb', line 33
def convert(str)
raise TJSON::TypeError, "expected String, got #{str.class}: #{str.inspect}" unless str.is_a?(::String)
raise TJSON::ParseError, "base32 must be lower case: #{str.inspect}" if str =~ /[A-Z]/
raise TJSON::ParseError, "padding disallowed: #{str.inspect}" if str.include?("=")
raise TJSON::ParseError, "invalid base32: #{str.inspect}" unless str =~ /\A[a-z2-7]*\z/
::Base32.decode(str.upcase).force_encoding(Encoding::BINARY)
end
|
#generate(binary) ⇒ Object
42
43
44
|
# File 'lib/tjson/datatype/binary.rb', line 42
def generate(binary)
Base32.encode(binary).downcase.delete("=")
end
|
29
30
31
|
# File 'lib/tjson/datatype/binary.rb', line 29
def tag
"b32"
end
|