# Path: tensor/interfaces.py
# class ITensorProtocol(Interface):
#     """Interface for Tensor client protocols"""
# 
#     def sendEvent(self, event):
#         """Sends an event to this client"""
#         pass


from tensor.ihateprotobuf import proto_pb2
from tensor.interfaces import ITensorProtocol
from zope.interface import implementer
from twisted.protocols.basic import Int32StringReceiver
from twisted.internet.protocol import DatagramProtocol
from twisted.internet import protocol
from twisted.python import log
                pbevent.metric_d = float(event.metric)
                pbevent.metric_f = float(event.metric)
        if event.attributes is not None:
            for key, value in event.attributes.items():
                attribute = pbevent.attributes.add()
                attribute.key, attribute.value = key, value

        return pbevent

    def encodeMessage(self, events):
        """Encode a list of Tensor events with protobuf"""

        message = proto_pb2.Msg(
            events=[self.encodeEvent(e) for e in events if e._type=='riemann']
        )

        return message.SerializeToString()

    def decodeMessage(self, data):
        """Decode a protobuf message into a list of Tensor events"""
        message = proto_pb2.Msg()
        message.ParseFromString(data)

        return message
    
    def sendEvents(self, events):
        """Send a Tensor Event to Riemann"""
        self.pressure += 1
        self.sendString(self.encodeMessage(events))


# Path: tensor/interfaces.py
# class ITensorProtocol(Interface):
#     """Interface for Tensor client protocols"""
# 
#     def sendEvent(self, event):
#         """Sends an event to this client"""
#         pass


# Path: tensor/protocol/riemann.py
from tensor.ihateprotobuf import proto_pb2
from tensor.interfaces import ITensorProtocol
from zope.interface import implementer
from twisted.protocols.basic import Int32StringReceiver
from twisted.internet.protocol import DatagramProtocol
from twisted.internet import protocol
from twisted.python import log

                pbevent.metric_d = float(event.metric)
                pbevent.metric_f = float(event.metric)
        if event.attributes is not None:
            for key, value in event.attributes.items():
                attribute = pbevent.attributes.add()
                attribute.key, attribute.value = key, value

        return pbevent

    def encodeMessage(self, events):
        """Encode a list of Tensor events with protobuf"""

        message = proto_pb2.Msg(
            events=[self.encodeEvent(e) for e in events if e._type=='riemann']
        )

        return message.SerializeToString()

    def decodeMessage(self, data):
        """Decode a protobuf message into a list of Tensor events"""
        message = proto_pb2.Msg()
        message.ParseFromString(data)

        return message
    
    def sendEvents(self, events):
        """Send a Tensor Event to Riemann"""
        self.pressure += 1
        self.sendString(self.encodeMessage(events))


@implementer(ITensorProtocol)