Exemplo n.º 1
0
def _decode_binary_thrift_objs(obj):
    spans = []
    trans = TMemoryBuffer(obj)
    _, size = read_list_begin(trans)
    for _ in range(size):
        span = zipkin_core.Span()
        span.read(TBinaryProtocol(trans))
        spans.append(span)
    return spans
Exemplo n.º 2
0
def decode_thrift(encoded_spans):
    spans = []
    trans = TMemoryBuffer(encoded_spans)
    _, size = read_list_begin(trans)
    for _ in range(size):
        span_obj = zipkin_core.Span()
        span_obj.read(TBinaryProtocol(trans))
        spans.append(span_obj)

    return spans
Exemplo n.º 3
0
def thrift_obj_in_bytes(thrift_obj):  # pragma: no cover
    """
    Returns TBinaryProtocol encoded Thrift object.

    :param thrift_obj: thrift object to encode
    :returns: thrift object in TBinaryProtocol format bytes.
    """
    trans = TMemoryBuffer()
    thrift_obj.write(TBinaryProtocol(trans))
    return bytes(trans.getvalue())
def thrift_obj_in_bytes(thrift_obj):
    """
    Encodes a Thrift object using TBinaryProtocol.

    :param thrift_obj
    :returns: TBinaryProtocol bytes represenation of thrift_obj.
    """
    trans = TMemoryBuffer()
    thrift_obj.write(TBinaryProtocol(trans))
    return trans.getvalue()
    return bytes(trans.getvalue())
Exemplo n.º 5
0
def span_to_bytes(thrift_span):
    """
    Returns a TBinaryProtocol encoded Thrift span.

    :param thrift_span: thrift object to encode.
    :returns: thrift object in TBinaryProtocol format bytes.
    """
    transport = TMemoryBuffer()
    protocol = TBinaryProtocol(transport)
    thrift_span.write(protocol)

    return bytes(transport.getvalue())
Exemplo n.º 6
0
def thrift_objs_in_bytes(thrift_obj_list):  # pragma: no cover
    """
    Returns TBinaryProtocol encoded Thrift objects.

    :param thrift_obj_list: thrift objects list to encode
    :returns: thrift objects in TBinaryProtocol format bytes.
    """
    transport = TMemoryBuffer()
    protocol = TBinaryProtocol(transport)
    write_list_begin(transport, TType.STRUCT, len(thrift_obj_list))
    for thrift_obj in thrift_obj_list:
        thrift_obj.write(protocol)

    return bytes(transport.getvalue())
Exemplo n.º 7
0
    def decode_spans(self, spans):
        """Decodes an encoded list of spans.

        :param spans: encoded list of spans
        :type spans: bytes
        :return: list of span builders
        :rtype: list
        """
        span_builders = []
        transport = TMemoryBuffer(spans)

        if six.byte2int(spans) == TType.STRUCT:
            _, size = read_list_begin(transport)
        else:
            size = 1

        for _ in range(size):
            span = zipkin_core.Span()
            span.read(TBinaryProtocol(transport))
            span_builders.append(self._decode_thrift_span(span))
        return span_builders
def _decode_binary_thrift_obj(obj):
    trans = TMemoryBuffer(obj)
    span = zipkin_core.Span()
    span.read(TBinaryProtocol(trans))
    return span
Exemplo n.º 9
0
 def get_proto(self):
     return TBinaryProtocol(self.trans)
Exemplo n.º 10
0
def spans_from_bytes(buf):
    trans = TMemoryBuffer(buf)
    thrift_object = zipkin_core.Spans()
    thrift_object.read(TBinaryProtocol(trans))
    return thrift_object