Class: TJSON::DataType::Binary16
Overview
Base16-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
11
12
13
14
15
16
17
|
# File 'lib/tjson/datatype/binary.rb', line 11
def decode(str)
raise TJSON::TypeError, "expected String, got #{str.class}: #{str.inspect}" unless str.is_a?(::String)
raise TJSON::ParseError, "base16 must be lower case: #{str.inspect}" if str =~ /[A-F]/
raise TJSON::ParseError, "invalid base16: #{str.inspect}" unless str =~ /\A[a-f0-9]*\z/
[str].pack("H*")
end
|
#encode(binary) ⇒ Object
19
20
21
|
# File 'lib/tjson/datatype/binary.rb', line 19
def encode(binary)
binary.unpack("H*").first
end
|
7
8
9
|
# File 'lib/tjson/datatype/binary.rb', line 7
def tag
"d16"
end
|