Class: Quark::MdkProtocol::JSONParser
- Inherits:
-
DatawireQuarkCore::QuarkObject
- Object
- DatawireQuarkCore::QuarkObject
- Quark::MdkProtocol::JSONParser
- Extended by:
- DatawireQuarkCore::Static
- Defined in:
- lib/mdk_protocol.rb
Overview
Convert JSON-encoded strings into objects.
Constant Summary
Constants included from DatawireQuarkCore::Static
DatawireQuarkCore::Static::Unassigned
Instance Attribute Summary collapse
-
#_typeToClass ⇒ Object
Returns the value of attribute _typeToClass.
Instance Method Summary collapse
- #__init_fields__ ⇒ Object
- #_getClass ⇒ Object
- #_getField(name) ⇒ Object
- #_setField(name, value) ⇒ Object
-
#decode(message) ⇒ Object
Decode a String into an Object.
-
#initialize ⇒ JSONParser
constructor
A new instance of JSONParser.
-
#register(type, cls) ⇒ Object
Register a type field and the corresponding class.
Methods included from DatawireQuarkCore::Static
_lazy_statics, static, unlazy_statics
Methods inherited from DatawireQuarkCore::QuarkObject
Constructor Details
#initialize ⇒ JSONParser
Returns a new instance of JSONParser.
1225 1226 1227 1228 1229 |
# File 'lib/mdk_protocol.rb', line 1225 def initialize() self.__init_fields__ nil end |
Instance Attribute Details
#_typeToClass ⇒ Object
Returns the value of attribute _typeToClass.
1218 1219 1220 |
# File 'lib/mdk_protocol.rb', line 1218 def _typeToClass @_typeToClass end |
Instance Method Details
#__init_fields__ ⇒ Object
1287 1288 1289 1290 1291 1292 |
# File 'lib/mdk_protocol.rb', line 1287 def __init_fields__() self._typeToClass = {} nil end |
#_getClass ⇒ Object
1261 1262 1263 1264 1265 1266 |
# File 'lib/mdk_protocol.rb', line 1261 def _getClass() return "mdk_protocol.JSONParser" nil end |
#_getField(name) ⇒ Object
1268 1269 1270 1271 1272 1273 1274 1275 1276 |
# File 'lib/mdk_protocol.rb', line 1268 def _getField(name) if ((name) == ("_typeToClass")) return (self)._typeToClass end return nil nil end |
#_setField(name, value) ⇒ Object
1278 1279 1280 1281 1282 1283 1284 1285 |
# File 'lib/mdk_protocol.rb', line 1278 def _setField(name, value) if ((name) == ("_typeToClass")) (self)._typeToClass = ::DatawireQuarkCore.cast(value) { ::Hash } end nil end |
#decode(message) ⇒ Object
Decode a String into an Object.
1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 |
# File 'lib/mdk_protocol.rb', line 1247 def decode() json = ::DatawireQuarkCore::JSONObject.parse() cls = ((self)._typeToClass)[json.getObjectItem("type").getString()] if ((cls) == (nil)) return nil end instance = cls.construct(::DatawireQuarkCore::List.new([])) ::Quark.quark.fromJSON(cls, instance, json) return instance nil end |
#register(type, cls) ⇒ Object
Register a type field and the corresponding class.
1237 1238 1239 1240 1241 1242 |
# File 'lib/mdk_protocol.rb', line 1237 def register(type, cls) ((self)._typeToClass)[type] = (cls) nil end |