예제 #1
0
 def to_json_serializable(cls, obj):
     amap = {}
     for k, v in obj.items():
         kk = Base.to_json_data(value_type=(k, cls.ktype))
         vv = Base.to_json_data(value_type=(v, cls.vtype))
         amap[kk] = vv
     return amap
예제 #2
0
 def to_json_serializable(self):
     amap = {}
     for name, atype in self._fields:
         value = getattr(self, name)
         atype = type_mapping(atype)
         amap[name] = Base.to_json_data(value_type=(value, atype))
     return amap
예제 #3
0
 def to_json_serializable(cls, obj):
     if cls.atype == Uint8:
         return struct.pack("<{}B".format(len(obj)), *obj).hex()
     ret = []
     for _, item in enumerate(obj):
         data = Base.to_json_data(value_type=(item, cls.atype))
         ret.append(data)
     return ret
예제 #4
0
 def to_json_serializable(cls, obj):
     ret = []
     #https://stackoverflow.com/questions/15721363/preserve-python-tuples-with-json
     #If need to deserialize tuple back later, above link will help.
     zipped = zip(cls.ttypes, obj)
     for k, v in zipped:
         data = Base.to_json_data(value_type=(v, k))
         ret.append(data)
     return ret
예제 #5
0
 def to_json_serializable(self):
     jj = Base.to_json_data(value_type=(self.value, self.value_type))
     return {self.enum_name: jj}
예제 #6
0
 def to_json_serializable(self):
     if self.value is None:
         return None
     return Base.to_json_data(value_type=(self.value, self.value_type))
예제 #7
0
 def to_json_serializable(cls, value):
     #if hasattr(cls, "to_json_serializable"):
     if 'to_json_serializable' in cls.__dict__.keys():
         return cls.to_json_serializable(value)
     return Base.to_json_data(value_type=(value, cls.dtype()))