Ejemplo n.º 1
2
func (h *HttpRpcHandler) ServeHTTP(out http.ResponseWriter, req *http.Request) {
	if req.Method == "POST" {
		var in *thrift.TMemoryBuffer
		size := int(req.ContentLength)
		if size > 0 {
			in = thrift.NewTMemoryBufferLen(size)
		} else {
			in = thrift.NewTMemoryBuffer()
		}

		in.ReadFrom(req.Body)
		defer req.Body.Close()

		iprot := thrift.NewTBinaryProtocol(in, true, true)

		outbuf := thrift.NewTMemoryBuffer()
		oprot := thrift.NewTBinaryProtocol(outbuf, true, true)

		ok, err := h.Process(iprot, oprot)

		if ok {
			outbuf.WriteTo(out)
		} else {
			http.Error(out, err.Error(), 500)
		}
	} else {
		http.Error(out, "Must POST TBinary encoded thrift RPC", 401)
	}
}
Ejemplo n.º 2
0
func (h *scribeHandler) spans() []*zipkincore.Span {
	h.RLock()
	defer h.RUnlock()
	spans := []*zipkincore.Span{}
	for _, m := range h.entries {
		decoded, err := base64.StdEncoding.DecodeString(m.GetMessage())
		if err != nil {
			h.t.Error(err)
			continue
		}
		buffer := thrift.NewTMemoryBuffer()
		if _, err := buffer.Write(decoded); err != nil {
			h.t.Error(err)
			continue
		}
		transport := thrift.NewTBinaryProtocolTransport(buffer)
		zs := &zipkincore.Span{}
		if err := zs.Read(transport); err != nil {
			h.t.Error(err)
			continue
		}
		spans = append(spans, zs)
	}
	return spans
}
Ejemplo n.º 3
0
Archivo: kafka.go Proyecto: zyanho/kit
func kafkaSerialize(s *Span) []byte {
	t := thrift.NewTMemoryBuffer()
	p := thrift.NewTBinaryProtocolTransport(t)
	if err := s.Encode().Write(p); err != nil {
		panic(err)
	}
	return t.Buffer.Bytes()
}
Ejemplo n.º 4
0
func scribeSerialize(s *Span) string {
	t := thrift.NewTMemoryBuffer()
	p := thrift.NewTBinaryProtocolTransport(t)
	if err := s.Encode().Write(p); err != nil {
		panic(err)
	}
	return base64.StdEncoding.EncodeToString(t.Buffer.Bytes())
}
Ejemplo n.º 5
0
func spanToBytes(span *zipkin.Span) ([]byte, error) {
	t := thrift.NewTMemoryBuffer()
	p := thrift.NewTBinaryProtocolTransport(t)
	err := span.Write(p)
	if err != nil {
		return nil, err
	}
	return t.Buffer.Bytes(), nil
}
Ejemplo n.º 6
0
func NewDynamicClientProts(url func() string, compact bool) (recv, send thrift.TProtocol) {
	recvbuf := thrift.NewTMemoryBuffer()
	send = getSendProt(url, recvbuf, compact)
	if compact {
		recv = thrift.NewTCompactProtocol(recvbuf)
	} else {
		recv = thrift.NewTBinaryProtocol(recvbuf, true, true)
	}
	return recv, send
}
Ejemplo n.º 7
0
func getSendProt(url func() string, recvbuf *thrift.TMemoryBuffer, compact bool) thrift.TProtocol {
	sendbuf := thrift.NewTMemoryBuffer()
	var underlying thrift.TProtocol
	if compact {
		underlying = thrift.NewTCompactProtocol(sendbuf)
	} else {
		underlying = thrift.NewTBinaryProtocol(sendbuf, true, true)
	}
	return &sendProt{&http.Client{Transport: &http.Transport{}}, url, sendbuf, recvbuf, underlying}
}
Ejemplo n.º 8
0
func (h *ThriftOverHTTPHandler) getBuf() *thrift.TMemoryBuffer {
	res := h.buffers.Get()
	if res == nil {
		return thrift.NewTMemoryBuffer()
	} else {
		out := res.(*thrift.TMemoryBuffer)
		out.Reset()
		return out
	}
}
Ejemplo n.º 9
0
func (h ThriftOverHTTPHandler) ServeHTTP(out http.ResponseWriter, req *http.Request) {
	if req.Method == "POST" {
		var in *thrift.TMemoryBuffer
		size := int(req.ContentLength)
		if size > 0 {
			in = thrift.NewTMemoryBufferLen(size)
		} else {
			in = thrift.NewTMemoryBuffer()
		}

		in.ReadFrom(req.Body)
		defer req.Body.Close()

		compact := false

		if in.Len() > 0 && in.Bytes()[0] == thrift.COMPACT_PROTOCOL_ID {
			compact = true
		}

		outbuf := thrift.NewTMemoryBuffer()

		var iprot thrift.TProtocol
		var oprot thrift.TProtocol

		if compact {
			iprot = thrift.NewTCompactProtocol(in)
			oprot = thrift.NewTCompactProtocol(outbuf)
		} else {
			iprot = thrift.NewTBinaryProtocol(in, true, true)
			oprot = thrift.NewTBinaryProtocol(outbuf, true, true)
		}

		ok, err := h.handle(iprot, oprot)

		if ok {
			outbuf.WriteTo(out)
		} else {
			http.Error(out, err.Error(), 500)
		}
	} else {
		http.Error(out, "Must POST TBinary encoded thrift RPC", 401)
	}
}
Ejemplo n.º 10
0
func (z *zipkin) pub(s *zipkincore.Span, pr sarama.SyncProducer) {
	t := thrift.NewTMemoryBuffer()
	p := thrift.NewTBinaryProtocolTransport(t)

	if err := s.Write(p); err != nil {
		return
	}

	m := &sarama.ProducerMessage{
		Topic: z.opts.Topic,
		Key:   nil,
		Value: sarama.ByteEncoder(t.Buffer.Bytes()),
	}

	pr.SendMessage(m)
}