示例#1
0
文件: type.py 项目: aducode/Gaeapy
def enum(name, **enums):
    """
    创建枚举类型并且注册序列化typeid
    :param name:
    :param enums:
    :return:
    """
    # TODO 按照现有做法,实际在invoke时,值的类型并不是Enum子类,序列化时就有问题
    enum_cls = mkenum(**enums)
    enum_cls.__simple_name__ = name
    register.reg(sign(name), enum_cls)
    return enum_cls
示例#2
0
文件: type.py 项目: aducode/Gaeapy
 def decorator(cls):
     """
     给类加上类型信息
     :param cls:
     :return:
     """
     cls.__serialize_name__ = cls.__name__ if len(name) == 0 else name[0]
     d = dict()
     for field_name, protocol_type in fields.items():
         desc = Descriptor(field_name, protocol_type) if isinstance(protocol_type, TypeInfo) \
             else Descriptor(field_name, TypeInfo(protocol_type))
         d[sign(field_name.lower())] = desc
         setattr(cls, field_name, desc)
     cls.__simple_name__ = cls.__serialize_name__
     cls.__serialize_fields__ = [item[1] for item in sorted(d.items(), key=lambda x:x[0])]
     register.reg(sign(cls.__serialize_name__), cls)
     return cls
示例#3
0
文件: type.py 项目: aducode/Gaeapy
def array(genercis=ProtocolType):
    if not issubclass(genercis, ProtocolType):
        raise RuntimeError('Genercis Type must be subclass of ProtocolType, but found:'+genercis.__str__())
    if genercis == ProtocolType:
        return Array
    if genercis not in Array.__generics_cache__:
        new_cls = type('{name}Array'.format(name=genercis.__name__), (Array, ), {
            '__generics__': genercis,
            '__simple_name__': genercis.__simple_name__ + '[]'
        })
        Array.__generics_cache__[genercis] = new_cls
    return Array.__generics_cache__[genercis]


register.reg(0, 1, Null)
register.reg(3, Bool)
register.reg(4, Character)
register.reg(5, 6, Byte)
register.reg(7, 8, Int16)
register.reg(9, 10, Int32)
register.reg(11, 12, Int64)
register.reg(13, Float)
register.reg(14, Double)
register.reg(15, Decimal)
register.reg(16, Datetime)
register.reg(18, String)
register.reg(19, 20, 21, List)
register.reg(22, KeyValue)
register.reg(23, Array)
register.reg(24, 25, Map)