Class SDL4R::SdlBinary
In: lib/sdl4r/sdl_binary.rb
Parent: Object

Represents a binary value.

This class was introduced to avoid the confusion between a Ruby String and a binary literal.

Methods

==   decode64   eql?   hash   new   to_s  

Attributes

bytes  [RW] 

Public Class methods

Decodes the specified base-64 encoded string and returns a corresponding SdlBinary instance. s might not include the conventional starting and ending square brackets.

[Source]

# File lib/sdl4r/sdl_binary.rb, line 57
    def self.decode64(s)
      s = s.delete("\n\r\t ")

      binary = Base64.decode64(s)
      
      if binary.empty? and not s.empty?
        raise ArgumentError, "bad binary literal"
      end

      return SdlBinary.new(binary)
    end

value: a String containing the bytes

[Source]

# File lib/sdl4r/sdl_binary.rb, line 33
    def initialize(bytes)
      @bytes = bytes
    end

Public Instance methods

[Source]

# File lib/sdl4r/sdl_binary.rb, line 37
    def ==(o)
      return true if self.equal?(o)
      return false if not o.instance_of?(self.class)
      return self.bytes == o.bytes
    end
eql?(o)

Alias for #==

[Source]

# File lib/sdl4r/sdl_binary.rb, line 45
    def hash
      return bytes.hash
    end

Returns the bytes base64-encoded.

[Source]

# File lib/sdl4r/sdl_binary.rb, line 50
    def to_s
      return Base64.encode64(bytes)
    end

[Validate]