Class: BinaryBlocker::CountedArrayEncoder
Instance Method Summary
collapse
attributes, attributes=, #block, clear_registered_klasses, #clone, has_bit_field, has_counted_array, has_fixed_array, has_list_of, has_one, has_one_of, include_klasses, inherited, keys, klasses, klasses=, lookup, lookup=, #method_missing, #orig_clone, register_klass, #to_h, #valid?, #value, #value=
Methods inherited from Encoder
#block, #key_value?, #me
Constructor Details
#initialize(count_type, classes, *opts) ⇒ CountedArrayEncoder
Returns a new instance of CountedArrayEncoder.
956
957
958
959
960
961
962
963
964
|
# File 'lib/blocker.rb', line 956
def initialize(count_type, classes, *opts)
@count_enc = BinaryBlocker.pack_symbols[count_type] || count_type
@count = 0
initialize_options(*opts)
@classes = classes
@value = []
initialize_data(*opts)
end
|
Instance Method Details
#<<(val) ⇒ Object
993
994
995
996
|
# File 'lib/blocker.rb', line 993
def <<(val)
@count += 1
@value << val
end
|
#[](offset) ⇒ Object
983
984
985
986
|
# File 'lib/blocker.rb', line 983
def [](offset)
raise RangeError.new("Access (#{offset}) out of range (#{@count})") unless (0...@count) === offset
@value[offset]
end
|
#[]=(offset, val) ⇒ Object
988
989
990
991
|
# File 'lib/blocker.rb', line 988
def []=(offset,val)
raise RangeError.new("Access (#{offset}) out of range (#{@count})") unless (0...@count) === offset
@value[offset] = val
end
|
#deblock(io) ⇒ Object
971
972
973
974
975
976
977
978
979
980
981
|
# File 'lib/blocker.rb', line 971
def deblock(io)
length = BinaryBlocker.sizeof_format(@count_enc)
result = []
with_guarded_io_pos(io) do
@count = io.read(length).unpack(@count_enc)
@count.times do
result << OneOfEncoder.new(@classes, io, @opts)
end
end
@value = result
end
|
#internal_block(val) ⇒ Object
966
967
968
969
|
# File 'lib/blocker.rb', line 966
def internal_block(val)
buf = [val.size].pack(@count_enc)
val.inject(buf) { |r, o| r + o.block }
end
|
#size ⇒ Object
Also known as:
length
998
999
1000
|
# File 'lib/blocker.rb', line 998
def size
@count
end
|