def register_schema(cls, typ, schema, typecode):
if typecode is not None and typ in cls.TYPE_CODES:
if cls.TYPE_CODES[typ] != typecode or cls.OBJ_PACKERS[typecode][2].schema is not schema:
raise ValueError("Registering different types with same typecode %r: %r" % (cls.TYPE_CODES[typ], typ))
return cls.OBJ_PACKERS[typecode][2]
if isinstance(typ, mapped_object_with_schema):
packable = typ
else:
packable = mapped_object_with_schema(schema)
class SchemaBufferProxyProperty(GenericBufferProxyProperty):
typ = packable
if typecode is not None:
cls.TYPE_CODES[typ] = typecode
cls.TYPE_CODES[packable] = typecode
cls.OBJ_PACKERS[typecode] = (packable.pack_into, packable.unpack_from, packable)
TYPES[typ] = packable
TYPES[packable] = packable
PROXY_TYPES[typ] = SchemaBufferProxyProperty
PROXY_TYPES[packable] = SchemaBufferProxyProperty
return packable
评论列表
文章目录