class RLP::LazyList
the length is possible as well but requires full horizontal encoding.
Both indexing with positive indices and iterating are supported. Getting
A RLP encoded list which decodes itself when necessary.
#
def [](i)
def [](i) fetch(i, nil) end
def each(&block)
def each(&block) @elements.each(&block) loop { block.call(next_item) } end
def fetch(*args)
def fetch(*args) i = args[0] loop do raise StopIteration if @elements.size > i next_item end @elements.fetch(*args) end
def initialize(rlp, start, next_start, sedes: nil, sedes_options: nil)
-
sedes_options
(Hash
) -- keyword arguments which will be passed on to -
sedes
(Object
) -- a sedes object which deserializes each element of the -
next_start
(Integer
) -- the position of the last payload byte of the -
start
(Integer
) -- the position of the first payload byte of the -
rlp
(String
) -- the rlp string in which the list is encoded
def initialize(rlp, start, next_start, sedes: nil, sedes_options: nil) @rlp = rlp @start = start @next_start = next_start @index = start @elements = [] @size = nil @sedes = sedes @sedes_options = sedes_options end
def next_item
def next_item if @index == @next_start @size = @elements.size raise StopIteration elsif @index < @next_start item, @index = consume_item_lazy @rlp, @index if @sedes # FIXME: lazy man's kwargs item = @sedes_options.empty? ? @sedes.deserialize(item) : @sedes.deserialize(item, **@sedes_options) end @elements.push item item else raise "Assertion failed: index cannot be larger than next start" end end
def size
def size unless @size loop { next_item } end @size end