Esempio n. 1
0
                /**
                 * @brief Constructor for a Protobuf Subscriber
                 *
                 * @param topicName Topic name on which the subscriber subscribes to data.
                 **/
                public ProtobufSubscriber(string topicName)
                {
                    T msg = new T();

                    binarySubscriber = new Subscriber(topicName, Common.ProtobufHelper.GetProtoMessageTypeName(msg), Common.ProtobufHelper.GetProtoMessageDescription(msg));
                    receivedData     = new ReceiveCallbackData();
                }
Esempio n. 2
0
                /**
                 * @brief Receive data.
                 *
                 * @param receiveTimeout Timeout after which the function returns, even if no data was received.
                 *        If -1, it will only return after data was received.
                 *
                 * @return  The received data, can be null if no data was received.
                 **/
                public ReceiveCallbackData Receive(int receiveTimeout)
                {
                    var receivedData = binarySubscriber.Receive(receiveTimeout);

                    if (receivedData != null)
                    {
                        byte[] msgBytes  = Encoding.Default.GetBytes(receivedData.data);
                        var    msgStream = new MemoryStream(msgBytes);

                        var protobufCallbackData = new ReceiveCallbackData();
                        protobufCallbackData.data = new T();
                        protobufCallbackData.data.MergeFrom(msgStream);
                        protobufCallbackData.clock = receivedData.clock;
                        protobufCallbackData.id    = receivedData.id;
                        protobufCallbackData.time  = receivedData.time;
                        return(protobufCallbackData);
                    }
                    else
                    {
                        return(null);
                    }
                }