Class: TJSON::DataType::Binary32
Overview
Base32-serialized binary data
Constant Summary
TAGS
Instance Method Summary
collapse
Methods inherited from Scalar
#inspect
[], encode, identify_type, parse
Instance Method Details
#decode(str) ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/tjson/datatype/binary.rb', line 30
def decode(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
|
#encode(binary) ⇒ Object
39
40
41
|
# File 'lib/tjson/datatype/binary.rb', line 39
def encode(binary)
Base32.encode(binary).downcase.delete("=")
end
|
26
27
28
|
# File 'lib/tjson/datatype/binary.rb', line 26
def tag
"d32"
end
|