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.
1217 1218 1219 1220 1221 |
# File 'lib/mdk_protocol.rb', line 1217 def initialize() self.__init_fields__ nil end |
Instance Attribute Details
#_typeToClass ⇒ Object
Returns the value of attribute _typeToClass.
1210 1211 1212 |
# File 'lib/mdk_protocol.rb', line 1210 def _typeToClass @_typeToClass end |
Instance Method Details
#__init_fields__ ⇒ Object
1279 1280 1281 1282 1283 1284 |
# File 'lib/mdk_protocol.rb', line 1279 def __init_fields__() self._typeToClass = {} nil end |
#_getClass ⇒ Object
1253 1254 1255 1256 1257 1258 |
# File 'lib/mdk_protocol.rb', line 1253 def _getClass() return "mdk_protocol.JSONParser" nil end |
#_getField(name) ⇒ Object
1260 1261 1262 1263 1264 1265 1266 1267 1268 |
# File 'lib/mdk_protocol.rb', line 1260 def _getField(name) if ((name) == ("_typeToClass")) return (self)._typeToClass end return nil nil end |
#_setField(name, value) ⇒ Object
1270 1271 1272 1273 1274 1275 1276 1277 |
# File 'lib/mdk_protocol.rb', line 1270 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.
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 |
# File 'lib/mdk_protocol.rb', line 1239 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.
1229 1230 1231 1232 1233 1234 |
# File 'lib/mdk_protocol.rb', line 1229 def register(type, cls) ((self)._typeToClass)[type] = (cls) nil end |