[HICN-529] Fix viper API to work with hicn and cicn. 49/25249/2
authorMauro Sardara <[email protected]>
Tue, 18 Feb 2020 15:53:12 +0000 (16:53 +0100)
committerMauro Sardara <[email protected]>
Tue, 18 Feb 2020 15:57:02 +0000 (15:57 +0000)
Change-Id: I9715c29855302ee747313a95897e645d86218c7f
Signed-off-by: Mauro Sardara <[email protected]>
Signed-off-by: Mauro Sardara <[email protected]>
Input/ICNConnectionConsumerApi.cpp
Input/ICNConnectionConsumerApi.h

index 5933085..26edd83 100644 (file)
@@ -148,24 +148,36 @@ int       ICNConnectionConsumerApi::Read(uint8_t *data, size_t len)
                                                        {"Connection", "Keep-Alive"}};
        std::string s(m_name.c_str());
        hTTPClientConnection->get(s, headers, {}, nullptr, nullptr, this->v6FirstWord);
+#ifdef HICNET
+       response = hTTPClientConnection->response()->getPayload();
+#else
        response  = hTTPClientConnection->response();
+#endif
        this->res = true;
        this->dataPos = 0;
     }
-    if (response.getPayload().size() - this->dataPos > (int)len)
+#ifdef HICNET
+    char * bytes = (char*)response->writableData();
+    std::size_t size = response->length();
+#else
+    char *bytes = response.getPayload().data();
+    std::size_t size = response.getPayload().size();
+#endif
+
+    if (size - this->dataPos > (int)len)
     {
-       memcpy(data, (char*)response.getPayload().data() + this->dataPos, len);
+       memcpy(data, bytes + this->dataPos, len);
        this->dataPos += len;
        return len;
     } else
     {
-        memcpy(data, (char*)response.getPayload().data() + this->dataPos, response.getPayload().size() - this->dataPos);
-        int length = response.getPayload().size() - this->dataPos;
+        memcpy(data, bytes + this->dataPos, size - this->dataPos);
+        int length = size - this->dataPos;
         if (length == 0)
         {
           this->res = false;
         }
-        this->dataPos = response.getPayload().size();
+        this->dataPos = size;
         return length;
     }
 }
index c4e8992..539e2e0 100644 (file)
@@ -96,7 +96,11 @@ public:
 
 private:
     libl4::http::HTTPClientConnection *hTTPClientConnection;
-    libl4::http::HTTPResponse response;
+#ifdef HICNET
+    libl4::http::HTTPPayload response;
+#else
+    std::shared_ptr<libl4::http::HTTPResponse> response;
+#endif
     float beta;
     float drop;
     std::string v6FirstWord;