module BitStream::Utils

Public Class Methods

bit_lshift(s, bit) click to toggle source
# File lib/types/string-utils.rb, line 10
def self.bit_lshift(s, bit)
  if bit != 0
    last_byte = nil
    (s.size - 1).times do |i|
      dbyte = s[i..(i + 1)].unpack('n')[0]
      c = dbyte >> (8 - bit)
      s[i] = (c & 0xff).chr
    end
  end
end
bit_rshift(s, bit) click to toggle source
# File lib/types/string-utils.rb, line 21
def self.bit_rshift(s, bit)
  if bit != 0
    s << "\0"
    first_byte = nil
    (s.size - 1).downto 1 do |i|
      dbyte = s[(i - 1)..i].unpack('n')[0]
      c = dbyte >> bit
      s[i] = (c & 0xff).chr
      first_byte = c >> 8
    end
    s[0] = first_byte.chr
  end
end
camel2snake(camel) click to toggle source
# File lib/bitstream/utils.rb, line 14
def self.camel2snake(camel)
  snake = camel.dup
  snake[0] = snake[0].downcase
  snake.gsub(/[A-Z]/) do |s|
    "_" + s.downcase
  end
end
class2symbol(type) click to toggle source
# File lib/bitstream/utils.rb, line 9
def self.class2symbol(type)
  name = type.name.split("::").last
  name = self.camel2snake(name).intern
end