Represents a binary value.
This class was introduced to avoid the confusion between a Ruby String and a binary literal.
Attributes
bytes | [RW] |
Public class methods
decode64
(s)
Decodes the specified base-64 encoded string and returns a corresponding SdlBinary instance. s might not include the conventional starting and ending square brackets.
[show source]
# File lib/sdl4r/sdl_binary.rb, line 57 57: def self.decode64(s) 58: s = s.delete("\n\r\t ") 59: 60: binary = Base64.decode64(s) 61: 62: if binary.empty? and not s.empty? 63: raise ArgumentError, "bad binary literal" 64: end 65: 66: return SdlBinary.new(binary) 67: end
new
(bytes)
value: a String containing the bytes
[show source]
# File lib/sdl4r/sdl_binary.rb, line 33 33: def initialize(bytes) 34: @bytes = bytes 35: end
Public instance methods
==
(o)
[show source]
# File lib/sdl4r/sdl_binary.rb, line 37 37: def ==(o) 38: return true if self.equal?(o) 39: return false if not o.instance_of?(self.class) 40: return self.bytes == o.bytes 41: end
hash
()
[show source]
# File lib/sdl4r/sdl_binary.rb, line 45 45: def hash 46: return bytes.hash 47: end
to_s
()
Returns the bytes base64-encoded.
[show source]
# File lib/sdl4r/sdl_binary.rb, line 50 50: def to_s 51: return Base64.encode64(bytes) 52: end