From 5ea87a37f7217c3269db8ee4053e43227268e467 Mon Sep 17 00:00:00 2001 From: Erik Zandvliet Date: Sun, 15 Sep 2013 16:08:30 +0200 Subject: [PATCH] Update on the JSON lib to support new parts encoding. --- lib/json.cpp | 15 +++++++++++++++ lib/json.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/lib/json.cpp b/lib/json.cpp index 928c410b..ab716a6b 100644 --- a/lib/json.cpp +++ b/lib/json.cpp @@ -992,3 +992,18 @@ JSON::Value JSON::fromDTMI2(const unsigned char * data, unsigned int len, unsign tmp["trackid"] = tmpTrackID; return tmp; } + +std::string JSON::encodeVector(std::vector & toEncode){ + std::string result; + for(int i = 0; i < toEncode.size(); i++){ + long long int temp = toEncode[i]; + while( temp >= 0xFFFF){ + result += (char)0xFF; + result += (char)0xFF; + temp -= 0xFFFF; + } + result += (char)temp / 255; + result += (char)temp % 255; + } + return result; +} diff --git a/lib/json.h b/lib/json.h index e16268c1..b1f6b6cc 100644 --- a/lib/json.h +++ b/lib/json.h @@ -5,6 +5,7 @@ #include #include #include +#include //empty definition of DTSC::Stream so it can be a friend. namespace DTSC { @@ -107,4 +108,5 @@ namespace JSON { Value fromString(std::string json); Value fromFile(std::string filename); + std::string encodeVector(std::vector & toEncode); }