Repository: pedrokiefer/aiostomp

Issue:
ValueError while parsing data
Since version 1.4.0 I constantly get the following error:

```
Traceback (most recent call last):
  File "/usr/lib/python3.6/asyncio/events.py", line 145, in _run
    self._callback(*self._args)
  File "/usr/lib/python3.6/asyncio/selector_events.py", line 732, in _read_ready
    self._protocol.data_received(data)
  File "/lib/python3.6/site-packages/aiostomp/aiostomp.py", line 388, in data_received 
    self._protocol.feed_data(data)
  File "/lib/python3.6/site-packages/aiostomp/protocol.py", line 43, in feed_data 
    pending_data = self._feed_data(pending_data)
  File "/lib/python3.6/site-packages/aiostomp/protocol.py", line 57, in _feed_data
    b''.join(self._pending_parts))
  File "/lib/python3.6/site-packages/aiostomp/protocol.py", line 75, in _parse_data
    command, data = data.split(b'\n', 1)
ValueError: not enough values to unpack (expected 2, got 1)
```

An examples of `data` at this point are (when I print them out): 
- `b'MESSAGE'`
- `b'ME'`
- `b'MESSAG'`
- `b'MES'`

I'm using Python 3.6.3 and connecting to an ActiveMQ Broker.

I'm facing this issue since 1.4.0.
1.3.0 works fine

Please let me know if I can do anything to help

Comments:

Patch:
diff --git a/aiostomp/protocol.py b/aiostomp/protocol.py
index 6936ae2..6b3edfb 100644
--- a/aiostomp/protocol.py
+++ b/aiostomp/protocol.py
@@ -70,7 +70,10 @@ class StompProtocol(object):
     def _parse_data(self, data):
 
         if not self._intermediate_frame:
-            command, data = data.split(b'\n', 1)
+            try:
+                command, data = data.split(b'\n', 1)
+            except ValueError:
+                return None, data
             command = self._decode(command)
             self._intermediate_frame = {'command': command}
 


Test patch:
diff --git a/tests/test_main.py b/tests/test_main.py
index cd38b84..06a8540 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -275,6 +275,52 @@ class TestStompReader(AsyncTestCase):
         await asyncio.sleep(0.001)
         message_handle_mock.assert_called_once()
 
+    @patch('aiostomp.aiostomp.StompReader._handle_message')
+    @unittest_run_loop
+    async def test_can_process_long_messages(self, message_handle_mock):
+        stomp = StompReader(None, self.loop)
+
+        await asyncio.sleep(0.001)
+
+        data = b'stent:true\ntimestamp:1548945234003\n\n111.11.11.111\x00\n' \
+            b'MESSAGE\n' \
+            b'content-length:14\nexpires:0\ndestination:/topic/' \
+            b'xxxxxxxxxxxxxxxxxxxxxxxxxl' \
+            b'\nsubscription:1\npriority:4\nActiveMQ.MQTT.QoS:1\nmessage-id' \
+            b':ID\\cxxxxxx-35207-1543430467768-204' \
+            b'\\c363\\c-1\\c1\\c463859\npersistent:true\ntimestamp' \
+            b':1548945234003\n\n222.222.22.222' \
+            b'\x00\nMESSAGE\ncontent-length:12\nexpires:0\ndestination:' \
+            b'/topic/xxxxxxxxxxxxxxxxxxxxxxxxxx' \
+            b'\nsubscription:1\npriority:4\nActiveMQ.MQTT.QoS:1\nmessage-id' \
+            b':ID\\cxxxxxx-35207-1543430467768-204' \
+            b'\\c363\\c-1\\c1\\c463860\npersistent:true\ntimestamp' \
+            b':1548945234005\n\n88.88.888.88' \
+            b'\x00\nMESSAGE\ncontent-length:11\nexpires:0\ndestination:' \
+            b'/topic/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
+            b'\nsubscription:1\npriority:4\nActiveMQ.MQTT.QoS:1\nmessage-id' \
+            b':ID\\cxxxxxx-35207-1543430467768-204'\
+            b'\\c362\\c-1\\c1\\c290793\npersistent:true\ntimestamp' \
+            b':1548945234005\n\n111.11.1.11' \
+            b'\x00\nMESSAGE\ncontent-length:14\nexpires:0\ndestination:' \
+            b'/topic/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
+            b'\nsubscription:1\npriority:4\nActiveMQ.MQTT.QoS:1\nmessage-id' \
+            b':ID\\cxxxxxx-35207-1543430467768-204' \
+            b'\\c362\\c-1\\c1\\c290794\npersistent:true\ntimestamp:' \
+            b'1548945234005\n\n222.222.22.222' \
+            b'\x00\nMESSAGE\ncontent-length:12\nexpires:0\ndestination:' \
+            b'/topic/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
+            b'\nsubscription:1\npriority:4\nActiveMQ.MQTT.QoS:1\nmessage-id' \
+            b':ID\\cxxxxxx-35207-1543430467768-204' \
+            b'\\c362\\c-1\\c1\\c290795\npersistent:true\ntimestamp:' \
+            b'1548945234005\n\n88.88.888.88\x00\nMESS'
+
+        stomp.data_received(data)
+
+        await asyncio.sleep(0.001)
+        self.assertEqual(message_handle_mock.call_count, 5)
+        self.assertEqual(stomp._protocol._pending_parts, [b'MESS'])
+
     @patch('aiostomp.aiostomp.StompReader._handle_message')
     @unittest_run_loop
     async def test_consecutive_calls_data_received(self, message_handle_mock):