没有项目描述
packed的Python项目详细描述
打包
安装
pip3 install packed
用法
frompackedimportpackable@packable# 1) register classclassEqualMatcher:def__init__(self,expected):self._expected=expecteddefmatch(self,actual):returnactual==self._expecteddef__packed__(self):# 2) pick fieldsreturn{"expected":self._expected}
客户端
frompackedimportpackmatcher=EqualMatcher("banana")packed=pack(matcher)# -> send «packed» over network
服务器
frompackedimportunpack# <- recieve «packed» as binarymatcher=unpack(packed)assertmatcher.match("banana")isTrue