Replace templates in io/proto_stream.h with upcasting. (#833)

master
Alexander Belyaev 2018-01-22 14:12:14 +01:00 committed by Wally B. Feed
parent 9e30c1e0cd
commit 67850d25a0
1 changed files with 3 additions and 4 deletions

View File

@ -20,6 +20,7 @@
#include <fstream> #include <fstream>
#include "cartographer/common/port.h" #include "cartographer/common/port.h"
#include "google/protobuf/message.h"
namespace cartographer { namespace cartographer {
namespace io { namespace io {
@ -39,8 +40,7 @@ class ProtoStreamWriter {
ProtoStreamWriter& operator=(const ProtoStreamWriter&) = delete; ProtoStreamWriter& operator=(const ProtoStreamWriter&) = delete;
// Serializes, compressed and writes the 'proto' to the file. // Serializes, compressed and writes the 'proto' to the file.
template <typename MessageType> void WriteProto(const google::protobuf::Message& proto) {
void WriteProto(const MessageType& proto) {
std::string uncompressed_data; std::string uncompressed_data;
proto.SerializeToString(&uncompressed_data); proto.SerializeToString(&uncompressed_data);
Write(uncompressed_data); Write(uncompressed_data);
@ -64,8 +64,7 @@ class ProtoStreamReader {
ProtoStreamReader(const ProtoStreamReader&) = delete; ProtoStreamReader(const ProtoStreamReader&) = delete;
ProtoStreamReader& operator=(const ProtoStreamReader&) = delete; ProtoStreamReader& operator=(const ProtoStreamReader&) = delete;
template <typename MessageType> bool ReadProto(google::protobuf::Message* proto) {
bool ReadProto(MessageType* proto) {
std::string decompressed_data; std::string decompressed_data;
return Read(&decompressed_data) && return Read(&decompressed_data) &&
proto->ParseFromString(decompressed_data); proto->ParseFromString(decompressed_data);