Class: DatawireQuarkCore::Codec

Inherits:
Object
  • Object
show all
Defined in:
lib/datawire-quark-core.rb

Constant Summary collapse

ZERO =
"\0".encode Encoding::ASCII_8BIT

Instance Method Summary collapse

Instance Method Details

#buffer(size) ⇒ Object



1110
1111
1112
# File 'lib/datawire-quark-core.rb', line 1110

def buffer(size)
  Buffer.new ZERO * size
end

#fromBase64(value) ⇒ Object



1135
1136
1137
# File 'lib/datawire-quark-core.rb', line 1135

def fromBase64(value)
  Buffer.new Base64.decode64 value
end

#fromHexdump(value) ⇒ Object



1125
1126
1127
1128
1129
1130
1131
1132
1133
# File 'lib/datawire-quark-core.rb', line 1125

def fromHexdump(value)
  value = value.split(" ").join
  if value[0...2].downcase == "0x"
    value[0...2] = ""
  end
  Buffer.new ((0...value.length).each_slice(2).map { |i|
    value[i[0]..i[1]].to_i(16)
  }.pack("C*"))
end

#toBase64(buffer, index, size) ⇒ Object



1121
1122
1123
# File 'lib/datawire-quark-core.rb', line 1121

def toBase64(buffer, index, size)
  Base64.encode64(buffer.data[index...index+size]).strip
end

#toHexdump(buffer, index, size, spaceScale) ⇒ Object



1114
1115
1116
1117
1118
1119
# File 'lib/datawire-quark-core.rb', line 1114

def toHexdump(buffer, index, size, spaceScale)
  hex = buffer.data[index...index+size].unpack("H*")[0]
  (0...hex.size).each_slice(2**(spaceScale+1)).map {|i|
    hex[i[0]..i[-1]]
  }.join " "
end