def test_sproto_unpack(self): result = a2b_hex( "3104d407c40763723f797374616c13fe6372797374616cff00406578616d706c651f2e636f6d26110f02c5040531308f3038360f022806053e3130303130" ) unpack_result = sproto_unpack(result) #print b2a_hex(unpack_result) expected = a2b_hex( "04000000d40700000000070000006372797374616c130000006372797374616c406578616d706c652e636f6d260000000f0000000200000004000500000031303038360f0000000200000006000500000031303031300000" ) self.assertEqual(expected, unpack_result)
def unpack(self, chunk): return core.sproto_unpack(chunk)
def test_sproto_unpack_bug(self): data = a2b_hex("123456789ABCDEF" * 256) pack_result = sproto_pack(data) unpack_data = sproto_unpack(pack_result) self.assertEqual(data, unpack_data)
def test_sproto_unpack(self): result = a2b_hex("3104d407c40763723f797374616c13fe6372797374616cff00406578616d706c651f2e636f6d26110f02c5040531308f3038360f022806053e3130303130") unpack_result = sproto_unpack(result) #print b2a_hex(unpack_result) expected = a2b_hex("04000000d40700000000070000006372797374616c130000006372797374616c406578616d706c652e636f6d260000000f0000000200000004000500000031303038360f0000000200000006000500000031303031300000") self.assertEqual(expected, unpack_result)
{ "type" : 2, "number":"10010", }, ], }) print "result length:", len(result) print ''.join(["%02x" %ord(x) for x in result]) print "-------------------------" print sproto_decode(st, result) print "=========================" pack_result = sproto_pack(result) print len(pack_result) print ''.join(["%02x" %ord(x) for x in pack_result]) print "-------------------------" 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")