diff --git a/src/moos/goby_moos_app.h b/src/moos/goby_moos_app.h index 5d3a1b35..f842ffd0 100644 --- a/src/moos/goby_moos_app.h +++ b/src/moos/goby_moos_app.h @@ -25,6 +25,7 @@ #include "goby/moos/moos_header.h" #include "goby/util/as.h" +#include "goby/moos/moos_translator.h" #include #include @@ -109,9 +110,11 @@ template template void publish_pb(const std::string& key, const ProtobufMessage& msg) { + std::string serialized; - serialize_for_moos(&serialized, msg); - publish(key, serialized); + bool is_binary = serialize_for_moos(&serialized, msg); + CMOOSMsg moos_msg = goby::moos::MOOSTranslator::make_moos_msg(key, serialized, is_binary, goby::moos::moos_technique, msg.GetDescriptor()->full_name()); + publish(moos_msg); } diff --git a/src/moos/moos_protobuf_helpers.h b/src/moos/moos_protobuf_helpers.h index 2ae7ffea..890d7bbd 100644 --- a/src/moos/moos_protobuf_helpers.h +++ b/src/moos/moos_protobuf_helpers.h @@ -1317,33 +1317,31 @@ namespace goby } -inline void serialize_for_moos(std::string* out, const google::protobuf::Message& msg) +inline bool serialize_for_moos(std::string* out, const google::protobuf::Message& msg) { switch(goby::moos::moos_technique) { case goby::moos::protobuf::TranslatorEntry::TECHNIQUE_PROTOBUF_NATIVE_ENCODED: goby::moos::MOOSTranslation::serialize(out, msg); - break; + return true; case goby::moos::protobuf::TranslatorEntry::TECHNIQUE_PROTOBUF_NATIVE_HEX: goby::moos::MOOSTranslation::serialize(out, msg); - break; + return false; case goby::moos::protobuf::TranslatorEntry::TECHNIQUE_PROTOBUF_TEXT_FORMAT: goby::moos::MOOSTranslation::serialize(out, msg); - break; - + return false; case goby::moos::protobuf::TranslatorEntry::TECHNIQUE_PREFIXED_PROTOBUF_NATIVE_ENCODED: goby::moos::MOOSTranslation::serialize(out, msg); - break; + return true; case goby::moos::protobuf::TranslatorEntry::TECHNIQUE_PREFIXED_PROTOBUF_NATIVE_HEX: goby::moos::MOOSTranslation::serialize(out, msg); - break; + return false; case goby::moos::protobuf::TranslatorEntry::TECHNIQUE_PREFIXED_PROTOBUF_TEXT_FORMAT: goby::moos::MOOSTranslation::serialize(out, msg); - break; + return false; default: goby::glog.is(goby::common::logger::DIE) && goby::glog << "Non-PROTOBUF techniques are not supported for 'moos_parser_technique': " << goby::moos::protobuf::TranslatorEntry::ParserSerializerTechnique_Name(goby::moos::moos_technique) << std::endl; - break; - + return false; } } diff --git a/src/moos/moos_translator.h b/src/moos/moos_translator.h index 31713230..4d22c44c 100644 --- a/src/moos/moos_translator.h +++ b/src/moos/moos_translator.h @@ -20,6 +20,9 @@ // You should have received a copy of the GNU Lesser General Public License // along with Goby. If not, see . +#ifndef MOOS_TRANSLATOR_H +#define MOOS_TRANSLATOR_H + #include #include #include @@ -133,8 +136,7 @@ namespace goby const std::map& dictionary() const { return dictionary_; } - private: - CMOOSMsg make_moos_msg(const std::string& var, const std::string& str, bool is_binary, goby::moos::protobuf::TranslatorEntry::ParserSerializerTechnique technique, const std::string& pb_name) + static CMOOSMsg make_moos_msg(const std::string& var, const std::string& str, bool is_binary, goby::moos::protobuf::TranslatorEntry::ParserSerializerTechnique technique, const std::string& pb_name) { if(is_binary) { @@ -157,7 +159,8 @@ namespace goby } } } - + private: + void initialize(double lat_origin = std::numeric_limits::quiet_NaN(), double lon_origin = std::numeric_limits::quiet_NaN(), @@ -456,3 +459,4 @@ GoogleProtobufMessagePointer goby::moos::MOOSTranslator::moos_to_protobuf(const } +#endif