proto_stream_deserializer.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2018 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
21 #include "glog/logging.h"
22 
23 namespace cartographer {
24 namespace io {
25 namespace {
26 mapping::proto::SerializationHeader ReadHeaderOrDie(
27  ProtoStreamReaderInterface* const reader) {
28  mapping::proto::SerializationHeader header;
29  CHECK(reader->ReadProto(&header)) << "Failed to read SerializationHeader.";
30  return header;
31 }
32 
33 bool IsVersionSupported(const mapping::proto::SerializationHeader& header) {
34  return header.format_version() == kMappingStateSerializationFormatVersion;
35 }
36 
37 } // namespace
38 
39 mapping::proto::PoseGraph DeserializePoseGraphFromFile(
40  const std::string& file_name) {
41  ProtoStreamReader reader(file_name);
42  ProtoStreamDeserializer deserializer(&reader);
43  return deserializer.pose_graph();
44 }
45 
47  ProtoStreamReaderInterface* const reader)
48  : reader_(reader), header_(ReadHeaderOrDie(reader)) {
49  CHECK(IsVersionSupported(header_)) << "Unsupported serialization format \""
50  << header_.format_version() << "\"";
51 
53  << "Serialized stream misses PoseGraph.";
54  CHECK(pose_graph_.has_pose_graph())
55  << "Serialized stream order corrupt. Expecting `PoseGraph` after "
56  "`SerializationHeader`, but got field tag "
57  << pose_graph_.data_case();
58 
60  << "Serialized stream misses `AllTrajectoryBuilderOptions`.";
61  CHECK(all_trajectory_builder_options_.has_all_trajectory_builder_options())
62  << "Serialized stream order corrupt. Expecting "
63  "`AllTrajectoryBuilderOptions` after "
64  "PoseGraph, got field tag "
65  << all_trajectory_builder_options_.data_case();
66 
67  CHECK_EQ(pose_graph_.pose_graph().trajectory_size(),
68  all_trajectory_builder_options_.all_trajectory_builder_options()
69  .options_with_sensor_ids_size());
70 }
71 
73  mapping::proto::SerializedData* data) {
74  return reader_->ReadProto(data);
75 }
76 
77 } // namespace io
78 } // namespace cartographer
std::unique_ptr< InMemoryProtoStreamReader > reader_
static constexpr int kMappingStateSerializationFormatVersion
bool ReadNextSerializedData(mapping::proto::SerializedData *data)
ProtoStreamDeserializer(ProtoStreamReaderInterface *const reader)
virtual bool ReadProto(google::protobuf::Message *proto)=0
mapping::proto::PoseGraph DeserializePoseGraphFromFile(const std::string &file_name)
mapping::proto::SerializationHeader header_
mapping::proto::SerializedData all_trajectory_builder_options_


cartographer
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:00:58