def base64_thrift(thrift_obj): trans = TMemoryBuffer() tbp = TBinaryProtocol(trans) thrift_obj.write(tbp) return b64encode(bytes(trans.getvalue())).strip()
def read_it(stream): stream_bytes = stream.read() transport_in = TMemoryBuffer(stream_bytes) protocol_in = TBinaryProtocol(transport_in) topology = storm_thrift.StormTopology() topology.read(protocol_in) cls._topology = topology cls.thrift_bolts = topology.bolts cls.thrift_spouts = topology.spouts # Can't reconstruct Python specs from Thrift. cls.specs = []
def write_it(stream): transport_out = TMemoryBuffer() protocol_out = TBinaryProtocol(transport_out) cls._topology.write(protocol_out) transport_bytes = transport_out.getvalue() stream.write(transport_bytes)
def get_proto(self): """Create a TBinaryProtocol instance """ self.trans = TBufferedTransport(self.sock) return TBinaryProtocol(self.trans)
def _build_log_message(span): trans = TMemoryBuffer() protocol = TBinaryProtocol(trans=trans) span.write(protocol) return base64.b64encode(trans.getvalue())