- Timestamp:
- 02/07/16 04:09:36 (9 years ago)
- Location:
- cpp/frams
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/param/param.cpp
r426 r464 296 296 ExtValue ex; 297 297 get(i, ex); 298 ws = SString(SERIALIZATION_PREFIX) + ex.serialize( );298 ws = SString(SERIALIZATION_PREFIX) + ex.serialize(NativeSerialization); 299 299 } 300 300 else -
cpp/frams/util/extvalue.cpp
r414 r464 183 183 } 184 184 185 SString ExtObject::serialize_inner( ) const185 SString ExtObject::serialize_inner(SerializationFormat format) const 186 186 { 187 187 int ref = tlsGetRef(ExtObject_serialization).add(*this); 188 SString ret; 189 188 190 if (ref >= 0) 189 return SString::sprintf("^%d", ref); 191 { 192 switch(format) 193 { 194 case NativeSerialization: return SString::sprintf("^%d", ref); 195 case JSONSerialization: return SString("null"); 196 } 197 } 190 198 191 199 if (isEmpty()) return SString("null"); 200 { 192 201 VectorObject *vec = VectorObject::fromObject(*this, false); 193 202 if (vec) 194 return vec->serialize(); 203 { ret=vec->serialize(format); goto finally; } 204 } 205 { 195 206 DictionaryObject *dic = DictionaryObject::fromObject(*this, false); 196 207 if (dic) 197 return dic->serialize(); 208 { ret=dic->serialize(format); goto finally; } 209 } 210 { 198 211 Param tmp_param; 199 212 ParamInterface *p = getParamInterface(tmp_param); … … 204 217 { 205 218 ExtObject o(p->getObject(m)); 206 SString ret = SString(interfaceName()) + o.serialize(); 207 return ret; 219 switch(format) 220 { 221 case NativeSerialization: ret=SString(interfaceName())+o.serialize(format); break; 222 case JSONSerialization: ret=SString::sprintf("{\"class\":\"%s\",\"data\":%s}",interfaceName(),o.serialize(format).c_str()); break; 223 } 224 goto finally; 208 225 } 209 226 m = p->findId("toString"); … … 212 229 SString str = p->getString(m); 213 230 sstringQuote(str); 214 SString ret = SString(interfaceName()) + "\"" + str + "\""; 215 return ret; 231 switch(format) 232 { 233 case NativeSerialization: ret=SString(interfaceName())+"\"" +str+"\""; break; 234 case JSONSerialization: ret=SString::sprintf("{\"class\":\"%s\",\"data\":\"%s\"}",interfaceName(),str.c_str()); break; 235 } 236 goto finally; 237 } 216 238 } 217 239 218 240 tlsGetRef(ExtObject_serialization).remove(*this);//undo nonserializable reference 219 SString ret = interfaceName(); 220 ret += SString::sprintf("<%p>", object ? object : paraminterface); 241 switch(format) 242 { 243 case NativeSerialization: return SString(interfaceName())+SString::sprintf("<%p>",object ? object : paraminterface); break; 244 case JSONSerialization: return SString::sprintf("{\"class\":\"%s\"}",interfaceName()); break; 245 } 246 247 finally: // not 100% "finally", the case of nonserializable reference (directly above) returns directly without going through finally 248 249 switch(format) 250 { 251 case JSONSerialization: 252 tlsGetRef(ExtObject_serialization).remove(*this);//JSON only tracks recursion, does not track reuse 253 break; 254 } 255 221 256 return ret; 222 257 } 223 258 224 SString ExtObject::serialize( ) const259 SString ExtObject::serialize(SerializationFormat format) const 225 260 { 226 261 tlsGetRef(ExtObject_serialization).begin(); 227 SString ret = serialize_inner( );262 SString ret = serialize_inner(format); 228 263 tlsGetRef(ExtObject_serialization).end(); 229 264 return ret; … … 874 909 } 875 910 876 SString ExtValue::serialize( ) const911 SString ExtValue::serialize(SerializationFormat format) const 877 912 { 878 913 switch (type) … … 889 924 return SString::valueOf(ddata()); 890 925 case TObj: 891 return odata().serialize( );926 return odata().serialize(format); 892 927 case TInvalid: 893 return SString("invalid"); 928 if (format==NativeSerialization) 929 return SString("invalid"); 930 // else null --v 894 931 default: 895 932 return SString("null"); -
cpp/frams/util/extvalue.h
r384 r464 32 32 virtual ~DestrBase() {} 33 33 }; 34 35 enum SerializationFormat { NativeSerialization, JSONSerialization }; 34 36 35 37 /** … … 75 77 76 78 SString toString() const; 77 SString serialize_inner( ) const;78 SString serialize( ) const;79 SString serialize_inner(SerializationFormat format) const; 80 SString serialize(SerializationFormat format) const; 79 81 80 82 ExtObject(Param *p, void *o) :subtype(2), object(o), param(p){} … … 194 196 SString getString() const; 195 197 const SString* getStringPtr() const;//< @return pointer to the internal sstring object or NULL if the current type is not string 196 SString serialize( ) const;198 SString serialize(SerializationFormat format) const; 197 199 ExtObject getObject() const; 198 200 bool isNull() const { return (type == TUnknown) || ((type == TObj) && odata().isEmpty()); } -
cpp/frams/vm/classes/collectionobj.cpp
r453 r464 154 154 } 155 155 156 SString VectorObject::serialize( ) const156 SString VectorObject::serialize(SerializationFormat format) const 157 157 { 158 158 SString out="["; … … 163 163 if (i) out+=","; 164 164 if (v) 165 out+=v->serialize( );165 out+=v->serialize(format); 166 166 else 167 167 out+="null"; … … 413 413 } 414 414 415 SString DictionaryObject::serialize( ) const415 SString DictionaryObject::serialize(SerializationFormat format) const 416 416 { 417 417 SString out="{"; … … 424 424 out+="\":"; 425 425 if (it->value!=NULL) 426 out+=((ExtValue*)it->value)->serialize( );426 out+=((ExtValue*)it->value)->serialize(format); 427 427 else 428 428 out+="null"; -
cpp/frams/vm/classes/collectionobj.h
r453 r464 42 42 static void p_new(void*,ExtValue*args,ExtValue*ret) 43 43 {ret->setObject(ExtObject(&par,new VectorObject));} 44 SString serialize( ) const;44 SString serialize(SerializationFormat format) const; 45 45 ExtObject makeObject() {return ExtObject(&par,this);} 46 46 … … 73 73 PARAMPROCDEF(p_clone); 74 74 #undef STATRICKCLASS 75 SString serialize( ) const;75 SString serialize(SerializationFormat format) const; 76 76 static void p_new(void*,ExtValue*args,ExtValue*ret) 77 77 {ret->setObject(ExtObject(&par,new DictionaryObject));}
Note: See TracChangeset
for help on using the changeset viewer.