class TJSON::DataType::Binary16

Base16-serialized binary data

Public Instance Methods

decode(str) click to toggle source
# 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) click to toggle source
# File lib/tjson/datatype/binary.rb, line 19
def encode(binary)
  binary.unpack("H*").first
end
tag() click to toggle source
# File lib/tjson/datatype/binary.rb, line 7
def tag
  "d16"
end