Introduce a ProtoStreamReaderInterface. (#837)
* Introduce a ProtoStreamReaderInterface. * Remove the comments from interface def.master
parent
986ac28ff8
commit
43008d391d
|
@ -20,6 +20,7 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include "cartographer/common/port.h"
|
#include "cartographer/common/port.h"
|
||||||
|
#include "cartographer/io/proto_stream_interface.h"
|
||||||
#include "google/protobuf/message.h"
|
#include "google/protobuf/message.h"
|
||||||
|
|
||||||
namespace cartographer {
|
namespace cartographer {
|
||||||
|
@ -52,17 +53,16 @@ class ProtoStreamWriter {
|
||||||
};
|
};
|
||||||
|
|
||||||
// A reader of the format produced by ProtoStreamWriter.
|
// A reader of the format produced by ProtoStreamWriter.
|
||||||
class ProtoStreamReader {
|
class ProtoStreamReader : public ProtoStreamReaderInterface {
|
||||||
public:
|
public:
|
||||||
ProtoStreamReader(const std::string& filename);
|
explicit ProtoStreamReader(const std::string& filename);
|
||||||
~ProtoStreamReader() = default;
|
~ProtoStreamReader() = default;
|
||||||
|
|
||||||
ProtoStreamReader(const ProtoStreamReader&) = delete;
|
ProtoStreamReader(const ProtoStreamReader&) = delete;
|
||||||
ProtoStreamReader& operator=(const ProtoStreamReader&) = delete;
|
ProtoStreamReader& operator=(const ProtoStreamReader&) = delete;
|
||||||
|
|
||||||
bool ReadProto(google::protobuf::Message* proto);
|
bool ReadProto(google::protobuf::Message* proto) override;
|
||||||
|
bool eof() const override;
|
||||||
bool eof() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool Read(std::string* decompressed_data);
|
bool Read(std::string* decompressed_data);
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018 The Cartographer Authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CARTOGRAPHER_IO_PROTO_STREAM_INTERFACE_H_
|
||||||
|
#define CARTOGRAPHER_IO_PROTO_STREAM_INTERFACE_H_
|
||||||
|
|
||||||
|
#include "cartographer/common/port.h"
|
||||||
|
#include "google/protobuf/message.h"
|
||||||
|
|
||||||
|
namespace cartographer {
|
||||||
|
namespace io {
|
||||||
|
|
||||||
|
// A reader of the format produced by ProtoStreamWriter.
|
||||||
|
class ProtoStreamReaderInterface {
|
||||||
|
public:
|
||||||
|
ProtoStreamReaderInterface() = default;
|
||||||
|
virtual ~ProtoStreamReaderInterface(){};
|
||||||
|
|
||||||
|
// Deserialize compressed proto from the pb stream.
|
||||||
|
virtual bool ReadProto(google::protobuf::Message* proto) = 0;
|
||||||
|
|
||||||
|
// 'End-of-file' marker for the pb stream.
|
||||||
|
virtual bool eof() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace io
|
||||||
|
} // namespace cartographer
|
||||||
|
|
||||||
|
#endif // CARTOGRAPHER_IO_PROTO_STREAM_INTERFACE_H_
|
|
@ -244,7 +244,7 @@ void MapBuilder::SerializeState(io::ProtoStreamWriter* const writer) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapBuilder::LoadMap(io::ProtoStreamReader* const reader) {
|
void MapBuilder::LoadMap(io::ProtoStreamReaderInterface* const reader) {
|
||||||
proto::PoseGraph pose_graph;
|
proto::PoseGraph pose_graph;
|
||||||
CHECK(reader->ReadProto(&pose_graph));
|
CHECK(reader->ReadProto(&pose_graph));
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ class MapBuilder : public MapBuilderInterface {
|
||||||
|
|
||||||
void SerializeState(io::ProtoStreamWriter* writer) override;
|
void SerializeState(io::ProtoStreamWriter* writer) override;
|
||||||
|
|
||||||
void LoadMap(io::ProtoStreamReader* reader) override;
|
void LoadMap(io::ProtoStreamReaderInterface* reader) override;
|
||||||
|
|
||||||
int num_trajectory_builders() const override;
|
int num_trajectory_builders() const override;
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ class MapBuilderInterface {
|
||||||
virtual void SerializeState(io::ProtoStreamWriter* writer) = 0;
|
virtual void SerializeState(io::ProtoStreamWriter* writer) = 0;
|
||||||
|
|
||||||
// Loads submaps from a proto stream into a new frozen trajectory.
|
// Loads submaps from a proto stream into a new frozen trajectory.
|
||||||
virtual void LoadMap(io::ProtoStreamReader* reader) = 0;
|
virtual void LoadMap(io::ProtoStreamReaderInterface* reader) = 0;
|
||||||
|
|
||||||
virtual int num_trajectory_builders() const = 0;
|
virtual int num_trajectory_builders() const = 0;
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ class MockMapBuilder : public cartographer::mapping::MapBuilderInterface {
|
||||||
std::string(const cartographer::mapping::SubmapId&,
|
std::string(const cartographer::mapping::SubmapId&,
|
||||||
cartographer::mapping::proto::SubmapQuery::Response*));
|
cartographer::mapping::proto::SubmapQuery::Response*));
|
||||||
MOCK_METHOD1(SerializeState, void(cartographer::io::ProtoStreamWriter*));
|
MOCK_METHOD1(SerializeState, void(cartographer::io::ProtoStreamWriter*));
|
||||||
MOCK_METHOD1(LoadMap, void(cartographer::io::ProtoStreamReader*));
|
MOCK_METHOD1(LoadMap, void(cartographer::io::ProtoStreamReaderInterface*));
|
||||||
MOCK_CONST_METHOD0(num_trajectory_builders, int());
|
MOCK_CONST_METHOD0(num_trajectory_builders, int());
|
||||||
MOCK_METHOD0(pose_graph, PoseGraphInterface*());
|
MOCK_METHOD0(pose_graph, PoseGraphInterface*());
|
||||||
};
|
};
|
||||||
|
|
|
@ -92,7 +92,8 @@ void MapBuilderStub::SerializeState(
|
||||||
LOG(FATAL) << "Not implemented";
|
LOG(FATAL) << "Not implemented";
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapBuilderStub::LoadMap(cartographer::io::ProtoStreamReader* reader) {
|
void MapBuilderStub::LoadMap(
|
||||||
|
cartographer::io::ProtoStreamReaderInterface* reader) {
|
||||||
LOG(FATAL) << "Not implemented";
|
LOG(FATAL) << "Not implemented";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ class MapBuilderStub : public cartographer::mapping::MapBuilderInterface {
|
||||||
const cartographer::mapping::SubmapId& submap_id,
|
const cartographer::mapping::SubmapId& submap_id,
|
||||||
cartographer::mapping::proto::SubmapQuery::Response* response) override;
|
cartographer::mapping::proto::SubmapQuery::Response* response) override;
|
||||||
void SerializeState(cartographer::io::ProtoStreamWriter* writer) override;
|
void SerializeState(cartographer::io::ProtoStreamWriter* writer) override;
|
||||||
void LoadMap(cartographer::io::ProtoStreamReader* reader) override;
|
void LoadMap(cartographer::io::ProtoStreamReaderInterface* reader) override;
|
||||||
int num_trajectory_builders() const override;
|
int num_trajectory_builders() const override;
|
||||||
cartographer::mapping::PoseGraphInterface* pose_graph() override;
|
cartographer::mapping::PoseGraphInterface* pose_graph() override;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue