コード例 #1
0
ファイル: benchmark_struct.py プロジェクト: tubular/thriftpy
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())
コード例 #2
0
ファイル: decode.py プロジェクト: ravjot28/snowplow-kafka
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
コード例 #3
0
ファイル: client.py プロジェクト: btdlin/myPyUtils
 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)
コード例 #4
0
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']))
コード例 #5
0
ファイル: calc_server.py プロジェクト: wooparadog/thriftpy
def main():
    server = make_server(calc.Calculator,
                         Dispatcher(),
                         '127.0.0.1',
                         6000,
                         proto_factory=TCyBinaryProtocolFactory())
    print("serving...")
    server.serve()
コード例 #6
0
def main():
    server = make_server(tutorial.Calculator,
                         CalculatorHandler(),
                         '127.0.0.1',
                         6000,
                         proto_factory=TCyBinaryProtocolFactory())
    print("serving...")
    server.serve()
コード例 #7
0
ファイル: cmd.py プロジェクト: doubleceston/thriftpy-cli
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)")
コード例 #8
0
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
コード例 #9
0
def main():
    server = make_server(calc_thrift.Calculator,
                         Dispatcher(),
                         '127.0.0.1',
                         6000,
                         proto_factory=TCyBinaryProtocolFactory(),
                         trans_factory=TCyBufferedTransportFactory())
    print("serving...")
    server.serve()
コード例 #10
0
ファイル: calc_client.py プロジェクト: atbrox/thriftpy
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)
コード例 #11
0
ファイル: benchmark.py プロジェクト: henrique/thriftpy
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)
コード例 #12
0
 def get_protoco_factory(self):
     from thriftpy.protocol import TCyBinaryProtocolFactory
     return TCyBinaryProtocolFactory().get_protocol
コード例 #13
0
ファイル: linkServer.py プロジェクト: gaybro8777/linkshop
            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