def test_sproto_protocal(self): with open("protocol.spb", "r") as fh: content = fh.read() sp = sproto_create(content) tag, req, resp = sproto_protocol(sp, "foo") self.assertEqual(req, None) self.assertNotEqual(resp, None)
def test_map_key_is_first_one(self): with open("protocol.spb", "r") as fh: content = fh.read() sp = sproto_create(content) tag, req, resp = sproto_protocol(sp, "synheroinfos") source = { "herolist": { 1: { "id": 1, "lv": 2, "cfgid": 3, }, 2: { "id": 2, "lv": 2, "cfgid": 4, }, } } msg = sproto_encode(req, source) dest, r = sproto_decode(req, msg) self.assertEqual(dest, source) self.assertEqual(r, len(msg))
def protocol(self, protoname): if not protoname in self.proto: self.proto[protoname] = core.sproto_protocol(self.sp, protoname) return self.proto[protoname]
def test_sproto_protocal_refcount(self): with open("protocol.spb", "r") as fh: content = fh.read() sp = sproto_create(content) proto = sproto_protocol(sp, "foobar") self.assertEqual(getrefcount(proto[1])-1, 1)
def test_sproto_protocal_refcount(self): with open("protocol.spb", "r") as fh: content = fh.read() sp = sproto_create(content) proto = sproto_protocol(sp, "foobar") self.assertEqual(getrefcount(proto[1]) - 1, 1)
unpack_result = sproto_unpack(pack_result) print ''.join(["%02x" %ord(x) for x in unpack_result]) print "=========================" try: tmp = sproto_encode(st, { "name":"t", "id":"fake_id", }) except pysproto.error: print "catch encode error" print "" print "-------------------------" with open("protocol.spb", "r") as fh: content = fh.read() sp = sproto_create(content) print sproto_protocol(sp, "foobar") print "=========================" with open("testall.spb", "r") as fh: content = fh.read() sp = sproto_create(content) st = sproto_type(sp, "foobar") msg = sproto_encode(st, { "a" : "hello", "b" : 1000000, "c" : True, "d" : { "world":{ "a" : "world", #skip b "c" : -1, },