00001 #ifndef BZ2_TRANSPORT_PUBLISHER_H 00002 #define BZ2_TRANSPORT_PUBLISHER_H 00003 00004 00005 #include <message_transport/simple_publisher_plugin.h> 00006 #include <bz2_transport/bz2_codec.h> 00007 #include <bz2_transport/BZ2Packet.h> 00008 00009 namespace bz2_transport { 00010 00011 template <class Base> 00012 class BZ2Publisher : 00013 public message_transport::SimplePublisherPlugin<Base,bz2_transport::BZ2Packet> 00014 { 00015 public: 00016 BZ2Publisher() : 00017 message_transport::SimplePublisherPlugin<Base,bz2_transport::BZ2Packet>(){} 00018 virtual ~BZ2Publisher() {} 00019 00020 virtual std::string getTransportName() const 00021 { 00022 return "bz2"; 00023 } 00024 protected: 00025 virtual void publish(const Base& message, 00026 const typename message_transport::SimplePublisherPlugin<Base,bz2_transport::BZ2Packet>::PublishFn& publish_fn) const { 00027 00028 BZ2Packet out; 00029 size_t datasize = ros::serialization::serializationLength(message); 00030 boost::shared_array<uint8_t> buffer(new uint8_t[datasize]); 00031 ros::serialization::OStream sout(buffer.get(),datasize); 00032 ros::serialization::serialize(sout,message); 00033 if (codec.compress(buffer, datasize, out)) { 00034 publish_fn(out); 00035 } 00036 } 00037 00038 BZ2Codec codec; 00039 }; 00040 00041 00042 } //namespace bz2_transport 00043 00044 00045 #endif // BZ2_TRANSPORT_PUBLISHER_H