def main(): n = 100000 print("binary protocol struct benchmark for {} times:".format(n)) encode(n) decode(n) print("\ncybin protocol struct benchmark for {} times:".format(n)) encode(n, TCyBinaryProtocolFactory()) decode(n, TCyBinaryProtocolFactory())
def decode_msg(kafka_msg): raw_payload = deserialize(STRUCTS.CollectorPayload(), kafka_msg, TCyBinaryProtocolFactory()) querystring = raw_payload.querystring obj = raw_payload.__dict__ obj['querystring_parsed'] = parse.parse_qs(raw_payload.querystring) return obj
def __create_client(self): socket = TSocket(self.__host, self.__port, socket_timeout=self.__timeout) self.__transport = TCyFramedTransportFactory().get_transport(socket) protocol = TCyBinaryProtocolFactory().get_protocol(self.__transport) self.__client = TClient(recs_thrift.RecommendationsService, protocol)
def print_thrift(timestamp, data): json_payload = json.loads(data.decode('utf-8')) decoded_thrift_payload = base64.b64decode(json_payload['line']) thrift_payload = deserialize(collector_payload, decoded_thrift_payload, TCyBinaryProtocolFactory()) print('{}: {}, {}'.format(timestamp, thrift_payload, json_payload['errors']))
def main(): server = make_server(calc.Calculator, Dispatcher(), '127.0.0.1', 6000, proto_factory=TCyBinaryProtocolFactory()) print("serving...") server.serve()
def main(): server = make_server(tutorial.Calculator, CalculatorHandler(), '127.0.0.1', 6000, proto_factory=TCyBinaryProtocolFactory()) print("serving...") server.serve()
def client(thrift, host, port, service): calc_thrift = thriftpy.load(str(thrift)) with client_context(getattr(calc_thrift, service), host, port, proto_factory=TCyBinaryProtocolFactory(), trans_factory=TCyBufferedTransportFactory()) as client: IPython.embed(header="Call client.api(*args)")
def decode_event(data, collector_payload): json_payload = json.loads(data.decode('utf-8')) decoded_thrift_payload = base64.b64decode(json_payload['line']) thrift_payload = deserialize(collector_payload, decoded_thrift_payload, TCyBinaryProtocolFactory()) qs = thrift_payload.querystring event = {'qs': parse.parse_qs(qs), 'errors': json_payload['errors']} return event
def main(): server = make_server(calc_thrift.Calculator, Dispatcher(), '127.0.0.1', 6000, proto_factory=TCyBinaryProtocolFactory(), trans_factory=TCyBufferedTransportFactory()) print("serving...") server.serve()
def main(): with client_context(calc.Calculator, '127.0.0.1', 6000, proto_factory=TCyBinaryProtocolFactory()) as cal: a = cal.mult(5, 2) b = cal.sub(7, 3) c = cal.sub(6, 4) d = cal.mult(b, 10) e = cal.add(a, d) f = cal.div(e, c) print(f)
def main(): print("TBinaryProtocol:") start = time.time() encode(10000) end = time.time() print(end - start) start = time.time() decode(10000) end = time.time() print(end - start) print("\nTCyBinaryProtocol:") start = time.time() encode(10000, TCyBinaryProtocolFactory()) end = time.time() print(end - start) start = time.time() decode(10000, TCyBinaryProtocolFactory()) end = time.time() print(end - start)
def get_protoco_factory(self): from thriftpy.protocol import TCyBinaryProtocolFactory return TCyBinaryProtocolFactory().get_protocol
return json.dumps(to_send) except fs.FileNotFound as e: to_send['err'] = str(e) return json.dumps(to_send) else: to_send['err'] = 'An unexpected error occurred' return json.dumps(to_send) #Signal handler to ensure that on a termination signal, the file store saves #the state of the system. Probably don't need this anymore. def signal_handler(signal, frame): sys.exit(0) #And now its watch has ended signal.signal(signal.SIGTERM, signal_handler) #Really, this is just like signing a will #Starts the thrift service running on port 6000 #Remember, use 127.0.0.1 and not localhost. We still want to avoid the apocalypse! server = make_server(link_thrift.Link, Dispatcher(), '127.0.0.1', 6000, proto_factory=TCyBinaryProtocolFactory(), trans_factory=TCyBufferedTransportFactory()) print("Service activated") server.serve() finished = True