Module: Utils::ByteUtils
Instance Method Summary collapse
- #byte_array_to_hex(byte_array) ⇒ String
- #byte_array_to_string(byte_array) ⇒ String
- #hex_from_little_endian_to_big_endian(hex_str) ⇒ String
- #hex_to_byte_array(hex_str) ⇒ Array
- #hex_to_i32_value(hex_str) ⇒ Object
- #hex_to_i64_value(hex_str) ⇒ Object
- #hex_to_integer(hex_str) ⇒ Integer
- #hex_to_string(hex_str) ⇒ String
- #hex_to_u32_value(hex_str) ⇒ Object
- #hex_to_u64_value(hex_str) ⇒ Object
- #hex_to_u8_value(hex_str) ⇒ Object
- #integer_to_hex(n) ⇒ String
- #string_to_byte_array(str) ⇒ Array
- #string_to_hex(str) ⇒ String
- #to_i32(n) ⇒ Object
- #to_i64(n) ⇒ Object
- #to_u32(n) ⇒ Object
- #to_u64(n) ⇒ String
- #to_u8(n) ⇒ Object
Instance Method Details
#byte_array_to_hex(byte_array) ⇒ String
26 27 28 29 |
# File 'lib/utils/byte_utils.rb', line 26 def byte_array_to_hex(byte_array) # byte_array.pack("C*").unpack1("H*") byte_array.pack("C*").unpack("H*").first end |
#byte_array_to_string(byte_array) ⇒ String
39 40 41 |
# File 'lib/utils/byte_utils.rb', line 39 def byte_array_to_string(byte_array) byte_array.pack("C*") end |
#hex_from_little_endian_to_big_endian(hex_str) ⇒ String
82 83 84 85 |
# File 'lib/utils/byte_utils.rb', line 82 def hex_from_little_endian_to_big_endian(hex_str) # [hex_str].pack("H*").unpack('N*').pack('V*').unpack1('H*') [hex_str].pack("H*").unpack('N*').pack('V*').unpack('H*').first end |
#hex_to_byte_array(hex_str) ⇒ Array
20 21 22 |
# File 'lib/utils/byte_utils.rb', line 20 def hex_to_byte_array(hex_str) [hex_str].pack("H*").unpack("C*") end |
#hex_to_i32_value(hex_str) ⇒ Object
87 88 89 |
# File 'lib/utils/byte_utils.rb', line 87 def hex_to_i32_value(hex_str) [hex_str].pack("H*").unpack("l*").first end |
#hex_to_i64_value(hex_str) ⇒ Object
91 92 93 |
# File 'lib/utils/byte_utils.rb', line 91 def hex_to_i64_value(hex_str) [hex_str].pack("H*").unpack("q*").first end |
#hex_to_integer(hex_str) ⇒ Integer
51 52 53 |
# File 'lib/utils/byte_utils.rb', line 51 def hex_to_integer(hex_str) [hex_str].pack("H*").unpack("l").first end |
#hex_to_string(hex_str) ⇒ String
14 15 16 |
# File 'lib/utils/byte_utils.rb', line 14 def hex_to_string(hex_str) [hex_str].pack("H*") end |
#hex_to_u32_value(hex_str) ⇒ Object
99 100 101 |
# File 'lib/utils/byte_utils.rb', line 99 def hex_to_u32_value(hex_str) [hex_str].pack("H*").unpack("L*").first end |
#hex_to_u64_value(hex_str) ⇒ Object
103 104 105 |
# File 'lib/utils/byte_utils.rb', line 103 def hex_to_u64_value(hex_str) [hex_str].pack("H*").unpack("Q*").first end |
#hex_to_u8_value(hex_str) ⇒ Object
95 96 97 |
# File 'lib/utils/byte_utils.rb', line 95 def hex_to_u8_value(hex_str) [hex_str].pack("H*").unpack("C*").first end |
#integer_to_hex(n) ⇒ String
45 46 47 |
# File 'lib/utils/byte_utils.rb', line 45 def integer_to_hex(n) [n].pack("l<*").unpack("H*").first end |
#string_to_byte_array(str) ⇒ Array
33 34 35 |
# File 'lib/utils/byte_utils.rb', line 33 def string_to_byte_array(str) str.unpack("C*") end |
#string_to_hex(str) ⇒ String
7 8 9 10 |
# File 'lib/utils/byte_utils.rb', line 7 def string_to_hex(str) # str.unpack1("H*") str.unpack("H*").first end |
#to_i32(n) ⇒ Object
55 56 57 58 59 |
# File 'lib/utils/byte_utils.rb', line 55 def to_i32(n) # [value].pack("l<*").unpack("C*") [n].pack("l<*").unpack("H*").first # [n].pack("l<*").unpack1("H*") end |
#to_i64(n) ⇒ Object
61 62 63 64 65 |
# File 'lib/utils/byte_utils.rb', line 61 def to_i64(n) # [value].pack("l<*").unpack("C*") [n].pack("q<*").unpack("H*").first # [n].pack("l<*").unpack1("H*") end |
#to_u32(n) ⇒ Object
70 71 72 73 |
# File 'lib/utils/byte_utils.rb', line 70 def to_u32(n) [n].pack("L<*").unpack("H*").first # [n].pack("L<*").unpack1("H*") end |
#to_u64(n) ⇒ String
76 77 78 |
# File 'lib/utils/byte_utils.rb', line 76 def to_u64(n) [n].pack("Q<*").unpack("H*").first end |
#to_u8(n) ⇒ Object
67 68 69 |
# File 'lib/utils/byte_utils.rb', line 67 def to_u8(n) [n].pack("C").unpack1("H*") end |