Class: TonSdkRuby::BitArray
- Inherits:
-
Array
- Object
- Array
- TonSdkRuby::BitArray
show all
- Extended by:
- TonSdkRuby
- Includes:
- TonSdkRuby
- Defined in:
- lib/ton-sdk-ruby/bit_array/bit_array.rb
Constant Summary
Constants included
from TonSdkRuby
DEPTH_BITS, FLAG_BOUNCEABLE, FLAG_NON_BOUNCEABLE, FLAG_TEST_ONLY, HASH_BITS, INT32_MAX, INT32_MIN, LEAN_BOC_MAGIC_PREFIX, LEAN_BOC_MAGIC_PREFIX_CRC, REACH_BOC_MAGIC_PREFIX, VERSION
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from TonSdkRuby
augment, base64_to_bytes, bits_to_big_int, bits_to_big_uint, bits_to_bytes, bits_to_hex, bits_to_int_uint, breadth_first_sort, bytes_compare, bytes_needed_for_words_bip39, bytes_to_base64, bytes_to_bits, bytes_to_data_string, bytes_to_hex, bytes_to_string, bytes_to_uint, crc16, crc16_bytes_be, crc32c, crc32c_bytes_le, depth_first_sort, deserialize, deserialize_cell, deserialize_fift, deserialize_header, generate_words_bip39, get_mapper, hex_to_bits, hex_to_bytes, hex_to_data_string, read_json_from_link, read_post_json_from_link, require_type, rollback, serialize, serialize_cell, sha256, sha512, sign_cell, slice_into_chunks, string_to_bytes, uint_to_hex, validate_library_reference, validate_merkle_proof, validate_merkle_update, validate_ordinary, validate_pruned_branch
Constructor Details
#initialize(size: 0, value: false) ⇒ BitArray
Returns a new instance of BitArray.
9
10
11
12
|
# File 'lib/ton-sdk-ruby/bit_array/bit_array.rb', line 9
def initialize(size: 0, value: false)
@read_cursor = 0
super(size) { |_| get_value(value) }
end
|
Instance Attribute Details
#read_cursor ⇒ Object
Returns the value of attribute read_cursor.
7
8
9
|
# File 'lib/ton-sdk-ruby/bit_array/bit_array.rb', line 7
def read_cursor
@read_cursor
end
|
Instance Method Details
#get_bit(index: nil) ⇒ Object
27
28
29
30
|
# File 'lib/ton-sdk-ruby/bit_array/bit_array.rb', line 27
def get_bit(index: nil)
raise "Wrong index #{index}. Out of bounds array" if index > size - 1 || index < 0
self[index]
end
|
#get_byte(index: nil) ⇒ Object
36
37
38
39
|
# File 'lib/ton-sdk-ruby/bit_array/bit_array.rb', line 36
def get_byte(index: nil)
raise "Wrong index #{index}. Out of bounds array" if index > size - 1 || index < 0
self[index..index+7].map { |e| e.to_i}.join('').to_i(2)
end
|
#read_sint!(bits_amount: nil) ⇒ Object
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/ton-sdk-ruby/bit_array/bit_array.rb', line 63
def read_sint!(bits_amount: nil)
raise "Wrong bits_amount #{bits_amount}" if bits_amount > self.size
negative_sign = false
bits_string = ""
(read_cursor + bits_amount).times do |index|
bits_string << (self[index] ? '1' : '0')
@read_cursor = index
end
calc_signed_integer(bits_string: bits_string)
end
|
#read_uint!(bits_amount: nil) ⇒ Object
53
54
55
56
57
58
59
60
61
|
# File 'lib/ton-sdk-ruby/bit_array/bit_array.rb', line 53
def read_uint!(bits_amount: nil)
raise "Wrong bits_amount #{bits_amount}" if bits_amount > self.size
bits_string = ""
(read_cursor + bits_amount).times do |index|
bits_string << self[index] ? '1' : '0'
@read_cursor = index
end
bits_string.to_i(2)
end
|
#set_bit!(index: nil, value: nil) ⇒ Object
22
23
24
25
|
# File 'lib/ton-sdk-ruby/bit_array/bit_array.rb', line 22
def set_bit!(index: nil, value: nil)
raise "Wrong index #{index}. Out of bounds array" if index > size || index < 0
self[index] = get_value(value)
end
|
#set_byte!(index: nil, value: nil) ⇒ Object
32
33
34
|
# File 'lib/ton-sdk-ruby/bit_array/bit_array.rb', line 32
def set_byte!(index: nil, value: nil)
set_number!(index: index, value: value, size: 8)
end
|
#show_cursor ⇒ Object
18
19
20
|
# File 'lib/ton-sdk-ruby/bit_array/bit_array.rb', line 18
def show_cursor
self.map { |e| e ? 1 : 0 }.join('').insert(cursor, '⏶')
end
|
#store_sint!(value: nil, size: nil) ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/ton-sdk-ruby/bit_array/bit_array.rb', line 45
def store_sint!(value: nil, size: nil)
max_sint = (1 << size - 1)
raise "Wrong value #{value}" if value < -max_sint || value >= max_sint
set_number!(value: value, size: size)
end
|
#store_uint!(value: nil, size: nil) ⇒ Object
41
42
43
|
# File 'lib/ton-sdk-ruby/bit_array/bit_array.rb', line 41
def store_uint!(value: nil, size: nil)
store_number!(value: value, size: size)
end
|
#to_s ⇒ Object
14
15
16
|
# File 'lib/ton-sdk-ruby/bit_array/bit_array.rb', line 14
def to_s
self.map { |e| e ? 1 : 0 }.join('')
end
|