summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorKenneth Anthony Giusti <kgiusti@apache.org>2010-03-30 20:09:59 +0000
committerKenneth Anthony Giusti <kgiusti@apache.org>2010-03-30 20:09:59 +0000
commitcfe6bb5fbde532d57e8cb8b6c1e338b00e58034b (patch)
tree440140ada63fa6eedfb435749a7b9be3a7b1f281 /cpp/src
parente87e7af34a950629ccdbfefda73789b23ea9c0ff (diff)
downloadqpid-python-cfe6bb5fbde532d57e8cb8b6c1e338b00e58034b.tar.gz
add support for QMF TYPE_LIST in engine, ruby and python wrappers
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@929244 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/qmf/engine/ValueImpl.cpp167
-rw-r--r--cpp/src/qmf/engine/ValueImpl.h13
2 files changed, 158 insertions, 22 deletions
diff --git a/cpp/src/qmf/engine/ValueImpl.cpp b/cpp/src/qmf/engine/ValueImpl.cpp
index b1c027520f..72c68c420b 100644
--- a/cpp/src/qmf/engine/ValueImpl.cpp
+++ b/cpp/src/qmf/engine/ValueImpl.cpp
@@ -18,20 +18,23 @@
*/
#include "qmf/engine/ValueImpl.h"
-#include <qpid/framing/FieldTable.h>
#include <qpid/framing/FieldValue.h>
+#include <qpid/framing/FieldTable.h>
+#include <qpid/framing/List.h>
using namespace std;
using namespace qmf::engine;
-using qpid::framing::Buffer;
-using qpid::framing::FieldTable;
-using qpid::framing::FieldValue;
+//using qpid::framing::Buffer;
+//using qpid::framing::FieldTable;
+//using qpid::framing::FieldValue;
+using namespace qpid::framing;
ValueImpl::ValueImpl(Typecode t, Buffer& buf) : typecode(t)
{
uint64_t first;
uint64_t second;
FieldTable ft;
+ List fl;
switch (typecode) {
case TYPE_UINT8 : value.u32 = (uint32_t) buf.getOctet(); break;
@@ -62,6 +65,10 @@ ValueImpl::ValueImpl(Typecode t, Buffer& buf) : typecode(t)
break;
case TYPE_LIST:
+ fl.decode(buf);
+ initList(fl);
+ break;
+
case TYPE_ARRAY:
case TYPE_OBJECT:
default:
@@ -126,7 +133,7 @@ void ValueImpl::initMap(const FieldTable& ft)
Value* subval(new Value(TYPE_DOUBLE));
subval->setDouble(fvalue.get<double>());
insert(name.c_str(), subval);
- } else {
+ } else if (amqType == 0xa8) {
FieldTable subFt;
bool valid = qpid::framing::getEncodedValue<FieldTable>(iter->second, subFt);
if (valid) {
@@ -134,6 +141,14 @@ void ValueImpl::initMap(const FieldTable& ft)
subval->impl->initMap(subFt);
insert(name.c_str(), subval);
}
+ } else if (amqType == 0xa9) {
+ List subList;
+ bool valid = qpid::framing::getEncodedValue<List>(iter->second, subList);
+ if (valid) {
+ Value* subval(new Value(TYPE_LIST));
+ subval->impl->initList(subList);
+ insert(name.c_str(), subval);
+ }
}
}
}
@@ -185,6 +200,14 @@ void ValueImpl::mapToFieldTable(FieldTable& ft) const
ft.setTable(name, subFt);
break;
case TYPE_LIST:
+ {
+ List subList;
+ subval.impl->listToFramingList(subList);
+ ft.set(name,
+ ::qpid::framing::FieldTable::ValuePtr(
+ new ListValue(
+ subList)));
+ } break;
case TYPE_ARRAY:
case TYPE_OBJECT:
case TYPE_UUID:
@@ -195,9 +218,126 @@ void ValueImpl::mapToFieldTable(FieldTable& ft) const
}
}
+
+void ValueImpl::initList(const List& fl)
+{
+ for (List::const_iterator iter = fl.begin();
+ iter != fl.end(); iter++) {
+ const FieldValue& fvalue(*iter->get());
+ uint8_t amqType = fvalue.getType();
+
+ if (amqType == 0x32) {
+ Value* subval(new Value(TYPE_UINT64));
+ subval->setUint64(fvalue.get<int64_t>());
+ appendToList(subval);
+ } else if ((amqType & 0xCF) == 0x02) {
+ Value* subval(new Value(TYPE_UINT32));
+ switch (amqType) {
+ case 0x02 : subval->setUint(fvalue.get<int>()); break;
+ case 0x12 : subval->setUint(fvalue.get<int>()); break;
+ case 0x22 : subval->setUint(fvalue.get<int>()); break;
+ }
+ appendToList(subval);
+ } else if ((amqType & 0xCF) == 0x01) {
+ Value* subval(new Value(TYPE_INT64));
+ subval->setInt64(fvalue.get<int64_t>());
+ appendToList(subval);
+ } else if (amqType == 0x85 || amqType == 0x95) {
+ Value* subval(new Value(TYPE_LSTR));
+ subval->setString(fvalue.get<string>().c_str());
+ appendToList(subval);
+ } else if (amqType == 0x23 || amqType == 0x33) {
+ Value* subval(new Value(TYPE_DOUBLE));
+ subval->setDouble(fvalue.get<double>());
+ appendToList(subval);
+ } else if (amqType == 0xa8) {
+ FieldTable subFt;
+ bool valid = qpid::framing::getEncodedValue<FieldTable>(*iter, subFt);
+ if (valid) {
+ Value* subval(new Value(TYPE_MAP));
+ subval->impl->initMap(subFt);
+ appendToList(subval);
+ }
+ } else if (amqType == 0xa9) {
+ List subList;
+ bool valid = qpid::framing::getEncodedValue<List>(*iter, subList);
+ if (valid) {
+ Value *subVal(new Value(TYPE_LIST));
+ subVal->impl->initList(subList);
+ appendToList(subVal);
+ }
+ }
+ }
+}
+
+void ValueImpl::listToFramingList(List& fl) const
+{
+ for (vector<Value>::const_iterator iter = vectorVal.begin();
+ iter != vectorVal.end(); iter++) {
+ const Value& subval(*iter);
+
+ switch (subval.getType()) {
+ case TYPE_UINT8:
+ case TYPE_UINT16:
+ case TYPE_UINT32:
+ fl.push_back(List::ValuePtr(new Unsigned64Value((uint64_t) subval.asUint())));
+ break;
+ case TYPE_UINT64:
+ case TYPE_DELTATIME:
+ fl.push_back(List::ValuePtr(new Unsigned64Value(subval.asUint64())));
+ break;
+ case TYPE_SSTR:
+ case TYPE_LSTR:
+ fl.push_back(List::ValuePtr(new Str16Value(subval.asString())));
+ break;
+ case TYPE_INT64:
+ case TYPE_ABSTIME:
+ fl.push_back(List::ValuePtr(new Integer64Value(subval.asInt64())));
+ break;
+ case TYPE_BOOL:
+ fl.push_back(List::ValuePtr(new IntegerValue(subval.asBool() ? 1 : 0)));
+ break;
+ case TYPE_FLOAT:
+ fl.push_back(List::ValuePtr(new FloatValue(subval.asFloat())));
+ break;
+ case TYPE_DOUBLE:
+ fl.push_back(List::ValuePtr(new DoubleValue(subval.asDouble())));
+ break;
+ case TYPE_INT8:
+ case TYPE_INT16:
+ case TYPE_INT32:
+ fl.push_back(List::ValuePtr(new IntegerValue(subval.asInt())));
+ break;
+ case TYPE_MAP:
+ {
+ FieldTable subFt;
+ subval.impl->mapToFieldTable(subFt);
+ fl.push_back(List::ValuePtr(new FieldTableValue(subFt)));
+
+ } break;
+ case TYPE_LIST:
+ {
+ List subList;
+ subval.impl->listToFramingList(subList);
+ fl.push_back(List::ValuePtr(new ListValue(subList)));
+ } break;
+
+ case TYPE_ARRAY:
+ case TYPE_OBJECT:
+ case TYPE_UUID:
+ case TYPE_REF:
+ default:
+ break;
+ }
+ }
+ }
+
+
+
void ValueImpl::encode(Buffer& buf) const
{
FieldTable ft;
+ List fl;
switch (typecode) {
case TYPE_UINT8 : buf.putOctet((uint8_t) value.u32); break;
@@ -222,6 +362,10 @@ void ValueImpl::encode(Buffer& buf) const
ft.encode(buf);
break;
case TYPE_LIST:
+ listToFramingList(fl);
+ fl.encode(buf);
+ break;
+
case TYPE_ARRAY:
case TYPE_OBJECT:
default:
@@ -280,19 +424,6 @@ const char* ValueImpl::key(uint32_t idx) const
return iter->first.c_str();
}
-Value* ValueImpl::listItem(uint32_t)
-{
- return 0;
-}
-
-void ValueImpl::appendToList(Value*)
-{
-}
-
-void ValueImpl::deleteListItem(uint32_t)
-{
-}
-
Value* ValueImpl::arrayItem(uint32_t)
{
return 0;
diff --git a/cpp/src/qmf/engine/ValueImpl.h b/cpp/src/qmf/engine/ValueImpl.h
index 84b0e768e6..3b535834fd 100644
--- a/cpp/src/qmf/engine/ValueImpl.h
+++ b/cpp/src/qmf/engine/ValueImpl.h
@@ -33,6 +33,7 @@
namespace qpid {
namespace framing {
class FieldTable;
+ class List;
}
}
@@ -138,13 +139,14 @@ namespace engine {
bool isList() const { return typecode == TYPE_LIST; }
uint32_t listItemCount() const { return vectorVal.size(); }
- Value* listItem(uint32_t idx);
- void appendToList(Value* val);
- void deleteListItem(uint32_t idx);
+ Value* listItem(uint32_t idx) { return idx < listItemCount() ? &vectorVal[idx] : 0; }
+ const Value* listItem(uint32_t idx) const { return idx < listItemCount() ? &vectorVal[idx] : 0; }
+ void appendToList(Value* val) { vectorVal.push_back(*val); }
+ void deleteListItem(uint32_t idx) { if (idx < listItemCount()) vectorVal.erase(vectorVal.begin()+idx); }
bool isArray() const { return typecode == TYPE_ARRAY; }
Typecode arrayType() const { return arrayTypecode; }
- uint32_t arrayItemCount() const { return vectorVal.size(); }
+ uint32_t arrayItemCount() const { return 0; }
Value* arrayItem(uint32_t idx);
void appendToArray(Value* val);
void deleteArrayItem(uint32_t idx);
@@ -152,6 +154,9 @@ namespace engine {
private:
void mapToFieldTable(qpid::framing::FieldTable& ft) const;
void initMap(const qpid::framing::FieldTable& ft);
+
+ void listToFramingList(qpid::framing::List& fl) const;
+ void initList(const qpid::framing::List& fl);
};
}
}