Skip to content

Commit 7f2c91f

Browse files
committed
Finished map
1 parent 8f5b2b2 commit 7f2c91f

File tree

1 file changed

+24
-30
lines changed

1 file changed

+24
-30
lines changed

type-variant.h

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ inline Variant& operator>> (object o, Variant& v)
5151
v = array;
5252
break;
5353
}
54+
case type::MAP: {
55+
Array array = Array::Create();
56+
if(o.via.map.size != 0) {
57+
object_kv* p(o.via.map.ptr);
58+
for(object_kv* const pend(o.via.map.ptr + o.via.map.size);
59+
p < pend; ++p) {
60+
Variant key, val;
61+
p->key >> key;
62+
p->val >> val;
63+
array.set(key, val, true);
64+
}
65+
}
66+
v = array;
67+
break;
68+
}
5469
default:
5570
break;
5671
}
@@ -88,13 +103,18 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const Variant& v)
88103
break;
89104
}
90105
case KindOfArray: {
91-
if (v.toArray()->isVectorData()) {
92-
o.pack_array(v.toArray().size());
93-
for (ArrayIter iter(v.toArray()); iter; ++iter) {
106+
Array array = v.toArray();
107+
if (array->isVectorData()) {
108+
o.pack_array(array.size());
109+
for (ArrayIter iter(array); iter; ++iter) {
94110
o << iter.second();
95111
}
96112
} else {
97-
113+
o.pack_map(array.size());
114+
for (ArrayIter iter(array); iter; ++iter) {
115+
o << iter.first();
116+
o << iter.second();
117+
}
98118
}
99119
break;
100120
}
@@ -105,32 +125,6 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const Variant& v)
105125
return o;
106126
}
107127

108-
inline void operator<< (object::with_zone& o, const Variant& v)
109-
{
110-
if (v.isString()) {
111-
String str = v.toString();
112-
113-
o.type = type::RAW;
114-
char* ptr = (char*)o.zone->malloc(str.size());
115-
o.via.raw.ptr = ptr;
116-
o.via.raw.size = (uint32_t)str.size();
117-
memcpy(ptr, str.c_str(), str.size());
118-
}
119-
}
120-
121-
inline void operator<< (object& o, const Variant& v)
122-
{
123-
if (v.isString()) {
124-
String str = v.toString();
125-
126-
o.type = type::RAW;
127-
o.via.raw.ptr = str.c_str();
128-
o.via.raw.size = (uint32_t)str.size();
129-
}
130-
}
131-
132-
133128
} // namespace msgpack
134129

135130
#endif
136-

0 commit comments

Comments
 (0)