branch with improvemnts

Fork of M2XStreamClient by AT&T M2X Team

Revision:
2:7ea7ab05f120
Parent:
0:f479e4f4db0e
Child:
4:ba0d02be2835
--- a/M2XStreamClient.cpp	Wed Feb 12 19:43:34 2014 +0000
+++ b/M2XStreamClient.cpp	Sun Sep 07 05:28:55 2014 +0000
@@ -7,6 +7,25 @@
 
 const char* M2XStreamClient::kDefaultM2XHost = "api-m2x.att.com";
 
+// import from jsonlite.c
+typedef uint8_t parse_state;
+struct jsonlite_parser_struct {
+    const uint8_t *cursor;
+    const uint8_t *limit;
+    const uint8_t *token_start;
+    const uint8_t *buffer;
+    
+    uint8_t *buffer_own;
+    uint8_t *rest;
+    size_t rest_size;
+    
+    parse_state *current;
+    const parse_state *last;
+    
+    jsonlite_result result;
+    jsonlite_parser_callbacks callbacks;
+};
+
 int print_encoded_string(Print* print, const char* str);
 int tolower(int ch);
 
@@ -287,7 +306,7 @@
 
 int M2XStreamClient::readStreamValue(stream_value_read_callback callback,
                                      void* context) {
-  const int BUF_LEN = 32;
+  const int BUF_LEN = 64;
   char buf[BUF_LEN];
 
   int length = readContentLength();
@@ -311,6 +330,7 @@
   jsonlite_parser_callbacks cbs = jsonlite_default_callbacks;
   cbs.key_found = on_stream_key_found;
   cbs.string_found = on_stream_string_found;
+  cbs.number_found = on_stream_string_found;
   cbs.context.client_state = &state;
 
   jsonlite_parser p = jsonlite_parser_init(jsonlite_parser_estimate_size(5));
@@ -319,7 +339,6 @@
   jsonlite_result result = jsonlite_result_unknown;
   while (index < length) {
     int i = 0;
-
     DBG("%s", "Received Data: ");
     while ((i < BUF_LEN) && _client->available()) {
       buf[i++] = _client->read();
@@ -342,8 +361,8 @@
       close();
       return E_JSON_INVALID;
     }
-
-    index += i;
+    
+    index += i - p->rest_size;
   }
 
   jsonlite_parser_release(p);