Sha256: eb65f5edd14550c284463d273a7458536adfbcf999af5fa82ea3a199cac94527
Contents?: true
Size: 1.03 KB
Versions: 2
Compression:
Stored size: 1.03 KB
Contents
JInt = java.lang.Integer module GeoScript module Util class Bytes def self.decode(str, base) # str.to_java_bytes #n = Math.log(256, base).ceil #bytes = [] #(0...str.size).step(n) do |i| # bytes << string_to_byte(str[i...(i + n)].join(''), base) #end #bytes.to_java java.lang.Byte str.to_java_bytes end def self.encode(bytes, base) # bytes.from_java_bytes #bytes_array = [] # #bytes.each do |byte| # bytes_array << byte_to_string(byte, base) #end # #bytes_array.join '' bytes.from_java_bytes end def self.byte_to_string(byte, base) n = Math.log(256, base).ceil s = byte < 0 ? JInt.to_string(((b.abs ^ 0xff) + 0x01), base) : JInt.to_string(b, base) "%0#{n}d" % s end def self.string_to_byte(string, base) int = string.to_i(base) if int > 128 -1 * ((int ^ 0xff) + 0x01) else int end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
geoscript-0.0.1 | lib/geoscript/util/bytes.rb |
geoscript-0.0.1.pre | lib/geoscript/util/bytes.rb |