def consume_payload(rlp, start, type, length)
      case type
      when :str
        [rlp[start...(start+length)], start+length]
      when :list
        items = []
        next_item_start = start
        payload_end = next_item_start + length

        while next_item_start < payload_end
          item, next_item_start = consume_item rlp, next_item_start
          items.push item
        end

        raise DecodingError.new('List length prefix announced a too small length', rlp) if next_item_start > payload_end

        [items, next_item_start]
      else
        raise TypeError, 'Type must be either :str or :list'
      end
    end
def consume_payload(rlp, start, type, length)
      case type
      when :str
        [rlp[start...(start+length)], start+length]
      when :list
        items = []
        next_item_start = start
        payload_end = next_item_start + length

        while next_item_start < payload_end
          item, next_item_start = consume_item rlp, next_item_start
          items.push item
        end

        raise DecodingError.new('List length prefix announced a too small length', rlp) if next_item_start > payload_end

        [items, next_item_start]
      else
        raise TypeError, 'Type must be either :str or :list'
      end
    end
Read the payload of an item from an RLP string.

 * `rlp` - the rlp string to read from
 * `type` - the type of the payload (`:str` or `:list`)
 * `start` - the position at which to start reading
 * `length` - the length of the payload in bytes

 Returns a pair `[item, end]`, where `item` is the read item and `end` is
 the position of the first unprocessed byte.